From e986d8692b19743b2f81111405adefc58d7ceaf4 Mon Sep 17 00:00:00 2001 From: tomoron Date: Tue, 7 May 2024 17:43:00 +0200 Subject: [PATCH] fix des trucs --- srcs/exec_bonus.c | 5 ++--- srcs/here_doc_utils.c | 12 +++++++++++- srcs/minishell.h | 5 +++-- srcs/path.c | 3 ++- srcs/utils.c | 4 ++-- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index d0cf393..6f11169 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/07 12:36:41 by tomoron ### ########.fr */ +/* Updated: 2024/05/07 17:26:49 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,10 +81,8 @@ void exec_command(t_msh *msh, int i, int cmd_count) if (!msh->fds[i]) ft_exit(msh, 1); if (msh->tokens && !cmd_is_builtin(msh, msh->tokens->value)) -// && msh->in_fd != -1) get_cmd_path(msh); if (((msh->tokens && msh->tokens->value) || is_parenthesis(msh->cmds))) -// && msh->in_fd != -1) exec(msh, get_cmd_args(msh), i, cmd_count); else { @@ -136,6 +134,7 @@ void exec_commands(t_msh *msh) { get_redirections(msh, msh->cmds); g_return_code = (msh->in_fd < 0 || msh->out_fd < 0); + remove_here_doc_file(msh); if (msh->in_fd > 2) close(msh->in_fd); if (msh->out_fd > 2) diff --git a/srcs/here_doc_utils.c b/srcs/here_doc_utils.c index c098368..a476d41 100755 --- a/srcs/here_doc_utils.c +++ b/srcs/here_doc_utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/26 09:06:51 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 20:48:54 by marde-vr ### ########.fr */ +/* Updated: 2024/05/07 17:26:43 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,3 +78,13 @@ void parse_var(t_msh *msh, char *line) line++; } } + +void remove_here_doc_file(t_msh *msh) +{ + if(msh->here_doc_filename) + { + unlink(msh->here_doc_filename); + free(msh->here_doc_filename); + msh->here_doc_filename = 0; + } +} diff --git a/srcs/minishell.h b/srcs/minishell.h index 1f82001..b3d3508 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/05/06 15:17:14 by tomoron ### ########.fr */ +/* Updated: 2024/05/07 17:34:59 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,8 +71,8 @@ typedef struct s_msh t_cmd_type in_type; t_cmd_type out_type; int in_fd; - int echoctl; int out_fd; + int echoctl; int last_return_code; int locked_return_code; char *here_doc_filename; @@ -130,6 +130,7 @@ char **split_paths_from_env(t_env *env); int add_return_code_to_str(char *res); void close_pipe_fds(t_msh *msh, int i); void parse_var(t_msh *msh, char *line); +void remove_here_doc_file(t_msh *msh); int get_var_name_len(char *command); void handle_minishellrc(t_msh *msh); char *get_tmp_file_name(t_msh *msh); diff --git a/srcs/path.c b/srcs/path.c index 791a279..e410695 100755 --- a/srcs/path.c +++ b/srcs/path.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */ -/* Updated: 2024/05/06 14:25:40 by tomoron ### ########.fr */ +/* Updated: 2024/05/07 16:08:17 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -99,6 +99,7 @@ void get_cmd_path(t_msh *msh) ft_printf_fd(2, "'': command not found\n"); else ft_printf_fd(2, "%s: command not found\n", msh->tokens->value); + close_all_pipes(msh); g_return_code = 127; } } diff --git a/srcs/utils.c b/srcs/utils.c index f8bff8c..7012f40 100755 --- a/srcs/utils.c +++ b/srcs/utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ -/* Updated: 2024/05/06 16:17:32 by tomoron ### ########.fr */ +/* Updated: 2024/05/07 17:07:16 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,7 +79,7 @@ void close_all_pipes(t_msh *msh) int i; i = 0; - while (msh->fds[i]) + while (msh->fds && msh->fds[i]) { close_pipe_fds(msh, i); i++;