summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libserver/worker_util.c32
-rw-r--r--src/libserver/worker_util.h2
-rw-r--r--src/rspamd.h4
3 files changed, 24 insertions, 14 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);
/**
diff --git a/src/rspamd.h b/src/rspamd.h
index a716c3788..b2157bd3e 100644
--- a/src/rspamd.h
+++ b/src/rspamd.h
@@ -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;
};