]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: test-http-client-errors - Use lib-signals API.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 13 Apr 2020 10:21:00 +0000 (12:21 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 22 May 2020 08:42:33 +0000 (08:42 +0000)
Using signal() is not portable for installing a signal handler.

src/lib-http/test-http-client-errors.c

index f77027853313d685dd6faf92506a53d64c280a31..ff076cceebdf9403a495789cebaadd59ee5aac04 100644 (file)
@@ -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;
 }