]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: test-smtp-server-errors - Use lib-signals API.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 13 Apr 2020 13:40:23 +0000 (15:40 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 25 May 2020 15:29:02 +0000 (17:29 +0200)
Using signal() is not portable for installing a signal handler.

src/lib-smtp/test-smtp-server-errors.c

index e138022aa90559c9d8e7e4c42dbfb11922c893d5..91ce635ab7edc6edb9b7698fd5a1cb0624073678 100644 (file)
@@ -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;
 }