From 27d38f50680b6a831de4671835d617ccf149f3d2 Mon Sep 17 00:00:00 2001 From: mdev9 Date: Fri, 19 Apr 2024 19:38:06 +0200 Subject: [PATCH] fixed exit | exit --- srcs/builtins.c | 4 +++- srcs/pipe.c | 36 +----------------------------------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/srcs/builtins.c b/srcs/builtins.c index d9e8d94..d392fb9 100755 --- a/srcs/builtins.c +++ b/srcs/builtins.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 20:48:48 by marde-vr ### ########.fr */ +/* Updated: 2024/04/19 19:36:51 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,8 @@ int cmd_is_builtin(t_msh *msh, char *cmd_token) { if (!cmd_token) return (0); + else if (msh->in_type == PIPE || msh->out_type == PIPE) + return (1); else if (!ft_strcmp(cmd_token, "cd")) { cd(msh->tokens); diff --git a/srcs/pipe.c b/srcs/pipe.c index f251f65..564e36d 100755 --- a/srcs/pipe.c +++ b/srcs/pipe.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 20:48:58 by marde-vr ### ########.fr */ +/* Updated: 2024/04/19 19:27:52 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,26 +17,14 @@ void close_pipe_fds(t_msh *msh, int i) if (i != 0) { if (msh->fds[i - 1][0] > 2) - { - //fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][0]); close(msh->fds[i - 1][0]); - } if (msh->fds[i - 1][1] > 2) - { - //fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][1]); close(msh->fds[i - 1][1]); - } } if (msh->fds[i][0] > 2) - { - //fprintf(stderr, "closing fd %d in child\n", msh->fds[i][0]); close(msh->fds[i][0]); - } if (msh->fds[i][1] > 2) - { - //fprintf(stderr, "closing fd %d in child\n", msh->fds[i][1]); close(msh->fds[i][1]); - } } void execute_command(t_msh *msh, char **cmd_args) @@ -54,10 +42,7 @@ void execute_command(t_msh *msh, char **cmd_args) set_echoctl(msh->echoctl); env = env_to_char_tab(msh->env); if (env) - { - //fprintf(stderr, "execveing %s\n", msh->tokens->value); execve(msh->tokens->value, cmd_args, env); - } ft_free_str_arr(env); } } @@ -71,7 +56,6 @@ void child(t_msh *msh, char **cmd_args, int i) if (msh->out_type == PIPE || msh->out_type == RED_O || msh->out_type == RED_O_APP) redirect_output(msh, i); - //fprintf(stderr, "closing fds\n"); close_pipe_fds(msh, i); execute_command(msh, cmd_args); close(0); @@ -88,37 +72,19 @@ void parent(t_msh *msh, int i, int cmd_count) if (i != 0) { if (msh->fds[i - 1][0] > 2) - { - //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][0]); close(msh->fds[i - 1][0]); - } if (msh->fds[i - 1][1] > 2) - { - //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][1]); close(msh->fds[i - 1][1]); - } } if (i == cmd_count - 1) { if (msh->fds[i][0] > 2) - { - //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][0]); close(msh->fds[i][0]); - } if (msh->fds[i][1] > 2) - { - //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][1]); close(msh->fds[i][1]); - } } if (msh->in_fd > 2) - { - //fprintf(stderr, "closing in_fd %d in parent\n", msh->in_fd); close(msh->in_fd); - } if (msh->out_fd > 2) - { - //fprintf(stderr, "closing in_fd %d in parent\n", msh->out_fd); close(msh->out_fd); - } }