diff --git a/cport/databuffer.h b/cport/databuffer.h index 0065f67..3f44231 100644 --- a/cport/databuffer.h +++ b/cport/databuffer.h @@ -135,20 +135,26 @@ void db_readline(struct databuffer *db, FILE *input) { // Appends one line from db_append(db, &thisdb); } -void runcmd(const char **command) { // Dumbly runs command +int runcmd(const char **command, bool wait_exit) { // Dumbly runs command fflush(stdout); - if (fork() == 0) { - execvp(command[0], command); + if (fork() == 0) { + execvp(command[0], command); perror(command[0]); - } - wait(0); + } + if (wait_exit) { + int status; + wait(&status); + return status; + } else { + return 0; + } } void db_cmdread(struct databuffer *db, const char **command) { // Appends output (stdout) of command to db struct databuffer thisdb; int stdout_backup = dup(1); dup2(memfd_create("pipe", 0), 1); - runcmd(command); + runcmd(command, true); FILE *proc_out = fdopen(1, "r"); fseek(proc_out, 0, SEEK_SET); db_fread(db, proc_out);