From 2acbbf9cf6e60822a973bbd28ea6acbbbe47a1a7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 5 Oct 2020 15:45:37 +0200 Subject: Update --- src/e_pipes_next.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/e_pipes_next.c b/src/e_pipes_next.c index 90e64f9..b39df15 100644 --- a/src/e_pipes_next.c +++ b/src/e_pipes_next.c @@ -37,9 +37,16 @@ static void e_fullpath_not_found(t_com *ptr, t_msh *msh) exit(127); } -/* -** TODO: handle execve failed -*/ +static void e_execve_failed(const char fullpath[], t_com *ptr, t_msh *msh) +{ + f_exec(fullpath, ptr->bin); + u_eof_fd(msh->fd); + s_com_destroy(&msh->com); + s_lpipes_clear(&msh->pipes); + s_line_clear(&msh->curr); + s_destroy(msh); + exit(errno); +} void e_pipe_child(char fullpath[], uint8_t fp_ret, t_com *ptr, t_msh *msh) { @@ -62,16 +69,8 @@ void e_pipe_child(char fullpath[], uint8_t fp_ret, t_com *ptr, t_msh *msh) { if (fp_ret == 2) e_fullpath_not_found(ptr, msh); - if (execve(fullpath, ptr->argv, msh->envp) == -1) - { - f_exec(fullpath, ptr->bin); - u_eof_fd(msh->fd); - s_com_destroy(&msh->com); - s_lpipes_clear(&msh->pipes); - s_line_clear(&msh->curr); - s_destroy(msh); - exit(errno); - } + else if (execve(fullpath, ptr->argv, msh->envp) == -1) + e_execve_failed(fullpath, ptr, msh); } } -- cgit v1.2.3