diff --git a/src/executing/group_cmd/group_cmd_execute.c b/src/executing/group_cmd/group_cmd_execute.c index 9b2a69f..7c537fe 100644 --- a/src/executing/group_cmd/group_cmd_execute.c +++ b/src/executing/group_cmd/group_cmd_execute.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/04 19:50:42 by kcolin #+# #+# */ -/* Updated: 2025/04/29 15:11:00 by kcolin ### ########.fr */ +/* Updated: 2025/04/30 14:06:24 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ #include "../simple_cmd/handle_redirections.h" #include "../simple_cmd/std_fds.h" #include +#include t_subprocess group_cmd_execute(t_group_cmd *cmd, t_minishell *app) { @@ -30,6 +31,12 @@ t_subprocess group_cmd_execute(t_group_cmd *cmd, t_minishell *app) restore_std_fds(&fds); return (SUBPROCESS); } + if (pid < 0) + { + perror("minishell: fork"); + app->last_return_value = 255; + return (PARENTPROCESS); + } do_waitpid(app, pid); return (PARENTPROCESS); } diff --git a/src/executing/simple_cmd/simple_cmd_execute.c b/src/executing/simple_cmd/simple_cmd_execute.c index 2118220..5e1f4a3 100644 --- a/src/executing/simple_cmd/simple_cmd_execute.c +++ b/src/executing/simple_cmd/simple_cmd_execute.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/27 16:21:56 by kcolin #+# #+# */ -/* Updated: 2025/04/29 15:47:27 by kcolin ### ########.fr */ +/* Updated: 2025/04/30 14:05:26 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,6 +72,13 @@ static t_simple_cmd *post_process_command(t_simple_cmd *cmd, t_minishell *app) return (cmd); } +static t_subprocess fork_fail(t_minishell *app) +{ + perror("minishell: fork"); + app->last_return_value = 255; + return (PARENTPROCESS); +} + static t_subprocess exec_external_cmd(t_simple_cmd *cmd, t_minishell *app, t_std_fds *fds) { @@ -87,6 +94,8 @@ static t_subprocess exec_external_cmd(t_simple_cmd *cmd, t_minishell *app, if (pid == 0) return (execute_subprocess(exe, cmd, app, fds)); free(exe); + if (pid < 0) + return (fork_fail(app)); do_waitpid(app, pid); } restore_std_fds(fds);