]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to reuse signal handlers chains
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 22 Jul 2017 19:35:06 +0000 (20:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 22 Jul 2017 19:35:06 +0000 (20:35 +0100)
src/libserver/worker_util.c
src/libserver/worker_util.h
src/rspamd.h

index 88e775b54e4131695fb2a36f816251f3762eccb2..9dfb6d5e6068cdb651ec74ff579739b89f9f9674 100644 (file)
@@ -87,7 +87,7 @@ rspamd_worker_terminate_handlers (struct rspamd_worker *w)
 /*
  * Config reload is designed by sending sigusr2 to active workers and pending shutdown of them
  */
-static void
+static gboolean
 rspamd_worker_usr2_handler (struct rspamd_worker_signal_handler *sigh, void *arg)
 {
        /* Do not accept new connections, preparing to end worker's process */
@@ -108,18 +108,24 @@ rspamd_worker_usr2_handler (struct rspamd_worker_signal_handler *sigh, void *arg
                event_base_loopexit (sigh->base, &tv);
                rspamd_worker_stop_accept (sigh->worker);
        }
+
+       /* No more signals */
+       return FALSE;
 }
 
 /*
  * Reopen log is designed by sending sigusr1 to active workers and pending shutdown of them
  */
-static void
+static gboolean
 rspamd_worker_usr1_handler (struct rspamd_worker_signal_handler *sigh, void *arg)
 {
        rspamd_log_reopen (sigh->worker->srv->logger);
+
+       /* Get more signals */
+       return TRUE;
 }
 
-static void
+static gboolean
 rspamd_worker_term_handler (struct rspamd_worker_signal_handler *sigh, void *arg)
 {
        struct timeval tv;
@@ -147,21 +153,23 @@ rspamd_worker_term_handler (struct rspamd_worker_signal_handler *sigh, void *arg
 #endif
                rspamd_worker_stop_accept (sigh->worker);
        }
+
+       /* Stop reacting on signals */
+       return FALSE;
 }
 
 static void
-rspamd_worker_signal_handler (int fd, short what, void *arg)
+rspamd_worker_signal_handle (int fd, short what, void *arg)
 {
        struct rspamd_worker_signal_handler *sigh =
                        (struct rspamd_worker_signal_handler *) arg;
-       struct rspamd_worker_signal_cb *cb;
-
-       cb = sigh->cb;
+       struct rspamd_worker_signal_cb *cb, *cbtmp;
 
        /* Call all signal handlers registered */
-       while (cb) {
-               cb->handler (sigh, cb->handler_data);
-               cb = cb->next;
+       DL_FOREACH_SAFE (sigh->cb, cb, cbtmp) {
+               if (!cb->handler (sigh, cb->handler_data)) {
+                       DL_DELETE (sigh->cb, cb);
+               }
        }
 }
 
@@ -180,7 +188,7 @@ rspamd_worker_ignore_signal (int signo)
 void
 rspamd_worker_set_signal_handler (int signo, struct rspamd_worker *worker,
                struct event_base *base,
-               void (*handler)(struct rspamd_worker_signal_handler *sigh, void *),
+               rspamd_worker_signal_handler handler,
                void *handler_data)
 {
        struct rspamd_worker_signal_handler *sigh;
@@ -195,7 +203,7 @@ rspamd_worker_set_signal_handler (int signo, struct rspamd_worker *worker,
                sigh->base = base;
                sigh->enabled = TRUE;
 
-               signal_set (&sigh->ev, signo, rspamd_worker_signal_handler, sigh);
+               signal_set (&sigh->ev, signo, rspamd_worker_signal_handle, sigh);
                event_base_set (base, &sigh->ev);
                signal_add (&sigh->ev, NULL);
 
index 5e33c940dd3b87c6d649f3f6f2aec9104b6651a8..1fc4565cb550746687481d7cbf85f3c3e6daa846 100644 (file)
@@ -48,7 +48,7 @@ rspamd_prepare_worker (struct rspamd_worker *worker, const char *name,
 void rspamd_worker_set_signal_handler (int signo,
                struct rspamd_worker *worker,
                struct event_base *base,
-               void (*handler) (struct rspamd_worker_signal_handler *, void *),
+               rspamd_worker_signal_handler handler,
                void *handler_data);
 
 /**
index a716c37880227c838e02f1464e13ec026f90957b..b2157bd3e9e17e89cfc1852ef338498854758325 100644 (file)
@@ -88,9 +88,11 @@ struct rspamd_abstract_worker_ctx {
 };
 
 struct rspamd_worker_signal_handler;
+typedef gboolean (*rspamd_worker_signal_handler) (
+               struct rspamd_worker_signal_handler *, void *ud);
 
 struct rspamd_worker_signal_cb {
-       void (*handler) (struct rspamd_worker_signal_handler *, void *ud);
+       rspamd_worker_signal_handler handler;
        void *handler_data;
        struct rspamd_worker_signal_cb *next, *prev;
 };