]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: test-smtp-client-errors - Use lib-signals API.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 13 Apr 2020 12:18:05 +0000 (14:18 +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-client-errors.c

index fe2fd27c1227963f6386b61a31fe9a948f22f3dc..7c5b2b0a594d11ba5a4db690b4bca4f3b1e2cc3b 100644 (file)
@@ -3874,6 +3874,8 @@ test_run_client_server(const struct smtp_client_settings *client_set,
        server_pids = NULL;
        server_pids_count = 0;
 
+       lib_signals_ioloop_detach();
+
        if (server_tests_count > 0) {
                int fds[server_tests_count];
 
@@ -3895,6 +3897,7 @@ test_run_client_server(const struct smtp_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)
@@ -3930,6 +3933,7 @@ test_run_client_server(const struct smtp_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)
@@ -3946,6 +3950,8 @@ test_run_client_server(const struct smtp_client_settings *client_set,
                i_close_fd(&fd_listen);
        }
 
+       lib_signals_ioloop_attach();
+
        /* parent: client */
        i_set_failure_prefix("CLIENT: ");
        if (debug)
@@ -3971,8 +3977,10 @@ test_run_client_server(const struct smtp_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;
@@ -3992,14 +4000,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) {
@@ -4016,5 +4028,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;
 }