From c368cf80eadd60f14d513aea342c91f550b5eaea Mon Sep 17 00:00:00 2001 From: whaffman Date: Tue, 18 Feb 2025 16:00:38 +0100 Subject: [PATCH] exit status at the end of the executor_execute_pipeline --- inc/executor.h | 6 +++--- inc/typedef.h | 2 +- src/executor/executor_execute_pipeline.c | 11 ++++++++--- src/executor/executor_fork.c | 12 ++++++------ src/utils/simple_builtins.c | 7 +++++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/inc/executor.h b/inc/executor.h index e6c145e..61d0075 100644 --- a/inc/executor.h +++ b/inc/executor.h @@ -6,7 +6,7 @@ /* By: willem +#+ */ /* +#+ */ /* Created: 2025/02/08 17:06:07 by willem #+# #+# */ -/* Updated: 2025/02/13 14:57:13 by whaffman ######## odam.nl */ +/* Updated: 2025/02/18 15:45:27 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -17,9 +17,9 @@ char *executor_absolute_path(t_list *env, char *cmd); void executor_child(t_command *command); -int executor_fork(t_command *command); +pid_t executor_fork(t_command *command); void executor_create_pipes(t_minishell *minishell); -void executor_execute_pipeline(t_minishell *minishell); +int executor_execute_pipeline(t_minishell *minishell); void executor_close_fds(int n_fds); diff --git a/inc/typedef.h b/inc/typedef.h index 9039e04..817f5e0 100644 --- a/inc/typedef.h +++ b/inc/typedef.h @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */ -/* Updated: 2025/02/13 14:27:07 by whaffman ######## odam.nl */ +/* Updated: 2025/02/18 14:34:39 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/executor/executor_execute_pipeline.c b/src/executor/executor_execute_pipeline.c index 970de1b..e86e9e3 100644 --- a/src/executor/executor_execute_pipeline.c +++ b/src/executor/executor_execute_pipeline.c @@ -6,24 +6,29 @@ /* By: willem +#+ */ /* +#+ */ /* Created: 2025/02/12 21:25:02 by willem #+# #+# */ -/* Updated: 2025/02/13 15:04:18 by whaffman ######## odam.nl */ +/* Updated: 2025/02/18 15:59:43 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" -void executor_execute_pipeline(t_minishell *minishell) +int executor_execute_pipeline(t_minishell *minishell) { t_list *current; t_command *command; + pid_t last_pid; + int exit_status; executor_create_pipes(minishell); current = minishell->commands; + last_pid = 0; while (current) { command = (t_command *)current->content; command->environment = minishell->environment; - executor_fork(command); + last_pid = executor_fork(command); current = current->next; } + waitpid(last_pid, &exit_status, 0); + return (((exit_status) & 0xff00) >> 8); } diff --git a/src/executor/executor_fork.c b/src/executor/executor_fork.c index af52654..bdc2c08 100644 --- a/src/executor/executor_fork.c +++ b/src/executor/executor_fork.c @@ -6,16 +6,16 @@ /* By: willem +#+ */ /* +#+ */ /* Created: 2025/02/12 21:24:52 by willem #+# #+# */ -/* Updated: 2025/02/13 15:03:19 by whaffman ######## odam.nl */ +/* Updated: 2025/02/18 15:41:56 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" -int executor_fork(t_command *command) +pid_t executor_fork(t_command *command) { pid_t pid; - int status; + // int status; pid = fork(); if (pid > 0) @@ -24,12 +24,12 @@ int executor_fork(t_command *command) close(command->fd_in); if (command->fd_out != 1) close(command->fd_out); - waitpid(pid, &status, 0); - return (((status) & 0xff00) >> 8); + // waitpid(pid, &status, 0); + // return (((status) & 0xff00) >> 8); } else if (pid == 0) executor_child(command); else perror("fork"); - return (-1); + return (pid); } diff --git a/src/utils/simple_builtins.c b/src/utils/simple_builtins.c index d197f8e..922f38a 100644 --- a/src/utils/simple_builtins.c +++ b/src/utils/simple_builtins.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/05 16:21:39 by whaffman #+# #+# */ -/* Updated: 2025/02/12 20:25:23 by willem ######## odam.nl */ +/* Updated: 2025/02/18 15:49:36 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -95,7 +95,10 @@ void simple_builtins(t_minishell *minishell) else if (cmp_value(minishell->tokens, "export")) builtin_export(minishell); else if (cmp_value(minishell->tokens, "unset")) - environment_del(&(minishell->environment), ((t_token *)minishell->tokens->next->content)->value); + { + environment_del(&(minishell->environment), + ((t_token *)minishell->tokens->next->content)->value); + } else { executor_execute_pipeline(minishell);