tReplaced dodgy single fork process spawning code with much nicer double fork, to avoid creating zombie processes. - vaccinewars - be a doctor and try to vaccinate the world
git clone git://src.adamsgaard.dk/vaccinewars
Log
Files
Refs
README
LICENSE
---
commit 147442dcbe60931edd8763928f6913c2cca6310f
parent 064d97cc35949782635605a9d9caf3b648ed8f52
Author: Ben Webb 
Date:   Fri, 24 May 2002 11:18:59 +0000

Replaced dodgy single fork process spawning code with much nicer double
fork, to avoid creating zombie processes.


Diffstat:
  M src/gtkport/gtkport.c               |      18 ++++++++++++++----

1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/gtkport/gtkport.c b/src/gtkport/gtkport.c
t@@ -26,6 +26,7 @@
 
 #ifndef CYGWIN
 #include           /* For pid_t (fork) */
+#include            /* For wait */
 #ifdef HAVE_UNISTD_H
 #include              /* For fork and execv */
 #endif
t@@ -5275,6 +5276,7 @@ static gboolean gtk_url_triggered(GtkWidget *widget, GdkEventButton *event,
 #ifdef HAVE_FORK
   gchar *bin, *target, *args[3];
   pid_t pid;
+  int status;
 
   target = (gchar *)gtk_object_get_data(GTK_OBJECT(widget), "target");
   bin = (gchar *)gtk_object_get_data(GTK_OBJECT(widget), "bin");
t@@ -5283,11 +5285,19 @@ static gboolean gtk_url_triggered(GtkWidget *widget, GdkEventButton *event,
     args[0] = bin;
     args[1] = target;
     args[2] = NULL;
+    /* Fork twice so that the spawned process gets init as its parent */
     pid = fork();
-    if (pid == 0) {
-      execv(bin, args);
-      g_print("dopewars: cannot execute %s\n", bin);
-      _exit(1);
+    if (pid > 0) {
+      waitpid(-1, &status, WNOHANG);
+    } else if (pid == 0) {
+      pid = fork();
+      if (pid == 0) {
+        execv(bin, args);
+        g_print("dopewars: cannot execute %s\n", bin);
+        exit(1);
+      } else {
+        exit(0);
+      }
     }
   }
 #endif