From: Stephan Bosch Date: Mon, 13 Apr 2020 13:40:23 +0000 (+0200) Subject: lib-smtp: test-smtp-server-errors - Use lib-signals API. X-Git-Tag: 2.3.13~627 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7afecadf1e390906c84d3f0c8ac0ac9f3160a92d;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: test-smtp-server-errors - Use lib-signals API. Using signal() is not portable for installing a signal handler. --- diff --git a/src/lib-smtp/test-smtp-server-errors.c b/src/lib-smtp/test-smtp-server-errors.c index e138022aa9..91ce635ab7 100644 --- a/src/lib-smtp/test-smtp-server-errors.c +++ b/src/lib-smtp/test-smtp-server-errors.c @@ -1,6 +1,7 @@ /* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "lib-signals.h" #include "str.h" #include "array.h" #include "hostpid.h" @@ -2984,6 +2985,8 @@ test_run_client_server(const struct smtp_server_settings *server_set, fd_listen = test_open_server_fd(); if (client_tests_count > 0) { + lib_signals_ioloop_detach(); + client_pids = i_new(pid_t, client_tests_count); for (i = 0; i < client_tests_count; i++) client_pids[i] = (pid_t)-1; @@ -2996,6 +2999,7 @@ test_run_client_server(const struct smtp_server_settings *server_set, client_pids[i] = (pid_t)-1; client_pids_count = 0; hostpid_init(); + lib_signals_deinit(); /* child: client */ i_set_failure_prefix("CLIENT[%u]: ", i + 1); if (debug) @@ -3018,6 +3022,8 @@ test_run_client_server(const struct smtp_server_settings *server_set, exit(1); } } + + lib_signals_ioloop_attach(); } /* parent: server */ @@ -3044,8 +3050,10 @@ test_run_client_server(const struct smtp_server_settings *server_set, 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; @@ -3065,14 +3073,18 @@ static void test_atexit(void) int main(int argc, char *argv[]) { int c; + int ret; + + lib_init(); + lib_signals_init(); 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, "D")) > 0) { switch (c) { @@ -3089,5 +3101,10 @@ int main(int argc, char *argv[]) bind_ip.family = AF_INET; bind_ip.u.ip4.s_addr = htonl(INADDR_LOOPBACK); - return test_run(test_functions); + ret = test_run(test_functions); + + lib_signals_deinit(); + lib_deinit(); + + return ret; }