]> source.dussan.org Git - rspamd.git/commitdiff
Block signals when exiting event loop
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Oct 2015 21:38:34 +0000 (22:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Oct 2015 21:38:34 +0000 (22:38 +0100)
src/controller.c
src/fuzzy_storage.c
src/http_proxy.c
src/libserver/worker_util.c
src/libserver/worker_util.h
src/lua_worker.c
src/rspamd.c
src/smtp_proxy.c
src/worker.c

index 534db37e8ad52da0859b080e1ff291d122c0ade5..17494b899e2afe56aa973c2201d60bda396bd6be 100644 (file)
@@ -2548,6 +2548,7 @@ start_controller_worker (struct rspamd_worker *worker)
        rspamd_stat_init (worker->srv->cfg);
 
        event_base_loop (ctx->ev_base, 0);
+       rspamd_worker_block_signals ();
 
        g_mime_shutdown ();
        rspamd_stat_close ();
index 0baebdf24d258c309a214940d6da959b67320a03..4d4171e9958e374a369fa7f971d205aa92603718 100644 (file)
@@ -605,6 +605,7 @@ start_fuzzy (struct rspamd_worker *worker)
        rspamd_map_watch (worker->srv->cfg, ctx->ev_base);
 
        event_base_loop (ctx->ev_base, 0);
+       rspamd_worker_block_signals ();
 
        rspamd_fuzzy_backend_sync (ctx->backend, ctx->expire, TRUE);
        rspamd_fuzzy_backend_close (ctx->backend);
index c35b771acf5b6e471fa1525f1521a43eb49a44be..85ee1c4bd87f7cd1cb7aac7dc8d91d8020d3cd06 100644 (file)
@@ -471,6 +471,7 @@ start_http_proxy (struct rspamd_worker *worker)
        event_add (&ctx->rotate_ev, &rot_tv);
 
        event_base_loop (ctx->ev_base, 0);
+       rspamd_worker_block_signals ();
 
        g_mime_shutdown ();
        rspamd_log_close (worker->srv->logger);
index 5aff8883b90114e18e4f5908e7a0ff45adf6514f..0e4a29a327a4a7f0bdbd98a9b4f4883872e7cabf 100644 (file)
@@ -511,3 +511,17 @@ rspamd_fork_worker (struct rspamd_main *rspamd_main,
 
        return cur;
 }
+
+void
+rspamd_worker_block_signals (void)
+{
+       sigset_t set;
+
+       sigemptyset (&set);
+       sigaddset (&set, SIGTERM);
+       sigaddset (&set, SIGINT);
+       sigaddset (&set, SIGHUP);
+       sigaddset (&set, SIGUSR1);
+       sigaddset (&set, SIGUSR2);
+       sigprocmask (SIG_BLOCK, &set, NULL);
+}
index 30fbe904f357ad015770ecbee91366cd05c983ba..74118092297ccd06236aadeb61f5cd6018b6c8ca 100644 (file)
@@ -111,6 +111,11 @@ worker_t * rspamd_get_worker_by_type (struct rspamd_config *cfg, GQuark type);
 
 void rspamd_worker_stop_accept (struct rspamd_worker *worker);
 
+/**
+ * Block signals before terminations
+ */
+void rspamd_worker_block_signals (void);
+
 /**
  * Fork new worker with the specified configuration
  */
index 7e15c632a791f153fc479fa77cfb7cae9b77a45a..1e37419a25b5d0ddc2fc6caa89a906efa5752051 100644 (file)
@@ -394,6 +394,8 @@ start_lua_worker (struct rspamd_worker *worker)
        rspamd_map_watch (worker->srv->cfg, ctx->ev_base);
 
        event_base_loop (ctx->ev_base, 0);
+       rspamd_worker_block_signals ();
+
        luaL_unref (L, LUA_REGISTRYINDEX, ctx->cbref_accept);
        if (ctx->cbref_fin != 0) {
                /* Call finalizer function */
index 21563bf18b7434c7acd88ba140a750d156a9a9e8..2377f8892e1c653e002b3a41dc1b1afb83571e8a 100644 (file)
@@ -1043,12 +1043,7 @@ main (gint argc, gchar **argv, gchar **env)
 
        event_base_loop (ev_base, 0);
        /* We need to block signals unless children are waited for */
-       sigaddset (&signals.sa_mask, SIGTERM);
-       sigaddset (&signals.sa_mask, SIGINT);
-       sigaddset (&signals.sa_mask, SIGHUP);
-       sigaddset (&signals.sa_mask, SIGUSR1);
-       sigaddset (&signals.sa_mask, SIGUSR2);
-       sigprocmask (SIG_BLOCK, &signals.sa_mask, NULL);
+       rspamd_worker_block_signals ();
 
        if (control_fd != -1) {
                event_del (&control_ev);
index 40e5ce4737b8b8a0afa38622255ee4aaed4171ef..0ae9c70c48752e4e28666fed7ffb299eb863f27c 100644 (file)
@@ -1079,6 +1079,7 @@ start_smtp_proxy (struct rspamd_worker *worker)
        umask (S_IWGRP | S_IWOTH | S_IROTH | S_IRGRP);
 
        event_base_loop (ctx->ev_base, 0);
+       rspamd_worker_block_signals ();
 
        rspamd_log_close (worker->srv->logger);
        exit (EXIT_SUCCESS);
index cde69c2a16e6dd1887bcc240afaf9d0c02d2ffd7..8256b879e6460ef3d4b659f6a22f7cfeddfb63ec 100644 (file)
@@ -360,6 +360,7 @@ start_worker (struct rspamd_worker *worker)
        rspamd_stat_init (worker->srv->cfg);
 
        event_base_loop (ctx->ev_base, 0);
+       rspamd_worker_block_signals ();
 
        g_mime_shutdown ();
        rspamd_stat_close ();