diff options
Diffstat (limited to '')
-rw-r--r-- | src/e_externs.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/e_externs.c b/src/e_externs.c index e1b8b7c..a3d3594 100644 --- a/src/e_externs.c +++ b/src/e_externs.c @@ -30,7 +30,7 @@ #include "u_path.h" #include "u_utils.h" -static void e_extern_child(const char *fullpath, t_com *ptr, t_msh *msh) +static void e_extern_child(const char fullpath[], t_com *ptr, t_msh *msh) { if (execve(fullpath, ptr->argv, msh->envp) == -1) { @@ -55,11 +55,24 @@ static void e_export_env_fork(t_com *ptr, t_msh *msh) } } +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_line_clear(&msh->curr); + s_destroy(msh); + exit(127); +} + /* ** TODO: handle fork failed */ -static void e_exec_path(const char fullpath[], t_com *ptr, t_msh *msh) +static void e_exec_path(const char fullpath[], + t_com *ptr, + uint8_t fp_ret, + t_msh *msh) { pid_t pid; int32_t status; @@ -69,6 +82,8 @@ static void e_exec_path(const char fullpath[], t_com *ptr, t_msh *msh) if (ptr->env_fork != NULL) e_export_env_fork(ptr, msh); e_dup_redirs(ptr, msh); + if (fp_ret == 2) + e_fullpath_not_found(ptr, msh); e_extern_child(fullpath, ptr, msh); } else if (pid < 0) @@ -85,17 +100,18 @@ static void e_exec_path(const char fullpath[], t_com *ptr, t_msh *msh) void e_extern(t_com *ptr, t_msh *msh) { char fullpath[PATH_MAX]; + uint8_t fp_ret; fullpath[0] = C_NUL; if (ft_ischarset("./", ptr->bin[0]) == TRUE) { ft_strlcpy(fullpath, ptr->bin, PATH_MAX); - e_exec_path(fullpath, ptr, msh); + e_exec_path(fullpath, ptr, 0, msh); return ; } else { - u_search_in_path(fullpath, ptr->bin, PATH_MAX, msh); - e_exec_path(fullpath, ptr, msh); + fp_ret = u_search_in_path(fullpath, ptr->bin, PATH_MAX, msh); + e_exec_path(fullpath, ptr, fp_ret, msh); } } |