simple_cmd_builtin() done.
+ exec_cmd_line.c split in multiples files
This commit is contained in:
53
srcs/exec/subshell_wait.c
Normal file
53
srcs/exec/subshell_wait.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* subshell_wait.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/18 13:27:43 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int handle_wait_error(void);
|
||||
|
||||
void wait_subshell(pid_t last_cmd_pid, int *last_exit_status)
|
||||
{
|
||||
int wstatus;
|
||||
int ret;
|
||||
|
||||
wstatus = 0;
|
||||
if (last_cmd_pid > 0)
|
||||
{
|
||||
if (waitpid(last_cmd_pid, &wstatus, 0) == -1)
|
||||
perror("waitpid()");
|
||||
if (WIFEXITED(wstatus))
|
||||
*last_exit_status = WEXITSTATUS(wstatus);
|
||||
}
|
||||
ret = 0;
|
||||
while (ret != -1)
|
||||
{
|
||||
ret = wait(&wstatus);
|
||||
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)
|
||||
{
|
||||
if (errno == ECHILD)
|
||||
return (-1);
|
||||
else if (errno == EINTR)
|
||||
return (0);
|
||||
else
|
||||
perror("wait()");
|
||||
return (-1);
|
||||
}
|
||||
Reference in New Issue
Block a user