summaryrefslogtreecommitdiffstats
path: root/src/e_externs.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-18 17:37:43 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-18 17:37:43 +0200
commit0872d876f187a30b63062f77c17b8e78296b0557 (patch)
tree1a85d6c9629335592a6d1bb8a5dda5214cde27be /src/e_externs.c
parentUpdated TODO (diff)
download42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.tar.gz
42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.tar.bz2
42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.tar.xz
42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.tar.zst
42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.zip
Handled execve fail
Diffstat (limited to '')
-rw-r--r--src/e_externs.c23
1 files changed, 17 insertions, 6 deletions
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 <sys/wait.h>
#include <libft.h>
-#include <stdlib.h>
#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
+#include <errno.h>
#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)