Debugging zombies: pthread_sigmask and sigwait

Mel Flynn rflynn at acsalaska.net
Wed Apr 11 15:58:45 UTC 2012


On 4/11/2012 16:47, Konstantin Belousov wrote:

> What happens, as I guess it, the SIGINFO and SIGCHLD are ignored, so
> kernel do not even bother to queue the signals to the master process.
> Register a dummy signal handler for your signals with sigaction
> before creating 'signal_handler' thread.

Right on the mark. I've modified the test code accordingly and things
work as expected. I've also applied the logic to the Zarafa spooler and
in the logs I'm finally seeing:
child: [79572] E-mail for user mel was accepted by SMTP server
parent: [79565] Received signal 20
                ^^^^^^^^^^^^^^^^^^

Many thanks and for the archives, the diff below sig.
-- 
Mel

diff -r 509d7301c720 spoolerbug/spoolerbug.c
--- a/spoolerbug/spoolerbug.c   Wed Apr 11 05:37:50 2012 -0800
+++ b/spoolerbug/spoolerbug.c   Wed Apr 11 07:35:50 2012 -0800
@@ -12,6 +12,7 @@
 #include <unistd.h> /* vfork */

 #include <stdlib.h> /* arc4random() */
+#include <string.h> /* memset() */
 #include <stdbool.h>
 #include <getopt.h>

@@ -25,6 +26,7 @@
 void *signal_handler(void *);
 int running_server(void);
 void process_signal(int);
+void signal_dummy(int);

 /* globals */
 pthread_t              signal_thread;
@@ -112,6 +114,12 @@
        }
 }

+void
+signal_dummy(int sig __unused)
+{
+       return;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -131,11 +139,19 @@

        if( !bForked )
        {
+               struct sigaction dummies;
+
+               memset(&dummies, 0, sizeof(dummies));
                sigemptyset(&signal_mask);
                sigaddset(&signal_mask, SIGTERM);
                sigaddset(&signal_mask, SIGINT);
                sigaddset(&signal_mask, SIGCHLD);
                sigaddset(&signal_mask, SIGINFO);
+               dummies.sa_handler = signal_dummy;
+               dummies.sa_mask = signal_mask;
+               dummies.sa_flags |= SA_NOCLDSTOP;
+               sigaction(SIGCHLD, &dummies, NULL);
+               sigaction(SIGINFO, &dummies, NULL);
        }

        daemon(1, 1);



More information about the freebsd-hackers mailing list