From 1b3cffe710e805d2d95bc622f906d7d15440931d Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 4 Nov 2011 20:05:00 +0100 Subject: [PATCH] retried to fix the zombie problem --- src/cmd_neonserv_extscript.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/cmd_neonserv_extscript.c b/src/cmd_neonserv_extscript.c index 37d6f91..21aad8b 100644 --- a/src/cmd_neonserv_extscript.c +++ b/src/cmd_neonserv_extscript.c @@ -111,15 +111,15 @@ CMD_BIND(neonserv_cmd_extscript) { } command[commandpos] = '\0'; //we should now have a valid command - FILE *fp; - fp = popen(command, "r"); - if (fp) { - 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); + 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); + FILE *fp; + fp = popen(command, "r"); + if (fp) { char *a; while (fgets(command, 1024, fp) != NULL) { if((a = strchr(command, '\n'))) @@ -130,18 +130,15 @@ CMD_BIND(neonserv_cmd_extscript) { reply(textbot, user, "%s", command); } pclose(fp); - 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); + reply(getTextBot(), user, "internal bot error - please contact an administrator!"); } - } else { - //error + exit(EXIT_FAILURE); + } else if (pID < 0) { reply(getTextBot(), user, "internal bot error - please contact an administrator!"); - return; + } else { + //parent bot - continue program + wait(NULL); } } -- 2.20.1