From: Vsevolod Stakhov Date: Mon, 19 Jul 2010 11:14:46 +0000 (+0400) Subject: * Reopen log file by USR1 signal X-Git-Tag: 0.3.1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0b7a87e6aaa8dd90604d470ea6558ff53691e85;p=thirdparty%2Frspamd.git * Reopen log file by USR1 signal * Add reopenlog method to FreeBSD rc script --- diff --git a/freebsd/rspamd.sh.in b/freebsd/rspamd.sh.in index d58259008a..d01b3394cb 100755 --- a/freebsd/rspamd.sh.in +++ b/freebsd/rspamd.sh.in @@ -37,7 +37,13 @@ rspamd_checkconfig() eval ${command} -t } -extra_commands="reload configtest" +reopenlog_cmd() +{ + export sig_reload="USR1" + run_rc_command reload +} + +extra_commands="reload configtest reopenlog" sig_reload="HUP" command="$procname" diff --git a/src/controller.c b/src/controller.c index 531f605dbe..0adc771738 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 7db272c11d..e612e1d862 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 7ba43d6cb7..c3d1bf9019 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 19ea767b8b..f17835764e 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 3c292f2b4e..cbbfea2680 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 e8b6023bbb..aefdf2ca7b 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 1ecc9c4f01..2c508ebe18 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(?