Compare commits

...

2 Commits

Author SHA1 Message Date
Camille Chauvet
e2c43eb973 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-03-13 12:45:42 +01:00
Camille Chauvet
3d68490320 fix: execve failed 2023-03-13 12:45:29 +01:00

View File

@ -11,6 +11,7 @@
/* ************************************************************************** */
#include "execution_private.h"
#include <unistd.h>
static int ft_own_cmd(t_data *data, t_cmd *cmd)
{
@ -41,7 +42,7 @@ static int ft_own_cmd(t_data *data, t_cmd *cmd)
return (return_code);
}
static int ft_executor(t_cmd *cmd, char **env)
static bool ft_executor(t_cmd *cmd, char **env)
{
if (cmd->fd_in[0] == -1 || cmd->fd_out[0] == -1 || cmd->executable == NULL)
return (0);
@ -52,11 +53,15 @@ static int ft_executor(t_cmd *cmd, char **env)
{
dup2(cmd->fd_in[0], 0);
dup2(cmd->fd_out[0], 1);
if (cmd->fd_in[0] > 2)
close(cmd->fd_in[0]);
if (cmd->fd_out[0] > 2)
close(cmd->fd_out[0]);
if (cmd->fd_in[1] != -1)
dup2(cmd->fd_in[1], 0);
if (cmd->fd_out[1] != -1)
dup2(cmd->fd_out[1], 1);
ft_closer(cmd->fd_in);
ft_closer(cmd->fd_out);
execve(cmd->executable, cmd->args, env);
ft_eprintf("minishell: permission denied: %s\n", cmd->executable);
return (1);
}
return (0);
}
@ -78,9 +83,9 @@ static int ft_cmd_executor(t_data *data, t_cmd *cmd)
if (env == NULL)
return (1);
exit_code = ft_executor(cmd, env);
if (exit_code == -1)
return (1);
ft_freer_tab_ultimate(1, env);
if (exit_code == 1)
return (1);
}
if (ft_gen_exit_code(data))
return (1);