}
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')))
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);
}
}