From: Lukas Jiriste Date: Thu, 5 Sep 2024 07:27:09 +0000 (+0200) Subject: Fix not closing pipes on a failed command X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=ce36110085e30f746fe9f66247ab7e6d751edfc1;p=42%2Fminishell.git Fix not closing pipes on a failed command The symptom of this is no output after execution of command of he form "nonexistent_cmd | rest of pipeline". The nonexistent command produces error, which prevents forgetting the pipe fds. This makes it so (at least) two fds are not forgotten which interferes later on. --- diff --git a/inc/execution.h b/inc/execution.h index d76503a..2bfb016 100644 --- a/inc/execution.h +++ b/inc/execution.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/02 17:40:19 by ljiriste #+# #+# */ -/* Updated: 2024/09/01 14:43:27 by ljiriste ### ########.fr */ +/* Updated: 2024/09/05 09:25:52 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,7 @@ int ex_fields(char **fields, t_vec *assignments, const t_vec *redirections, t_execution_env *env); int ex_command(t_parse_tree_node *command, t_execution_env *env); int ex_pipeline(t_parse_tree_node *pipeline, - t_execution_env *env, int depth); + t_execution_env *env, size_t depth); int ex_program(t_parse_tree_node *program, t_execution_env *env); char *get_word(const t_parse_tree_node *parent); diff --git a/src/exe_pipeline.c b/src/exe_pipeline.c index bf8e0bb..dae951d 100644 --- a/src/exe_pipeline.c +++ b/src/exe_pipeline.c @@ -6,7 +6,7 @@ /* By: lnikolov children, 0), env, depth + 1); ft_swap_int(&pipe_fds[1], &env->stdout_fd); close(pipe_fds[1]); - if (res == 0) - { + if (env->fds_to_close.size == 2 * depth + 2) ft_vec_forget(&env->fds_to_close, env->fds_to_close.size - 1); + if (env->fds_to_close.size == 2 * depth + 1) ft_vec_forget(&env->fds_to_close, env->fds_to_close.size - 1); - } ft_swap_int(&pipe_fds[0], &env->stdin_fd); res = res || ex_command(ft_vec_access(&pipeline->children, 2), env); ft_swap_int(&pipe_fds[0], &env->stdin_fd); @@ -110,7 +109,7 @@ static int advance_pipeline(t_parse_tree_node *pipeline, return (res); } -int ex_pipeline(t_parse_tree_node *pipeline, t_execution_env *env, int depth) +int ex_pipeline(t_parse_tree_node *pipeline, t_execution_env *env, size_t depth) { if (g_last_signal != 0) return (0);