summaryrefslogtreecommitdiffstats
path: root/src/e_externs.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_externs.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 'src/e_externs.c')
-rw-r--r--src/e_externs.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/e_externs.c b/src/e_externs.c
index a3d3594..7b25516 100644
--- a/src/e_externs.c
+++ b/src/e_externs.c
@@ -15,6 +15,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
@@ -23,6 +24,7 @@
#include "d_define.h"
#include "f_fail.h"
#include "e_redirs.h"
+#include "e_unshebanged.h"
#include "s_com.h"
#include "s_destroy.h"
#include "s_line.h"
@@ -32,6 +34,21 @@
static void e_extern_child(const char fullpath[], t_com *ptr, t_msh *msh)
{
+ 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, FALSE);
+ return ;
+ }
+ close(fd);
+ }
if (execve(fullpath, ptr->argv, msh->envp) == -1)
{
f_exec(fullpath, ptr->bin);
@@ -103,7 +120,8 @@ void e_extern(t_com *ptr, t_msh *msh)
uint8_t fp_ret;
fullpath[0] = C_NUL;
- if (ft_ischarset("./", ptr->bin[0]) == TRUE)
+ if (ptr->bin != NULL && (ft_ischarset("./", ptr->bin[0]) == TRUE
+ || ft_strchr(ptr->bin, '/') != NULL))
{
ft_strlcpy(fullpath, ptr->bin, PATH_MAX);
e_exec_path(fullpath, ptr, 0, msh);