summaryrefslogtreecommitdiffstats
path: root/src/e_pipes_next.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-05 18:34:26 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-05 18:34:26 +0200
commitca0db4893e765081d91ff9b1aed285eb7aacb107 (patch)
tree34bbafb158929c1e632af3dfe70c4f256a3e0a05 /src/e_pipes_next.c
parentTODO (diff)
download42-minishell-ca0db4893e765081d91ff9b1aed285eb7aacb107.tar.gz
42-minishell-ca0db4893e765081d91ff9b1aed285eb7aacb107.tar.bz2
42-minishell-ca0db4893e765081d91ff9b1aed285eb7aacb107.tar.xz
42-minishell-ca0db4893e765081d91ff9b1aed285eb7aacb107.tar.zst
42-minishell-ca0db4893e765081d91ff9b1aed285eb7aacb107.zip
Fixed no shebang scripts
Diffstat (limited to '')
-rw-r--r--src/e_pipes_next.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/e_pipes_next.c b/src/e_pipes_next.c
index b39df15..291ba62 100644
--- a/src/e_pipes_next.c
+++ b/src/e_pipes_next.c
@@ -13,10 +13,12 @@
#include <libft.h>
#include <stdlib.h>
#include <stdint.h>
+#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "e_redirs.h"
+#include "e_unshebanged.h"
#include "f_fail.h"
#include "s_com.h"
#include "s_destroy.h"
@@ -37,15 +39,33 @@ static void e_fullpath_not_found(t_com *ptr, t_msh *msh)
exit(127);
}
-static void e_execve_failed(const char fullpath[], t_com *ptr, t_msh *msh)
+static void e_exec_child(const char fullpath[], t_com *ptr, t_msh *msh)
{
- f_exec(fullpath, ptr->bin);
- u_eof_fd(msh->fd);
- s_com_destroy(&msh->com);
- s_lpipes_clear(&msh->pipes);
- s_line_clear(&msh->curr);
- s_destroy(msh);
- exit(errno);
+ char buff[7];
+ int32_t 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, TRUE);
+ 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_lpipes_clear(&msh->pipes);
+ s_line_clear(&msh->curr);
+ s_destroy(msh);
+ exit(errno);
+ }
}
void e_pipe_child(char fullpath[], uint8_t fp_ret, t_com *ptr, t_msh *msh)
@@ -69,8 +89,7 @@ void e_pipe_child(char fullpath[], uint8_t fp_ret, t_com *ptr, t_msh *msh)
{
if (fp_ret == 2)
e_fullpath_not_found(ptr, msh);
- else if (execve(fullpath, ptr->argv, msh->envp) == -1)
- e_execve_failed(fullpath, ptr, msh);
+ e_exec_child(fullpath, ptr, msh);
}
}