diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-24 21:27:16 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-24 21:46:17 +0100 |
commit | bd8172153357a1f51ed2ce450a15af322a074897 (patch) | |
tree | 4689f27c38296dd0d2dfc0152c80989459a73687 /src/libserver/worker_util.c | |
parent | e8c4bf889840913f8015eeb7e665ec90904eb6cf (diff) | |
download | rspamd-bd8172153357a1f51ed2ce450a15af322a074897.tar.gz rspamd-bd8172153357a1f51ed2ce450a15af322a074897.zip |
[Feature] Add termination callbacks for workers
Diffstat (limited to 'src/libserver/worker_util.c')
-rw-r--r-- | src/libserver/worker_util.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index b7aa5035f..2a0a76d04 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -89,6 +89,17 @@ rspamd_get_worker_by_type (struct rspamd_config *cfg, GQuark type) sig_atomic_t wanna_die = 0; +static void +rspamd_worker_terminate_handlers (struct rspamd_worker *w) +{ + guint i; + void (*cb)(struct rspamd_worker *); + + for (i = 0; i < w->finish_actions->len; i ++) { + cb = g_ptr_array_index (w->finish_actions, i); + cb (w); + } +} /* * Config reload is designed by sending sigusr2 to active workers and pending shutdown of them */ @@ -102,6 +113,7 @@ rspamd_worker_usr2_handler (struct rspamd_worker_signal_handler *sigh, void *arg tv.tv_sec = SOFT_SHUTDOWN_TIME; tv.tv_usec = 0; wanna_die = 1; + rspamd_worker_terminate_handlers (sigh->worker); rspamd_default_log_function (G_LOG_LEVEL_INFO, sigh->worker->srv->server_pool->tag.tagname, sigh->worker->srv->server_pool->tag.uid, @@ -134,6 +146,7 @@ rspamd_worker_term_handler (struct rspamd_worker_signal_handler *sigh, void *arg G_STRFUNC, "terminating after receiving signal %s", g_strsignal (sigh->signo)); + rspamd_worker_terminate_handlers (sigh->worker); wanna_die = 1; tv.tv_sec = 0; tv.tv_usec = 0; @@ -525,6 +538,7 @@ rspamd_fork_worker (struct rspamd_main *rspamd_main, memcpy (wrk->cf, cf, sizeof (struct rspamd_worker_conf)); wrk->index = index; wrk->ctx = cf->ctx; + wrk->finish_actions = g_ptr_array_new (); wrk->pid = fork (); |