From 7c82cd4d8f2d78adca2db968edfec2381db108df Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 5 Oct 2020 15:43:33 +0200 Subject: pipes update --- src/e_pipes_next.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'src/e_pipes_next.c') diff --git a/src/e_pipes_next.c b/src/e_pipes_next.c index b3482c3..90e64f9 100644 --- a/src/e_pipes_next.c +++ b/src/e_pipes_next.c @@ -14,8 +14,11 @@ #include #include #include +#include #include "e_redirs.h" +#include "f_fail.h" +#include "s_com.h" #include "s_destroy.h" #include "s_line.h" #include "s_lpipes.h" @@ -23,29 +26,53 @@ #include "u_utils.h" #include "u_utils.h" +static void e_fullpath_not_found(t_com *ptr, t_msh *msh) +{ + f_command_not_found(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(127); +} + /* ** TODO: handle execve failed */ -void e_pipe_child(char *fullpath[], uint8_t pipe_id, t_com *ptr, t_msh *msh) +void e_pipe_child(char fullpath[], uint8_t fp_ret, t_com *ptr, t_msh *msh) { uint8_t bu_id; uint8_t ret; e_dup_redirs(ptr, msh); - if (ft_strncmp(fullpath[pipe_id], "builtin", 8) == 0) + if (ft_strncmp(fullpath, "builtin", 8) == 0) { bu_id = u_get_builtin_id(ptr->bin); ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); u_eof_fd(msh->fd); + s_com_destroy(&msh->com); s_lpipes_clear(&msh->pipes); s_line_clear(&msh->curr); s_destroy(msh); - ft_delwords(fullpath); exit(ret); } else - execve(fullpath[pipe_id], ptr->argv, msh->envp); + { + 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); + } + } } size_t e_get_pipes_count(struct s_lpipes *ptr) -- cgit v1.2.3