]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: lib-signals - Replace LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE with LIBSIG_FLAG_IOLOOP_AUT...
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 19 May 2020 18:02:38 +0000 (21:02 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 2 Jul 2020 08:24:55 +0000 (08:24 +0000)
There aren't many signal handlers that actually want to move automatically.
It's just causing accidental bugs when signal handlers are run in
unexpected ioloops.

src/lib-test/test-subprocess.c
src/lib/child-wait.c
src/lib/lib-signals.c
src/lib/lib-signals.h
src/lib/test-lib-signals.c

index a856f9df161af5ac5508fcfdf83f6d62fffd15d0..e1bd1d237ae842a5d4c9d6d19842aa37ab6ac160 100644 (file)
@@ -52,12 +52,15 @@ test_subprocess_child(int (*func)(void *context), void *context,
        lib_signals_deinit();
        lib_signals_init();
 
-       lib_signals_set_handler(SIGTERM, LIBSIG_FLAG_DELAYED,
-                               test_subprocess_signal, NULL);
-       lib_signals_set_handler(SIGQUIT, LIBSIG_FLAG_DELAYED,
-                               test_subprocess_signal, NULL);
-       lib_signals_set_handler(SIGINT, LIBSIG_FLAG_DELAYED,
-                               test_subprocess_signal, NULL);
+       lib_signals_set_handler(SIGTERM,
+               LIBSIG_FLAG_DELAYED | LIBSIG_FLAG_IOLOOP_AUTOMOVE,
+               test_subprocess_signal, NULL);
+       lib_signals_set_handler(SIGQUIT,
+               LIBSIG_FLAG_DELAYED | LIBSIG_FLAG_IOLOOP_AUTOMOVE,
+               test_subprocess_signal, NULL);
+       lib_signals_set_handler(SIGINT,
+               LIBSIG_FLAG_DELAYED | LIBSIG_FLAG_IOLOOP_AUTOMOVE,
+               test_subprocess_signal, NULL);
 
        ret = func(context);
 
index 90f8ec545fae70fd4f1e0c0328b847a8c779f4d9..024d81d600851551389aafc825548c51329cd589 100644 (file)
@@ -112,8 +112,7 @@ void child_wait_init(void)
 
        hash_table_create_direct(&child_pids, default_pool, 0);
 
-       lib_signals_set_handler(SIGCHLD,
-               LIBSIG_FLAGS_SAFE | LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE,
+       lib_signals_set_handler(SIGCHLD, LIBSIG_FLAGS_SAFE,
                sigchld_handler, NULL);
 }
 
index 3c239333992d4d37265f10002326ed3a8a95838b..6ffe48d196655580f371c87b5ff92a6cabb326de 100644 (file)
@@ -180,7 +180,7 @@ static void signal_handle_shadowed(void)
                for (h = signal_handlers[sis[i].si_signo]; h != NULL;
                     h = h->next) {
                        if ((h->flags & LIBSIG_FLAG_DELAYED) == 0 ||
-                           (h->flags & LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE) == 0)
+                           (h->flags & LIBSIG_FLAG_IOLOOP_AUTOMOVE) != 0)
                                continue;
                        if (h->shadowed &&
                            h->current_ioloop != current_ioloop) {
@@ -281,7 +281,7 @@ static void ATTR_NULL(1) signal_read(void *context ATTR_UNUSED)
                                   context */
                                continue;
                        }
-                       if ((h->flags & LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE) != 0 &&
+                       if ((h->flags & LIBSIG_FLAG_IOLOOP_AUTOMOVE) == 0 &&
                            h->current_ioloop != current_ioloop) {
                                /* cannot run handler in current ioloop
                                   (shadowed) */
@@ -546,7 +546,7 @@ void lib_signals_switch_ioloop(int signo,
        for (h = signal_handlers[signo]; h != NULL; h = h->next) {
                if (h->handler == handler && h->context == context) {
                        i_assert((h->flags & LIBSIG_FLAG_DELAYED) != 0);
-                       i_assert((h->flags & LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE) != 0);
+                       i_assert((h->flags & LIBSIG_FLAG_IOLOOP_AUTOMOVE) == 0);
                        h->current_ioloop = current_ioloop;
                        /* check whether we can now handle any shadowed delayed
                           signals */
index 874cc5aed0dd5c6e881d98290676605dc67818e6..b6f266c8ee0c6ae43ec3316c19fb60d659930f22 100644 (file)
@@ -9,9 +9,9 @@ enum libsig_flags {
        LIBSIG_FLAG_DELAYED     = 0x01,
        /* Restart syscalls instead of having them fail with EINTR */
        LIBSIG_FLAG_RESTART     = 0x02,
-       /* Don't automatically shift delayed signal handling for this signal
+       /* Automatically shift delayed signal handling for this signal
           to a newly started ioloop. */
-       LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE = 0x04,
+       LIBSIG_FLAG_IOLOOP_AUTOMOVE = 0x04,
 };
 #define LIBSIG_FLAGS_SAFE (LIBSIG_FLAG_DELAYED | LIBSIG_FLAG_RESTART)
 
index e3f7dfd4d959e7059996b2faa7e30a3071c9d36a..75d324a835eb787969361f35ba0ea8590c91d48b 100644 (file)
@@ -49,7 +49,8 @@ test_lib_signals_delayed(void)
        i_zero(&tctx);
 
        lib_signals_init();
-       lib_signals_set_handler(SIGALRM, LIBSIG_FLAGS_SAFE,
+       lib_signals_set_handler(SIGALRM,
+               LIBSIG_FLAGS_SAFE | LIBSIG_FLAG_IOLOOP_AUTOMOVE,
                signal_handler_delayed, &tctx);
 
        ioloop = io_loop_create();
@@ -75,7 +76,8 @@ test_lib_signals_delayed(void)
        ioloop = io_loop_create();
 
        lib_signals_init();
-       lib_signals_set_handler(SIGALRM, LIBSIG_FLAGS_SAFE,
+       lib_signals_set_handler(SIGALRM,
+               LIBSIG_FLAGS_SAFE | LIBSIG_FLAG_IOLOOP_AUTOMOVE,
                signal_handler_delayed, &tctx);
 
        to_kill = timeout_add_short(200, kill_timeout, &tctx);
@@ -108,7 +110,8 @@ test_lib_signals_delayed_nested_ioloop(void)
        i_zero(&tctx);
 
        lib_signals_init();
-       lib_signals_set_handler(SIGALRM, LIBSIG_FLAGS_SAFE,
+       lib_signals_set_handler(SIGALRM,
+               LIBSIG_FLAGS_SAFE | LIBSIG_FLAG_IOLOOP_AUTOMOVE,
                signal_handler_delayed, &tctx);
 
        /* briefly run outer ioloop */
@@ -154,8 +157,7 @@ test_lib_signals_delayed_no_ioloop_automove(void)
        ioloop1 = io_loop_create();
 
        lib_signals_init();
-       lib_signals_set_handler(SIGALRM,
-               LIBSIG_FLAGS_SAFE | LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE,
+       lib_signals_set_handler(SIGALRM, LIBSIG_FLAGS_SAFE,
                signal_handler_delayed, &tctx);
 
        /* briefly run outer ioloop */
@@ -201,8 +203,7 @@ test_lib_signals_delayed_no_ioloop_automove(void)
        ioloop1 = io_loop_create();
 
        lib_signals_init();
-       lib_signals_set_handler(SIGALRM,
-               LIBSIG_FLAGS_SAFE | LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE,
+       lib_signals_set_handler(SIGALRM, LIBSIG_FLAGS_SAFE,
                signal_handler_delayed, &tctx);
 
        /* briefly run outer ioloop */