From d3e5d459cb32924bf7b696db2348099cda2fbf9f Mon Sep 17 00:00:00 2001 From: tomoron Date: Mon, 6 May 2024 10:28:30 +0200 Subject: [PATCH] fix fds ouverts --- srcs/exec_bonus.c | 9 ++++++++- srcs/exec_utils.c | 14 +++++++++----- srcs/output_redirections.c | 4 +++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index b765cfd..5f5f9ca 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/05/03 13:10:12 by marde-vr ### ########.fr */ +/* Updated: 2024/05/06 10:24:38 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,6 +84,13 @@ void exec_command(t_msh *msh, int i, int cmd_count) get_cmd_path(msh); if ((msh->tokens && msh->tokens->value) || is_parenthesis(msh->cmds)) exec(msh, get_cmd_args(msh), i, cmd_count); + else + { + if (msh->in_fd > 2) + close(msh->in_fd); + if (msh->out_fd > 2) + close(msh->out_fd); + } } remove_command_from_msh(msh); } diff --git a/srcs/exec_utils.c b/srcs/exec_utils.c index f859823..623b78d 100644 --- a/srcs/exec_utils.c +++ b/srcs/exec_utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 10:46:28 by marde-vr #+# #+# */ -/* Updated: 2024/04/30 14:41:48 by marde-vr ### ########.fr */ +/* Updated: 2024/05/06 10:13:22 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,18 +50,22 @@ int get_cmd_count(t_cmd *cmds) { int nb; - nb = 0; + nb = 1; while (cmds && !is_operand_type(cmds)) { - while (cmds && (is_output_type(cmds) || is_input_type(cmds))) + /*while (cmds && (is_output_type(cmds) || is_input_type(cmds))) cmds = cmds->next; - if (is_cmd_type(cmds)) + if (cmds && is_cmd_type(cmds)) nb++; while (cmds && (is_output_type(cmds) || is_input_type(cmds) || is_cmd_type(cmds))) cmds = cmds->next; + */ if (cmds && cmds->cmd_type == PIPE) - cmds = cmds->next; + { + nb++; + } + cmds = cmds->next; } return (nb); } diff --git a/srcs/output_redirections.c b/srcs/output_redirections.c index 2a23038..5d0b826 100755 --- a/srcs/output_redirections.c +++ b/srcs/output_redirections.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */ -/* Updated: 2024/05/03 14:07:43 by marde-vr ### ########.fr */ +/* Updated: 2024/05/06 09:58:11 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -87,6 +87,8 @@ int get_out_type(t_msh *msh, t_cmd *cur_cmd) int ret; msh->out_type = CMD; + if (msh->out_fd > 2) + close(msh->out_fd); msh->out_fd = 0; ret = 0; go_to_next_out_type(&cur_cmd);