summaryrefslogtreecommitdiffstats
path: root/src/e_externs.c
diff options
context:
space:
mode:
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)