From: Stephan Bosch Date: Mon, 13 Apr 2020 10:21:00 +0000 (+0200) Subject: lib-http: test-http-client-errors - Use lib-signals API. X-Git-Tag: 2.3.13~709 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a17eb0404d1dd1f786f1bb2faaff4393d6cf228;p=thirdparty%2Fdovecot%2Fcore.git lib-http: test-http-client-errors - Use lib-signals API. Using signal() is not portable for installing a signal handler. --- diff --git a/src/lib-http/test-http-client-errors.c b/src/lib-http/test-http-client-errors.c index f770278533..ff076cceeb 100644 --- a/src/lib-http/test-http-client-errors.c +++ b/src/lib-http/test-http-client-errors.c @@ -1,6 +1,7 @@ /* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "lib-signals.h" #include "str.h" #include "str-sanitize.h" #include "hostpid.h" @@ -3418,6 +3419,8 @@ test_run_client_server(const struct http_client_settings *client_set, test_server_deinit = NULL; test_server_input = NULL; + lib_signals_ioloop_detach(); + if (server_tests_count > 0) { int fds[server_tests_count]; @@ -3439,6 +3442,7 @@ test_run_client_server(const struct http_client_settings *client_set, server_pids[i] = (pid_t)-1; server_pids_count = 0; hostpid_init(); + lib_signals_deinit(); /* child: server */ i_set_failure_prefix("SERVER[%u]: ", i + 1); if (debug) @@ -3474,6 +3478,7 @@ test_run_client_server(const struct http_client_settings *client_set, if (dns_pid == 0) { dns_pid = (pid_t)-1; hostpid_init(); + lib_signals_deinit(); /* child: server */ i_set_failure_prefix("DNS: "); if (debug) @@ -3490,6 +3495,8 @@ test_run_client_server(const struct http_client_settings *client_set, i_close_fd(&fd_listen); } + lib_signals_ioloop_attach(); + /* parent: client */ i_set_failure_prefix("CLIENT: "); if (debug) @@ -3515,8 +3522,10 @@ test_run_client_server(const struct http_client_settings *client_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; @@ -3536,14 +3545,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) { @@ -3560,5 +3573,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; }