changeset 128:713879a7ca10

Wait for forked processes, to prevent a zombie apocalypse.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 30 Oct 2010 12:15:55 +0300
parents f741718d13c5
children 4235ff4ced04
files nnchat.c
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Fri Oct 29 23:12:23 2010 +0300
+++ b/nnchat.c	Sat Oct 30 12:15:55 2010 +0300
@@ -11,6 +11,8 @@
 #ifdef __WIN32
 /* Undefine because both windows.h and curses.h #define it */
 #undef MOUSE_MOVED
+#else
+#include <sys/wait.h>
 #endif
 #include <curses.h>
 
@@ -578,7 +580,6 @@
         /* Open given username's profile via firefox in a new tab */
         char *name = trimLeft(buf + 3),
              *browser = getenv("BROWSER");
-        pid_t pid;
 
         if (browser == NULL)
             browser = "firefox";
@@ -589,12 +590,22 @@
         snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr);
         th_free(tmpStr);
 
+#ifdef __WIN32
+        
+#else
+        {
+        int status;
+        pid_t pid;
         if ((pid = fork()) < 0) {
             printMsg("Could not create sub-process!\n");
         } else if (pid == 0) {
             execlp(browser, browser, "-remote", tmpBuf, NULL);
-            exit(errno);
+            _exit(errno);
         }
+        
+        wait(&status);
+        }
+#endif
         return 0;
     } else if (!strncasecmp(buf, "/to ", 4)) {
         /* Set private messaging target */