From 0872d876f187a30b63062f77c17b8e78296b0557 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 18 Aug 2020 17:37:43 +0200 Subject: Handled execve fail --- src/e_externs.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/e_externs.c') diff --git a/src/e_externs.c b/src/e_externs.c index 5128bc8..ce0d41d 100644 --- a/src/e_externs.c +++ b/src/e_externs.c @@ -12,9 +12,11 @@ #include #include -#include #include +#include +#include #include +#include #include "b_export_next.h" #include "e_externs_next.h" @@ -30,8 +32,14 @@ static void t_msh *msh) { dup_redirs(ptr, msh); - execve(fullpath, ptr->argv, msh->envp); - /* TODO: handle execve failed */ + if (execve(fullpath, ptr->argv, msh->envp) == -1) + { + f_exec(fullpath); + ft_memdel((void*)&fullpath); + s_line_clear(&msh->curr); + s_destroy(msh); + exit(errno); + } } static void @@ -50,8 +58,8 @@ static void static void exec_path(const char fullpath[], - t_com *ptr, - t_msh *msh) + t_com *ptr, + t_msh *msh) { pid_t pid; int32_t status; @@ -83,7 +91,10 @@ void if (ft_ischarset("./", ptr->bin[0]) == TRUE) { - exec_path(ptr->bin, ptr, msh); + if ((fullpath = ft_strdup(ptr->bin)) == NULL) + return ; + exec_path(fullpath, ptr, msh); + ft_memdel((void*)&fullpath); return ; } else if ((envpath = get_env_path(msh)) != NULL) -- cgit v1.2.3