From c0b7a87e6aaa8dd90604d470ea6558ff53691e85 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 19 Jul 2010 15:14:46 +0400 Subject: * Reopen log file by USR1 signal * Add reopenlog method to FreeBSD rc script --- src/controller.c | 3 +++ src/fuzzy_storage.c | 3 +++ src/lmtp.c | 3 +++ src/logger.c | 22 ++++++++-------------- src/main.c | 23 +++++++++++++++++++---- src/smtp.c | 3 +++ src/url.c | 7 ++++++- src/worker.c | 3 +++ 8 files changed, 48 insertions(+), 19 deletions(-) (limited to 'src') 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) { diff --git a/src/url.c b/src/url.c index 1ecc9c4f0..2c508ebe1 100644 --- a/src/url.c +++ b/src/url.c @@ -49,7 +49,12 @@ struct _proto { unsigned int need_ssl:1; }; -static const char *text_url = "((https?|ftp)://)?" "(\\b(?