From: Timo Sirainen Date: Tue, 19 May 2020 18:02:38 +0000 (+0300) Subject: lib: lib-signals - Replace LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE with LIBSIG_FLAG_IOLOOP_AUT... X-Git-Tag: 2.3.13~470 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bda17bd78313faffba4a964107caa3dc49b12513;p=thirdparty%2Fdovecot%2Fcore.git lib: lib-signals - Replace LIBSIG_FLAG_NO_IOLOOP_AUTOMOVE with LIBSIG_FLAG_IOLOOP_AUTOMOVE 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. --- diff --git a/src/lib-test/test-subprocess.c b/src/lib-test/test-subprocess.c index a856f9df16..e1bd1d237a 100644 --- a/src/lib-test/test-subprocess.c +++ b/src/lib-test/test-subprocess.c @@ -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); diff --git a/src/lib/child-wait.c b/src/lib/child-wait.c index 90f8ec545f..024d81d600 100644 --- a/src/lib/child-wait.c +++ b/src/lib/child-wait.c @@ -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); } diff --git a/src/lib/lib-signals.c b/src/lib/lib-signals.c index 3c23933399..6ffe48d196 100644 --- a/src/lib/lib-signals.c +++ b/src/lib/lib-signals.c @@ -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 */ diff --git a/src/lib/lib-signals.h b/src/lib/lib-signals.h index 874cc5aed0..b6f266c8ee 100644 --- a/src/lib/lib-signals.h +++ b/src/lib/lib-signals.h @@ -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) diff --git a/src/lib/test-lib-signals.c b/src/lib/test-lib-signals.c index e3f7dfd4d9..75d324a835 100644 --- a/src/lib/test-lib-signals.c +++ b/src/lib/test-lib-signals.c @@ -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 */