diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-16 14:27:39 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-16 14:27:39 +0000 |
commit | 5e6a385fb64338a773a8ed643d7810be0481fc94 (patch) | |
tree | 919e6a8d32508f4fa3100e5c8cf2395180e64ff5 | |
parent | c4958798d0058d349fa33a1ed4dd3bede1dab730 (diff) | |
download | rspamd-5e6a385fb64338a773a8ed643d7810be0481fc94.tar.gz rspamd-5e6a385fb64338a773a8ed643d7810be0481fc94.zip |
[CritFix] Fix descriptors leak on reload
MFH: true
-rw-r--r-- | src/libutil/logger.c | 32 | ||||
-rw-r--r-- | src/rspamd.c | 3 |
2 files changed, 24 insertions, 11 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c index 8707acb39..923ac8dd9 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -73,6 +73,7 @@ struct rspamd_logger_s { gboolean is_debug; gboolean throttling; gboolean no_lock; + gboolean opened; time_t throttling_time; enum rspamd_log_type type; pid_t pid; @@ -212,18 +213,18 @@ rspamd_escape_log_string (gchar *str) gint rspamd_log_open_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) { - switch (rspamd_log->cfg->log_type) { + if (!rspamd_log->opened) { + switch (rspamd_log->cfg->log_type) { case RSPAMD_LOG_CONSOLE: /* Do nothing with console */ rspamd_log->enabled = TRUE; - return 0; + break; case RSPAMD_LOG_SYSLOG: #ifdef HAVE_SYSLOG_H openlog ("rspamd", LOG_NDELAY | LOG_PID, rspamd_log->cfg->log_facility); - rspamd_log->enabled = TRUE; #endif - return 0; + break; case RSPAMD_LOG_FILE: rspamd_log->fd = open (rspamd_log->cfg->log_file, O_CREAT | O_WRONLY | O_APPEND, @@ -241,10 +242,16 @@ rspamd_log_open_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) close (rspamd_log->fd); return -1; } - rspamd_log->enabled = TRUE; - return 0; + break; + default: + return -1; + } + + rspamd_log->opened = TRUE; + rspamd_log->enabled = TRUE; } - return -1; + + return 0; } void @@ -253,7 +260,8 @@ rspamd_log_close_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) gchar tmpbuf[256]; rspamd_log_flush (rspamd_log); - switch (rspamd_log->type) { + if (rspamd_log->opened) { + switch (rspamd_log->type) { case RSPAMD_LOG_CONSOLE: /* Do nothing special */ break; @@ -293,7 +301,6 @@ rspamd_log_close_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) rspamd_log->saved_loglevel | RSPAMD_LOG_FORCED, tmpbuf, rspamd_log); - return; } if (fsync (rspamd_log->fd) == -1) { @@ -302,15 +309,18 @@ rspamd_log_close_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) close (rspamd_log->fd); } break; - } + } - rspamd_log->enabled = FALSE; + rspamd_log->enabled = FALSE; + rspamd_log->opened = FALSE; + } } gint rspamd_log_reopen_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) { rspamd_log_close_priv (rspamd_log, uid, gid); + if (rspamd_log_open_priv (rspamd_log, uid, gid) == 0) { msg_info ("log file reopened"); return 0; diff --git a/src/rspamd.c b/src/rspamd.c index a6142614b..627230d48 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -256,6 +256,9 @@ config_logger (rspamd_mempool_t *pool, gpointer ud) rspamd_set_logger (rspamd_main->cfg, g_quark_try_string ("main"), &rspamd_main->logger, rspamd_main->server_pool); + rspamd_log_close_priv (rspamd_main->logger, + rspamd_main->workers_uid, rspamd_main->workers_gid); + if (rspamd_log_open_priv (rspamd_main->logger, rspamd_main->workers_uid, rspamd_main->workers_gid) == -1) { fprintf (stderr, "Fatal error, cannot open logfile, exiting\n"); |