diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index b450bf1..187a287 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -24,14 +24,14 @@ void cmd_close(void* ptr) cmd_t* content = ptr; if (content->input[0] > 2) close(content->input[0]); - content->input[0] = -1; + // content->input[0] = -1; if (content->input[1] > 2) close(content->input[1]); - content->input[1] = -1; + // content->input[1] = -1; if (content->output[0] > 2) close(content->output[0]); - content->output[0] = -1; + // content->output[0] = -1; if (content->output[1] > 2) close(content->output[1]); - content->output[1] = -1; + // content->output[1] = -1; } diff --git a/src/exec/exec.c b/src/exec/exec.c index 3b28386..9c0df53 100644 --- a/src/exec/exec.c +++ b/src/exec/exec.c @@ -80,6 +80,36 @@ void add_fd(int fds[2], int fd) fds[1] = fd; } +void cmds_wait(lst** cmds, data_t* data) +{ + lst* current = *cmds; + cmd_t* content; + int exit_status; + + while (current) + { + content = current->content; + if (content->pid != -1 && content->input[0] != -2 && content->output[0] != -2) + { + waitpid(content->pid, &exit_status, 0); + if (WIFSIGNALED(exit_status)) + { + if (exit_status == 131) + { + printf("Quit (core dumped)"); + data->status_code = 131; + } + else + data->status_code = 130; + printf("\n"); + } + else + data->status_code = WEXITSTATUS(exit_status); + } + current = current->next; + } +} + int cmds_list_exec(lst** cmds, data_t *data) { lst* current = *cmds; @@ -110,5 +140,6 @@ int cmds_list_exec(lst** cmds, data_t *data) } current = current->next; } + cmds_wait(cmds, data); return 0; }