From fe58fe4057aef6f0c3a5e2dcd8306b1ab05a049e Mon Sep 17 00:00:00 2001 From: narnaud Date: Thu, 12 May 2022 08:49:15 +0200 Subject: [PATCH] fix: lastcmd pipe, subshell return code --- caller.c | 12 ++++++------ minishell.h | 2 +- utils.c | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/caller.c b/caller.c index 8bbf1cc..627e35e 100755 --- a/caller.c +++ b/caller.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */ -/* Updated: 2022/05/11 15:29:42 by narnaud@stude ### ########.fr */ +/* Updated: 2022/05/12 08:43:04 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,7 @@ int piper(t_datas *datas, t_command *cmd) pipe(pip); if (!cmd->fd[1]) cmd->fd[1] = pip[1]; - if (!cmd->fd[0]) + if (!cmd->next->fd[0]) cmd->next->fd[0] = pip[0]; } pid = caller(datas, cmd); @@ -82,11 +82,11 @@ int piper(t_datas *datas, t_command *cmd) if (DEBUG) printf("%s -ope: %d, pid: %d, fdin: %d, fdout: %d\n", cmd->argv[0], cmd->ope, pid, cmd->fd[0], cmd->fd[1]); if (cmd->ope == PIPE) - pid = piper(datas, cmd->next); - else + pid = piper(datas, cmd->next); + waitpid(pid, &status, 0); + datas->exit_code = handle_status(datas, status); + if (cmd->ope != PIPE) { - waitpid(pid, &status, 0); - datas->exit_code = handle_status(datas, status); while (cmd->next && check_skip(datas, cmd)) cmd = cmd->next; if (cmd->next) diff --git a/minishell.h b/minishell.h index de7d606..f4a551d 100755 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */ -/* Updated: 2022/05/11 15:19:11 by narnaud@stude ### ########.fr */ +/* Updated: 2022/05/12 08:43:53 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/utils.c b/utils.c index f074867..ca73d4b 100755 --- a/utils.c +++ b/utils.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/03 08:57:53 by narnaud #+# #+# */ -/* Updated: 2022/05/11 00:22:13 by narnaud@stude ### ########.fr */ +/* Updated: 2022/05/12 08:45:47 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,5 +66,7 @@ void halt(t_datas *datas, int ret_code, int silent) clear_history(); if (!silent) printf("exit\n"); + if (silent) + exit(datas->exit_code); exit(ret_code); }