fix(fork): handle fork error in all places

This commit is contained in:
Khaïs COLIN 2025-04-30 14:06:38 +02:00
parent 4b08629bef
commit f8f3d8ccca
2 changed files with 18 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);