From 9bc8856ce6e4488e7e8b37be9e93bee896b04e37 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Sun, 12 Apr 2020 18:12:16 +0200 Subject: [PATCH] lib-http: test-http-payload - Use lib-signals API. Using signal() is not portable for installing a signal handler. --- src/lib-http/test-http-payload.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib-http/test-http-payload.c b/src/lib-http/test-http-payload.c index 1a01898b6f..6dcfd4ea75 100644 --- a/src/lib-http/test-http-payload.c +++ b/src/lib-http/test-http-payload.c @@ -1,6 +1,7 @@ /* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "lib-signals.h" #include "str.h" #include "llist.h" #include "path-util.h" @@ -1612,11 +1613,14 @@ test_run_client_server( failure = NULL; test_open_server_fd(); + lib_signals_ioloop_detach(); + if ((server_pid = fork()) == (pid_t)-1) i_fatal("fork() failed: %m"); if (server_pid == 0) { server_pid = (pid_t)-1; hostpid_init(); + lib_signals_deinit(); if (debug) i_debug("server: PID=%s", my_pid); i_set_failure_prefix("SERVER: "); @@ -1636,6 +1640,8 @@ test_run_client_server( } i_close_fd(&fd_listen); + lib_signals_ioloop_attach(); + if (debug) i_debug("client: PID=%s", my_pid); i_set_failure_prefix("CLIENT: "); @@ -2234,8 +2240,10 @@ static void (*const test_functions[])(void) = { volatile sig_atomic_t terminating = 0; -static void test_signal_handler(int signo) +static void test_signal_handler(const siginfo_t *si, void *context ATTR_UNUSED) { + int signo = si->si_signo; + if (terminating != 0) raise(signo); terminating = 1; @@ -2258,17 +2266,18 @@ int main(int argc, char *argv[]) int ret; lib_init(); + lib_signals_init(); #ifdef HAVE_OPENSSL ssl_iostream_openssl_init(); #endif atexit(test_atexit); - (void)signal(SIGPIPE, SIG_IGN); - (void)signal(SIGTERM, test_signal_handler); - (void)signal(SIGQUIT, test_signal_handler); - (void)signal(SIGINT, test_signal_handler); - (void)signal(SIGSEGV, test_signal_handler); - (void)signal(SIGABRT, test_signal_handler); + lib_signals_ignore(SIGPIPE, TRUE); + lib_signals_set_handler(SIGTERM, 0, test_signal_handler, NULL); + lib_signals_set_handler(SIGQUIT, 0, test_signal_handler, NULL); + lib_signals_set_handler(SIGINT, 0, test_signal_handler, NULL); + lib_signals_set_handler(SIGSEGV, 0, test_signal_handler, NULL); + lib_signals_set_handler(SIGABRT, 0, test_signal_handler, NULL); while ((c = getopt(argc, argv, "DS")) > 0) { switch (c) { @@ -2294,6 +2303,7 @@ int main(int argc, char *argv[]) #ifdef HAVE_OPENSSL ssl_iostream_openssl_deinit(); #endif + lib_signals_deinit(); lib_deinit(); return ret; } -- 2.47.3