diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-22 20:35:06 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-22 20:35:06 +0100 |
commit | 02f3d42c14e272b6afaf791e59523dfbc58b0221 (patch) | |
tree | 11886633dad8d35fdcdf06f8f3b8c999c9608927 /src/libserver | |
parent | e460a6dc4b48f3bb31b072ee058475f08b6432d1 (diff) | |
download | rspamd-02f3d42c14e272b6afaf791e59523dfbc58b0221.tar.gz rspamd-02f3d42c14e272b6afaf791e59523dfbc58b0221.zip |
[Feature] Allow to reuse signal handlers chains
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/worker_util.c | 32 | ||||
-rw-r--r-- | src/libserver/worker_util.h | 2 |
2 files changed, 21 insertions, 13 deletions
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index 88e775b54..9dfb6d5e6 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -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); diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h index 5e33c940d..1fc4565cb 100644 --- a/src/libserver/worker_util.h +++ b/src/libserver/worker_util.h @@ -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); /** |