From 7c65dcd8978f778b54cc4e2640151c261b03e6ae Mon Sep 17 00:00:00 2001 From: LuckyLaszlo Date: Thu, 18 Nov 2021 14:38:23 +0100 Subject: [PATCH] fixed signal exit status only for last command --- srcs/exec/subshell_wait.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/srcs/exec/subshell_wait.c b/srcs/exec/subshell_wait.c index fdf16b0..359d720 100644 --- a/srcs/exec/subshell_wait.c +++ b/srcs/exec/subshell_wait.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */ -/* Updated: 2021/11/18 13:27:43 by lperrey ### ########.fr */ +/* Updated: 2021/11/18 14:29:31 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,11 @@ void wait_subshell(pid_t last_cmd_pid, int *last_exit_status) perror("waitpid()"); if (WIFEXITED(wstatus)) *last_exit_status = WEXITSTATUS(wstatus); + if (WIFSIGNALED(wstatus)) + { + write(STDIN_FILENO, "\n", 1); + *last_exit_status = 128 + WTERMSIG(wstatus); + } } ret = 0; while (ret != -1) @@ -34,11 +39,6 @@ void wait_subshell(pid_t last_cmd_pid, int *last_exit_status) if (ret == -1) ret = handle_wait_error(); } - if (WIFSIGNALED(wstatus)) - { - write(STDIN_FILENO, "\n", 1); - *last_exit_status = 128 + WTERMSIG(wstatus); - } } static int handle_wait_error(void)