-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/11/27 20:30:45 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/12 14:28:56 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/13 11:52:07 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -164,6 +164,7 @@ char *op_error_trimmed(t_list *curr); | |
bool overflows_llong(char *str); | ||
int pipe_error(void); | ||
void pipex(void); | ||
void pipex_handle_exit_ret(int children_pid, int exit_ret); | ||
bool plus_end_str(char *str); | ||
void print_cmds(void); | ||
void print_cmd_not_found(char *str); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: brenaudo <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/21 12:02:33 by brenaudo #+# #+# */ | ||
/* Updated: 2023/01/12 14:13:02 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/13 11:52:31 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,7 +17,8 @@ static void close_pipe_and_recreate(int *pipes, t_cmd *cmd); | |
|
||
static void pipex_loop_core(int *children_pid, t_list *curr, int *pipes) | ||
{ | ||
int built_in; | ||
int built_in; | ||
int ret; | ||
|
||
built_in = builtin(((t_cmd *)curr->content)->str); | ||
children_pid[((t_cmd *)curr->content)->cmd_idx] = fork(); | ||
|
@@ -31,6 +32,14 @@ static void pipex_loop_core(int *children_pid, t_list *curr, int *pipes) | |
} | ||
if (built_in == -1) | ||
change_sig_handling(((t_cmd *)curr->content)->str, pipes, children_pid); | ||
else | ||
{ | ||
waitpid(children_pid[((t_cmd *)curr->content)->cmd_idx], &ret, 0); | ||
if (ret >> 8 == 0) | ||
children_pid[((t_cmd *)curr->content)->cmd_idx] = -256; | ||
else | ||
children_pid[((t_cmd *)curr->content)->cmd_idx] = -1 * (ret >> 8); | ||
} | ||
g_glob->in_child = true; | ||
close_pipe_and_recreate(pipes, ((t_cmd *)curr->content)); | ||
} | ||
|
@@ -66,13 +75,9 @@ void pipex(void) | |
children_pid = pipex_loop(); | ||
while (children_pid[i] != 0) | ||
{ | ||
waitpid(children_pid[i], &exit_ret, 0); | ||
if (g_glob->sig_int) | ||
g_glob->exit_ret = 130; | ||
else if (g_glob->sig_quit) | ||
g_glob->exit_ret = 131; | ||
else | ||
g_glob->exit_ret = exit_ret >> 8; | ||
if (children_pid[i] > 0) | ||
waitpid(children_pid[i], &exit_ret, 0); | ||
pipex_handle_exit_ret(children_pid[i], exit_ret); | ||
i++; | ||
g_glob->sig_quit = false; | ||
g_glob->sig_int = false; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/09 13:24:09 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/10 10:59:53 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/13 11:51:51 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -26,3 +26,20 @@ void init_children_pid(int **children_pid, int size) | |
while (!*children_pid) | ||
*children_pid = ft_calloc(size, sizeof(int)); | ||
} | ||
|
||
void pipex_handle_exit_ret(int children_pid, int exit_ret) | ||
{ | ||
if (g_glob->sig_int) | ||
g_glob->exit_ret = 130; | ||
else if (g_glob->sig_quit) | ||
g_glob->exit_ret = 131; | ||
else | ||
{ | ||
if (children_pid < 0 && children_pid != -256) | ||
g_glob->exit_ret = children_pid * (-1); | ||
else if (children_pid < 0 && children_pid == -256) | ||
g_glob->exit_ret = 0; | ||
else if (children_pid > 0) | ||
g_glob->exit_ret = exit_ret >> 8; | ||
} | ||
} |