From d0b46a072c6f3227d3fc6f9d2ef7f7d96263c3f4 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 25 Nov 2020 16:59:13 +0100 Subject: Very good fix --- src/e_externs.c | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/e_externs.c b/src/e_externs.c index b184728..68040ab 100644 --- a/src/e_externs.c +++ b/src/e_externs.c @@ -11,17 +11,18 @@ /* ************************************************************************** */ #include -#include -#include -#include + #include -#include +#include +#include #ifdef __linux__ # include #else # include #endif -#include +#include +#include +#include #include "b_export_next.h" #include "d_define.h" @@ -37,29 +38,19 @@ static void e_extern_child(const char fullpath[], t_com *ptr, t_msh *msh) { - char buff[7]; - int fd; - - if ((fd = open(fullpath, O_RDONLY)) != -1) - { - if (read(fd, buff, 7) != -1) - if (ft_strncmp(buff, "\177ELF\002\001\001", 7) != 0 - && ft_strncmp(buff, "#!", 2) != 0) - { - close(fd); - e_extern_read_script(fullpath, ptr, msh, FALSE); - return ; - } - close(fd); - } if (execve(fullpath, ptr->argv, msh->envp) == -1) { - f_exec(fullpath, ptr->bin); - u_eof_fd(msh->fd); - s_com_destroy(&msh->com); - s_line_clear(&msh->curr); - s_destroy(msh); - exit(errno); + if (errno != ENOEXEC) + { + f_exec(fullpath, ptr->bin); + u_eof_fd(msh->fd); + s_com_destroy(&msh->com); + s_line_clear(&msh->curr); + s_destroy(msh); + exit(errno); + return ; + } + e_extern_read_script(fullpath, ptr, msh, FALSE); } } @@ -123,8 +114,7 @@ void e_extern(t_com *ptr, t_msh *msh) unsigned char fp_ret; fullpath[0] = C_NUL; - if (ptr->bin != NULL && (ft_ischarset("./", ptr->bin[0]) == TRUE - || ft_strchr(ptr->bin, '/') != NULL)) + if (ptr->bin != NULL && ft_strchr(ptr->bin, '/') != NULL) { ft_strlcpy(fullpath, ptr->bin, PATH_MAX); e_exec_path(fullpath, ptr, 0, msh); -- cgit v1.2.3