summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoe <rbousset@42lyon.fr>2020-11-25 16:59:13 +0100
committerjoe <rbousset@42lyon.fr>2020-11-25 16:59:13 +0100
commitd0b46a072c6f3227d3fc6f9d2ef7f7d96263c3f4 (patch)
treed2f8535311eabc79070b0c828dbd49dff724dd26
parentCleaner (diff)
download42-minishell-d0b46a072c6f3227d3fc6f9d2ef7f7d96263c3f4.tar.gz
42-minishell-d0b46a072c6f3227d3fc6f9d2ef7f7d96263c3f4.tar.bz2
42-minishell-d0b46a072c6f3227d3fc6f9d2ef7f7d96263c3f4.tar.xz
42-minishell-d0b46a072c6f3227d3fc6f9d2ef7f7d96263c3f4.tar.zst
42-minishell-d0b46a072c6f3227d3fc6f9d2ef7f7d96263c3f4.zip
Very good fix
-rw-r--r--src/e_externs.c46
1 files 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 <sys/wait.h>
-#include <libft.h>
-#include <stdlib.h>
-#include <string.h>
+
#include <fcntl.h>
-#include <unistd.h>
+#include <errno.h>
+#include <libft.h>
#ifdef __linux__
# include <linux/limits.h>
#else
# include <limits.h>
#endif
-#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#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);