diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-07-19 15:14:46 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-07-19 15:14:46 +0400 |
commit | c0b7a87e6aaa8dd90604d470ea6558ff53691e85 (patch) | |
tree | 10e5cfcb7160e48c595b11daa999d976e86e56e6 /src | |
parent | dec1abd6e4582b74b658db72a7071ce098d1c9e5 (diff) | |
download | rspamd-c0b7a87e6aaa8dd90604d470ea6558ff53691e85.tar.gz rspamd-c0b7a87e6aaa8dd90604d470ea6558ff53691e85.zip |
* Reopen log file by USR1 signal
* Add reopenlog method to FreeBSD rc script
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.c | 3 | ||||
-rw-r--r-- | src/fuzzy_storage.c | 3 | ||||
-rw-r--r-- | src/lmtp.c | 3 | ||||
-rw-r--r-- | src/logger.c | 22 | ||||
-rw-r--r-- | src/main.c | 23 | ||||
-rw-r--r-- | src/smtp.c | 3 | ||||
-rw-r--r-- | src/url.c | 7 | ||||
-rw-r--r-- | src/worker.c | 3 |
8 files changed, 48 insertions, 19 deletions
diff --git a/src/controller.c b/src/controller.c index 531f605db..0adc77173 100644 --- a/src/controller.c +++ b/src/controller.c @@ -100,6 +100,9 @@ sig_handler (int signo, siginfo_t *info, void *unused) #endif { switch (signo) { + case SIGUSR1: + reopen_log (); + break; case SIGINT: case SIGTERM: _exit (1); diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 7db272c11..e612e1d86 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -96,6 +96,9 @@ sig_handler (int signo, siginfo_t *info, void *unused) #endif { switch (signo) { + case SIGUSR1: + reopen_log (); + break; case SIGINT: /* Ignore SIGINT as we should got SIGTERM after it anyway */ return; diff --git a/src/lmtp.c b/src/lmtp.c index 7ba43d6cb..c3d1bf901 100644 --- a/src/lmtp.c +++ b/src/lmtp.c @@ -47,6 +47,9 @@ sig_handler (int signo, siginfo_t *info, void *unused) #endif { switch (signo) { + case SIGUSR1: + reopen_log (); + break; case SIGINT: case SIGTERM: _exit (1); diff --git a/src/logger.c b/src/logger.c index 19ea767b8..f17835764 100644 --- a/src/logger.c +++ b/src/logger.c @@ -278,11 +278,13 @@ rspamd_set_logger (enum rspamd_log_type type, enum process_type ptype, struct co int reopen_log (void) { -#ifdef RSPAMD_MAIN - do_reopen_log = 0; -#endif close_log (); - return open_log (); + if (open_log () == 0) { + msg_info ("log file reopened"); + return 0; + } + + return -1; } void @@ -370,11 +372,7 @@ static void syslog_log_function (const gchar * log_domain, const gchar *function, GLogLevelFlags log_level, const gchar * message, gboolean forced, gpointer arg) { struct config_file *cfg = (struct config_file *)arg; -#ifdef RSPAMD_MAIN - if (do_reopen_log) { - reopen_log (); - } -#endif + if (! rspamd_log->enabled) { return; } @@ -427,11 +425,7 @@ file_log_function (const gchar * log_domain, const gchar *function, GLogLevelFla if (! rspamd_log->enabled) { return; } -#ifdef RSPAMD_MAIN - if (do_reopen_log) { - reopen_log (); - } -#endif + if (forced || log_level <= rspamd_log->cfg->log_level) { /* Check repeats */ diff --git a/src/main.c b/src/main.c index 3c292f2b4..cbbfea268 100644 --- a/src/main.c +++ b/src/main.c @@ -116,7 +116,6 @@ sig_handler (int signo, siginfo_t *info, void *unused) switch (signo) { case SIGHUP: do_restart = 1; - do_reopen_log = 1; break; case SIGINT: case SIGTERM: @@ -125,6 +124,9 @@ sig_handler (int signo, siginfo_t *info, void *unused) case SIGCHLD: child_dead = 1; break; + case SIGUSR1: + do_reopen_log = 1; + break; case SIGUSR2: /* Do nothing */ break; @@ -605,6 +607,16 @@ wait_for_workers (gpointer key, gpointer value, gpointer unused) return TRUE; } +static void +reopen_log_handler (gpointer key, gpointer value, gpointer unused) +{ + struct rspamd_worker *w = value; + + if (kill (w->pid, SIGUSR1) == -1) { + msg_err ("kill failed for pid %P: %s", w->pid, strerror (errno)); + } +} + #if 0 /* XXX: remove this as it is unused now */ static gboolean @@ -958,14 +970,17 @@ main (int argc, char **argv, char **env) } if (do_restart) { do_restart = 0; - do_reopen_log = 1; - + reopen_log (); msg_info ("rspamd " RVERSION " is restarting"); g_hash_table_foreach (rspamd->workers, kill_old_workers, NULL); remove_all_maps (); reread_config (rspamd); spawn_workers (rspamd); - + } + if (do_reopen_log) { + do_reopen_log = 0; + reopen_log (); + g_hash_table_foreach (rspamd->workers, reopen_log_handler, NULL); } if (got_alarm) { got_alarm = 0; diff --git a/src/smtp.c b/src/smtp.c index e8b6023bb..aefdf2ca7 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -60,6 +60,9 @@ sig_handler (int signo, siginfo_t *info, void *unused) struct timeval tv; switch (signo) { + case SIGUSR1: + reopen_log (); + break; case SIGINT: case SIGTERM: if (!wanna_die) { @@ -49,7 +49,12 @@ struct _proto { unsigned int need_ssl:1; }; -static const char *text_url = "((https?|ftp)://)?" "(\\b(?<![.\\@A-Za-z0-9-])" "(?: [A-Za-z0-9][A-Za-z0-9-]*(?:\\.[A-Za-z0-9-]+)*\\." "(?i:com|net|org|biz|edu|gov|info|name|int|mil|aero|coop|jobs|mobi|museum|pro|travel" "|cc|[rs]u|uk|ua|by|de|jp|fr|fi|no|no|ca|it|ro|cn|nl|at|nu|se" "|[a-z]{2}" "(?(1)|(?=/)))" "(?!\\w)" "|(?:\\d{1,3}\\.){3}\\d{1,3}(?(1)|(?=[/:]))" /* ip in dotted view */ +static const char *text_url = "((https?|ftp)://)?" + "(\\b(?<![.\\@A-Za-z0-9-])" "(?: [A-Za-z0-9][A-Za-z0-9-]*(?:\\.[A-Za-z0-9-]+)*\\." + "(?i:com|net|org|biz|edu|gov|info|name|int|mil|aero|coop|jobs|mobi|museum|pro|travel" + "|cc|[rs]u|uk|ua|by|de|jp|fr|fi|no|no|ca|it|ro|cn|nl|at|nu|se" + "|[a-z]{2}" "(?(1)|(?=/)))" "(?!\\w)" + "|(?:\\d{1,3}\\.){3}\\d{1,3}(?(1)|(?=[/:]))" /* ip in dotted view */ "|\\d{5,20}(?(1)|(?=[/:]))" /* ip in numeric view */ ")" "(?::\\d{1,5})?" /* port */ "(?!\\.\\w)" /* host part ended, no more of this further on */ diff --git a/src/worker.c b/src/worker.c index 10a7aeace..8edf2ccce 100644 --- a/src/worker.c +++ b/src/worker.c @@ -100,6 +100,9 @@ sig_handler (int signo, siginfo_t *info, void *unused) struct timeval tv; switch (signo) { + case SIGUSR1: + reopen_log (); + break; case SIGINT: case SIGTERM: if (!wanna_die) { |