From 8c02b32601fbc70aa28023f9b9534a55ec1801bf Mon Sep 17 00:00:00 2001 From: whaffman Date: Fri, 21 Feb 2025 13:17:22 +0100 Subject: [PATCH] dont throw away of_fd before testing the new one --- inc/executor.h | 4 ++-- src/executor/executor_count_fds.c | 8 +++----- src/executor/executor_create_redirects.c | 10 +++++----- src/executor/executor_execute_pipeline.c | 2 +- src/executor/executor_open_fds.c | 8 ++++---- src/parser/parser_new_command.c | 18 +++++++++++------- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/inc/executor.h b/inc/executor.h index 7fdb68e..82ec74f 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/21 13:01:39 by whaffman ######## odam.nl */ +/* Updated: 2025/02/21 13:16:29 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ void executor_create_pipes(t_minishell *minishell); int executor_execute_pipeline(t_minishell *minishell); void executor_close_fds(int n_fds); int executor_count_fds(t_minishell *minishell); -int executor_open_fds(t_list *redirect_list); +int executor_open_fds(t_list *redirect_list, int og_fd); void executor_create_redirects(t_minishell *minishell); #endif // EXECUTOR_H diff --git a/src/executor/executor_count_fds.c b/src/executor/executor_count_fds.c index b1c1dea..f478882 100644 --- a/src/executor/executor_count_fds.c +++ b/src/executor/executor_count_fds.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/21 12:42:26 by whaffman #+# #+# */ -/* Updated: 2025/02/21 12:46:00 by whaffman ######## odam.nl */ +/* Updated: 2025/02/21 13:05:55 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -14,12 +14,10 @@ int executor_count_fds(t_minishell *minishell) { - int fd; - int count; - t_list *current; + int count; + t_list *current; t_command *command; - current = minishell->commands; count = (ft_lstsize(current) - 1) * 2; while (current) diff --git a/src/executor/executor_create_redirects.c b/src/executor/executor_create_redirects.c index e9c4caa..86388e1 100644 --- a/src/executor/executor_create_redirects.c +++ b/src/executor/executor_create_redirects.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/21 13:00:00 by whaffman #+# #+# */ -/* Updated: 2025/02/21 13:00:11 by whaffman ######## odam.nl */ +/* Updated: 2025/02/21 13:16:03 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -15,14 +15,14 @@ void executor_create_redirects(t_minishell *minishell) { t_list *current; - t_command *command; + t_command *cmd; current = minishell->commands; while (current) { - command = (t_command *)current->content; - command->fd_in = executor_open_fds(command->redirect_in); - command->fd_out = executor_open_fds(command->redirect_out); + cmd = (t_command *)current->content; + cmd->fd_in = executor_open_fds(cmd->redirect_in, cmd->fd_in); + cmd->fd_out = executor_open_fds(cmd->redirect_out, cmd->fd_out); current = current->next; } } diff --git a/src/executor/executor_execute_pipeline.c b/src/executor/executor_execute_pipeline.c index 3182355..9c6d49f 100644 --- a/src/executor/executor_execute_pipeline.c +++ b/src/executor/executor_execute_pipeline.c @@ -6,7 +6,7 @@ /* By: willem +#+ */ /* +#+ */ /* Created: 2025/02/12 21:25:02 by willem #+# #+# */ -/* Updated: 2025/02/21 12:49:21 by whaffman ######## odam.nl */ +/* Updated: 2025/02/21 13:11:17 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/executor/executor_open_fds.c b/src/executor/executor_open_fds.c index 9c104ca..4dc2b5e 100644 --- a/src/executor/executor_open_fds.c +++ b/src/executor/executor_open_fds.c @@ -6,18 +6,18 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/21 12:50:42 by whaffman #+# #+# */ -/* Updated: 2025/02/21 12:59:41 by whaffman ######## odam.nl */ +/* Updated: 2025/02/21 13:15:04 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" -int executor_open_fds(t_list *redirect_list) +int executor_open_fds(t_list *redirect_list, int og_fd) { t_redirect *redirect; int fd; - fd = 0; + fd = og_fd; while (redirect_list) { redirect = (t_redirect *)redirect_list->content; @@ -30,7 +30,7 @@ int executor_open_fds(t_list *redirect_list) if (fd < 0) { error_msg("executor_open_fds", "can't open file"); - return (fd); + return (og_fd); } redirect_list = redirect_list->next; } diff --git a/src/parser/parser_new_command.c b/src/parser/parser_new_command.c index d2780a7..5d4ff99 100644 --- a/src/parser/parser_new_command.c +++ b/src/parser/parser_new_command.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* parser_new_command.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */ -/* Updated: 2025/02/11 16:25:12 by qmennen ### ########.fr */ +/* :::::::: */ +/* parser_new_command.c :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */ +/* Updated: 2025/02/21 13:07:47 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -25,6 +25,10 @@ t_command *parser_command_new(char *cmd) command->args = NULL; command->fd_in = 0; command->fd_out = 1; + command->redirect_in = NULL; + command->redirect_out = NULL; + command->environment = NULL; + command->n_fds = 0; command->command = cmd; return (command); }