]> source.dussan.org Git - rspamd.git/commitdiff
* Reopen log file by USR1 signal
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 19 Jul 2010 11:14:46 +0000 (15:14 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 19 Jul 2010 11:14:46 +0000 (15:14 +0400)
* Add reopenlog method to FreeBSD rc script

freebsd/rspamd.sh.in
src/controller.c
src/fuzzy_storage.c
src/lmtp.c
src/logger.c
src/main.c
src/smtp.c
src/url.c
src/worker.c

index d58259008adad0acd195799b7d8a6f5173fd8a30..d01b3394cb2cbe75176bd00a8a72b94cb5b891bb 100755 (executable)
@@ -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"
index 531f605dbede09ac1ded316ff85a54a79f61ee33..0adc77173828a6c9faa54d67095d4d85603300c5 100644 (file)
@@ -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);
index 7db272c11d407b8aafaed3c9b42654ffd2b12cf6..e612e1d86203c69978bd6d431ea996f2bc581269 100644 (file)
@@ -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;
index 7ba43d6cb79c7dd60b913530aaf42bf88f49f257..c3d1bf9019205d7584c0388d4a4d3d5a43a0be52 100644 (file)
@@ -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);
index 19ea767b8beaed8e308e4e9e8241dadb48a98b3d..f17835764e198d3ba2aeff1e6e6c15129c9dd617 100644 (file)
@@ -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 */
index 3c292f2b4e04645103f7112cc3841d4fc8be7446..cbbfea26804fa28f9aff7b14e87ea2d660f07505 100644 (file)
@@ -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;
index e8b6023bbb4e732be72abf64ae28c6e3ae9583ca..aefdf2ca7b6a73da5fc0ae3dc2523111dd4ea820 100644 (file)
@@ -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) {
index 1ecc9c4f015e4a8bb646dde7cd29333606036588..2c508ebe18c6953cf1b627f31d683be517efd847 100644 (file)
--- 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(?<![.\\@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 */
index 10a7aeaceef3cd3b5df3c1b1d6f5e573fbba8539..8edf2ccceea2f491d2580eff97968e1d549b220b 100644 (file)
@@ -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) {