fixed signal exit status only for last command

This commit is contained in:
LuckyLaszlo
2021-11-18 14:38:23 +01:00
parent 0bd9dcb3bb
commit 7c65dcd897

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 01:57:38 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()"); perror("waitpid()");
if (WIFEXITED(wstatus)) if (WIFEXITED(wstatus))
*last_exit_status = WEXITSTATUS(wstatus); *last_exit_status = WEXITSTATUS(wstatus);
if (WIFSIGNALED(wstatus))
{
write(STDIN_FILENO, "\n", 1);
*last_exit_status = 128 + WTERMSIG(wstatus);
}
} }
ret = 0; ret = 0;
while (ret != -1) while (ret != -1)
@@ -34,11 +39,6 @@ void wait_subshell(pid_t last_cmd_pid, int *last_exit_status)
if (ret == -1) if (ret == -1)
ret = handle_wait_error(); ret = handle_wait_error();
} }
if (WIFSIGNALED(wstatus))
{
write(STDIN_FILENO, "\n", 1);
*last_exit_status = 128 + WTERMSIG(wstatus);
}
} }
static int handle_wait_error(void) static int handle_wait_error(void)