From 65c1eb9d842e56b1834ff8d95c9d9b5c2dc2b393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Mon, 28 Apr 2025 15:04:47 +0200 Subject: [PATCH] fix(connec_cmd): handle nested connections correctly --- src/executing/connec_cmd/connec_cmd_execute.c | 18 ++++++++---------- .../connec_cmd/connec_pipe_cmd_execute.c | 9 ++------- .../connec_cmd/connec_pipe_cmd_execute.h | 5 ++--- test.sh | 8 ++++++++ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/executing/connec_cmd/connec_cmd_execute.c b/src/executing/connec_cmd/connec_cmd_execute.c index 03a7be9..6c5b6be 100644 --- a/src/executing/connec_cmd/connec_cmd_execute.c +++ b/src/executing/connec_cmd/connec_cmd_execute.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/07 10:38:55 by khais #+# #+# */ -/* Updated: 2025/04/25 17:58:15 by khais ### ########.fr */ +/* Updated: 2025/04/28 15:04:45 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,19 +16,15 @@ #include #include -static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app, - bool should_exit) +static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app) { - (void)should_exit; cmd_execute(cmd->first, app, false); if (app->last_return_value == 0) cmd_execute(cmd->second, app, false); } -static void connec_or_cmd_execute(t_connec_cmd *cmd, t_minishell *app, - bool should_exit) +static void connec_or_cmd_execute(t_connec_cmd *cmd, t_minishell *app) { - (void)should_exit; cmd_execute(cmd->first, app, false); if (app->last_return_value != 0) cmd_execute(cmd->second, app, false); @@ -40,9 +36,11 @@ void connec_cmd_execute(t_connec_cmd *cmd, t_minishell *app, if (cmd == NULL) return ; if (cmd->connector == FT_AND) - connec_and_cmd_execute(cmd, app, should_exit); + connec_and_cmd_execute(cmd, app); if (cmd->connector == FT_OR) - connec_or_cmd_execute(cmd, app, should_exit); + connec_or_cmd_execute(cmd, app); if (cmd->connector == FT_PIPE) - connec_pipe_cmd_execute(cmd, app, should_exit); + connec_pipe_cmd_execute(cmd, app); + if (should_exit) + exit(app->last_return_value); } diff --git a/src/executing/connec_cmd/connec_pipe_cmd_execute.c b/src/executing/connec_cmd/connec_pipe_cmd_execute.c index a288dec..c47bec6 100644 --- a/src/executing/connec_cmd/connec_pipe_cmd_execute.c +++ b/src/executing/connec_cmd/connec_pipe_cmd_execute.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/11 12:01:29 by khais #+# #+# */ -/* Updated: 2025/04/16 16:56:55 by khais ### ########.fr */ +/* Updated: 2025/04/28 15:04:17 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,8 +46,7 @@ static void close_and_wait(t_minishell *app, int pid1, int pid2, int pipefd[2]) do_waitpid(app, pid2); } -void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app, - bool should_exit) +void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app) { int pid1; int pid2; @@ -69,9 +68,5 @@ void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app, cmd_execute(cmd->second, app, true); } else - { close_and_wait(app, pid1, pid2, pipefd); - if (should_exit) - exit(app->last_return_value); - } } diff --git a/src/executing/connec_cmd/connec_pipe_cmd_execute.h b/src/executing/connec_cmd/connec_pipe_cmd_execute.h index 4a16839..7bababc 100644 --- a/src/executing/connec_cmd/connec_pipe_cmd_execute.h +++ b/src/executing/connec_cmd/connec_pipe_cmd_execute.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/11 11:56:45 by khais #+# #+# */ -/* Updated: 2025/04/16 16:56:43 by khais ### ########.fr */ +/* Updated: 2025/04/28 15:04:23 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,6 @@ # include "../../minishell.h" -void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app, - bool should_exit); +void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app); #endif // CONNEC_PIPE_CMD_EXECUTE_H diff --git a/test.sh b/test.sh index d888344..7add031 100755 --- a/test.sh +++ b/test.sh @@ -1441,4 +1441,12 @@ minishell: infile: No such file or directory 1 EOF +when_run <