apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@attglobal.net>
Subject [PATCH] PR 9168 don't leave zombie processes on Mac OS X with mod_cgid
Date Tue, 21 May 2002 14:58:58 GMT
mod_cgid does apr_signal(SIGCHLD, SIG_IGN)...  assuming that we want
this to avoid zombies, does anybody have a better solution than the
following?

Index: srclib/apr/threadproc/unix/signals.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/unix/signals.c,v
retrieving revision 1.46
diff -u -r1.46 signals.c
--- srclib/apr/threadproc/unix/signals.c	10 May 2002 03:56:44 -0000	1.46
+++ srclib/apr/threadproc/unix/signals.c	21 May 2002 14:53:40 -0000
@@ -87,6 +87,17 @@
 
 #if APR_HAVE_SIGACTION
 
+#ifdef DARWIN
+static void avoid_zombies(int signo)
+{
+    int exit_status;
+
+    while (waitpid(-1, &exit_status, WNOHANG) > 0) {
+        /* do nothing */
+    }
+}
+#endif /* DARWIN */
+
 /*
  * Replace standard signal() with the more reliable sigaction equivalent
  * from W. Richard Stevens' "Advanced Programming in the UNIX Environment"
@@ -110,6 +121,15 @@
      */
     if ((signo == SIGCHLD) && (func == SIG_IGN)) {
         act.sa_flags |= SA_NOCLDWAIT;
+    }
+#endif
+#ifdef DARWIN
+    /* ignoring SIGCHLD or leaving the default disposition doesn't avoid zombies,
+     * and there is no SA_NOCLDWAIT flag, so catch the signal and reap status in 
+     * the handler to avoid zombies
+     */
+    if ((signo == SIGCHLD) && (func == SIG_IGN)) {
+        act.sa_handler = avoid_zombies;
     }
 #endif
     if (sigaction(signo, &act, &oact) < 0)

-- 
Jeff Trawick | trawick@attglobal.net
Born in Roswell... married an alien...

Mime
View raw message