Proposed Patch for Zombies Left by Dpi_start_dpid() in dpi.c

JG <jgaffney-W1WbbPd4oPN/W2okNb46yti2O/[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
It seems that the dpid children forked by Dpi_start_dpid() in dpi.c
are not reaped when they terminate themselves after a period of
inactivity while the parent dillo process is still running.  The patch
below is simply to reap these zombies.  The SIGCHLD handler should
probably do more, but I am not yet familiar enough with Dillo to know
what.

I believe this patch adheres to the Dillo rules of coding style, but
am new to the list and a novice at Dillo patching.  And hence also
apologies to Jorge for this duplication of a previous communication by
private email (although with one small change to get the patch to
compile under OpenBSD as well as Linux).

########  BEGIN PATCH  ########

--- a/src/IO/dpi.c	2013-01-27 12:26:38.000000000 -0500
+++ b/src/IO/dpi.c	2013-08-27 14:58:07.995235867 -0400
@@ -33,6 +33,8 @@
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#include <sys/wait.h>
+#include <signal.h>
 
 #include "../msg.h"
 #include "../klist.h"
@@ -331,16 +333,33 @@
    }
 }
 
+static void Sigchld_handler (int signum) {
+  int status;
+  waitpid (-1, &status, WNOHANG);
+  }
+
 /*
  * Start dpid.
  * Return: 0 starting now, 1 Error.
  */
 static int Dpi_start_dpid(void)
 {
+   static int install_sigchld_handler_flag = TRUE;
    pid_t pid;
    int st_pipe[2], ret = 1;
    char *answer;
 
+   if ( install_sigchld_handler_flag ) {
+     /* Install SIGCHLD handler. */
+     struct sigaction sa;
+     sa.sa_handler = Sigchld_handler;
+     sigemptyset(&sa.sa_mask);
+     sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
+     if (sigaction(SIGCHLD, &sa, 0))
+         MSG ("Unable to install SIGCHLD handler.\n");
+     install_sigchld_handler_flag = FALSE;
+     }
+
    /* create a pipe to track our child's status */
    if (pipe(st_pipe))
       return 1;

########  END PATCH  ########
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.