commit e49164c: [Feature] Check limits after being set, migrate to uint64

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Mar 19 12:35:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-03-19 12:32:19 +0000
URL: https://github.com/rspamd/rspamd/commit/e49164c4fd5756bbf950f5a2fb77e9685c07d806 (HEAD -> master)

[Feature] Check limits after being set, migrate to uint64

---
 src/libserver/cfg_file.h    |  4 ++--
 src/libserver/cfg_rcl.c     |  4 ++--
 src/libserver/worker_util.c | 20 +++++++++++++++++++-
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index c102ef570..5b9e89c6c 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -212,8 +212,8 @@ struct rspamd_worker_conf {
 	struct rspamd_worker_bind_conf *bind_conf;      /**< bind configuration									*/
 	gint16 count;                                   /**< number of workers									*/
 	GList *listen_socks;                            /**< listening sockets descriptors						*/
-	guint32 rlimit_nofile;                          /**< max files limit									*/
-	guint32 rlimit_maxcore;                         /**< maximum core file size								*/
+	guint64 rlimit_nofile;                          /**< max files limit									*/
+	guint64 rlimit_maxcore;                         /**< maximum core file size								*/
 	GHashTable *params;                             /**< params for worker									*/
 	GQueue *active_workers;                         /**< linked list of spawned workers						*/
 	gboolean has_socket;                            /**< whether we should make listening socket in main process */
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 59b1fc932..9ea80a49c 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -2255,13 +2255,13 @@ rspamd_rcl_config_init (struct rspamd_config *cfg, GHashTable *skip_sections)
 				"max_files",
 				rspamd_rcl_parse_struct_integer,
 				G_STRUCT_OFFSET (struct rspamd_worker_conf, rlimit_nofile),
-				RSPAMD_CL_FLAG_INT_32,
+				RSPAMD_CL_FLAG_INT_64,
 				"Maximum number of opened files per worker");
 		rspamd_rcl_add_default_handler (sub,
 				"max_core",
 				rspamd_rcl_parse_struct_integer,
 				G_STRUCT_OFFSET (struct rspamd_worker_conf, rlimit_maxcore),
-				RSPAMD_CL_FLAG_INT_32,
+				RSPAMD_CL_FLAG_INT_64,
 				"Max size of core file in bytes");
 		rspamd_rcl_add_default_handler (sub,
 				"enabled",
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 06296bba2..a5bb968e6 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -557,10 +557,28 @@ rspamd_worker_set_limits (struct rspamd_main *rspamd_main,
 			rlmt.rlim_max = (rlim_t) cf->rlimit_maxcore;
 
 			if (setrlimit (RLIMIT_CORE, &rlmt) == -1) {
-				msg_warn_main ("cannot set max core rlimit: %d, %s",
+				msg_warn_main ("cannot set max core rlimit: %HL, %s",
 						cf->rlimit_maxcore,
 						strerror (errno));
 			}
+
+			/* Ensure that we did it */
+			memset (&rlmt, 0, sizeof (rlmt));
+
+			if (getrlimit (RLIMIT_CORE, &rlmt) == -1) {
+				msg_warn_main ("cannot get max core rlimit: %HL, %s",
+						cf->rlimit_maxcore,
+						strerror (errno));
+			}
+
+			if (rlmt.rlim_cur != cf->rlimit_maxcore ||
+					rlmt.rlim_max != cf->rlimit_maxcore) {
+				msg_warn_main ("setting of limits was unsuccessful: %HL was wanted, "
+							   "but we have %HL cur and %HL max",
+						cf->rlimit_maxcore,
+						(guint64)rlmt.rlim_cur,
+						(guint64)rlmt.rlim_max);
+			}
 		}
 	}
 }


More information about the Commits mailing list