diff --git a/src/bluewave.c b/src/bluewave.c index 3d5876c..2be7e42 100644 --- a/src/bluewave.c +++ b/src/bluewave.c @@ -316,6 +316,10 @@ void bwave_create_packet() { int tot_areas = 0; int totmsgs = 0; int ret; + char **args; + int arg_count; + char *cmd; + pid_t pid; for (i=0;imail_area_count;j++) { @@ -532,8 +536,26 @@ void bwave_create_packet() { dup2(bbs_stdin, STDIN_FILENO); } - ret = system(buffer); - + args = (char **)malloc(sizeof (char *)); + arg_count = 0; + args[arg_count] = strtok(buffer, " "); + while (args[arg_count] != NULL) { + arg_count++; + args = (char **)realloc(args, sizeof(char *) * (arg_count + 1)); + args[arg_count] = strtok(NULL, " "); + } + cmd = strdup(args[0]); + pid = fork(); + if (pid == 0) { + execvp(cmd, args); + exit(0); + } else if (pid > 0) { + waitpid(pid, &ret, 0); + } else { + ret = -1; + } + free(cmd); + free(args); if (sshBBS) { dup2(stout, STDOUT_FILENO); @@ -783,6 +805,7 @@ void bwave_upload_reply() { int stin; int sterr; sqlite3 *db; + int ret; sqlite3_stmt *res; int rc; char *csql = "CREATE TABLE IF NOT EXISTS email (" @@ -795,7 +818,11 @@ void bwave_upload_reply() { "seen INTEGER);"; char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; char *err_msg = 0; - + char **args; + int arg_count; + char *cmd; + pid_t pid; + int ret; msg_count = 0; snprintf(buffer, 1024, "%s/node%d", conf.bbs_path, mynode); @@ -845,8 +872,26 @@ void bwave_upload_reply() { dup2(bbs_stderr, STDERR_FILENO); dup2(bbs_stdin, STDIN_FILENO); } - system(buffer); - + args = (char **)malloc(sizeof (char *)); + arg_count = 0; + args[arg_count] = strtok(buffer, " "); + while (args[arg_count] != NULL) { + arg_count++; + args = (char **)realloc(args, sizeof(char *) * (arg_count + 1)); + args[arg_count] = strtok(NULL, " "); + } + cmd = strdup(args[0]); + pid = fork(); + if (pid == 0) { + execvp(cmd, args); + exit(0); + } else if (pid > 0) { + waitpid(pid, &ret, 0); + } else { + ret = -1; + } + free(cmd); + free(args); if (sshBBS) { dup2(stout, STDOUT_FILENO);