prevent zombie processes on cmd_extscript
authorpk910 <philipp@zoelle1.de>
Fri, 4 Nov 2011 04:05:06 +0000 (05:05 +0100)
committerpk910 <philipp@zoelle1.de>
Fri, 4 Nov 2011 04:05:06 +0000 (05:05 +0100)
src/cmd_neonserv_extscript.c

index 2d7e0bd80c29e3fa9e625d2e89a41ff665c29794..37d6f9109805a5b0e95b0009440864d061b142c6 100644 (file)
@@ -117,6 +117,9 @@ CMD_BIND(neonserv_cmd_extscript) {
         struct ClientSocket *textbot = getTextBot();
         pid_t pID = fork();
         if (pID == 0) { //We're the child process :D
+            pID = fork();
+            if(pID < 0) exit(EXIT_FAILURE);
+            if(pID != 0) exit(EXIT_SUCCESS);
             char *a;
             while (fgets(command, 1024, fp) != NULL) {
                 if((a = strchr(command, '\n'))) 
@@ -127,12 +130,13 @@ CMD_BIND(neonserv_cmd_extscript) {
                     reply(textbot, user, "%s", command);
             }
             pclose(fp);
-            exit(0);
+            exit(EXIT_FAILURE);
         } else if (pID < 0) {
             reply(getTextBot(), user, "internal bot error - please contact an administrator!");
             pclose(fp);
         } else {
             //parent bot - continue program
+            wait(NULL);
         }
     } else {
         //error