diff --git a/cmd/cmd.c b/cmd/cmd.c index 0824964..461842a 100644 --- a/cmd/cmd.c +++ b/cmd/cmd.c @@ -6,7 +6,7 @@ /* By: cchauvet fd_out[1]); free(content); } + +void ft_cmdcloser(void *ptr) +{ + t_cmd *cmd; + + cmd = ptr; + ft_closer(cmd->fd_in); + ft_closer(cmd->fd_out); +} diff --git a/cmd/cmd.h b/cmd/cmd.h index 346980d..6bfd97c 100644 --- a/cmd/cmd.h +++ b/cmd/cmd.h @@ -6,7 +6,7 @@ /* By: cchauvet fd_in[0] == -1 || cmd->fd_out[0] == -1 || cmd->executable == NULL) return (0); @@ -53,17 +53,14 @@ static bool ft_executor(t_cmd *cmd, char **env, int fd) { dup2(cmd->fd_in[0], 0); dup2(cmd->fd_out[0], 1); - if (fd != -1) - close(fd); - ft_closer(cmd->fd_in); - ft_closer(cmd->fd_out); + ft_lstiter(*data->cmds, ft_cmdcloser); execve(cmd->executable, cmd->args, env); return (1); } return (0); } -static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd) +static int ft_cmd_executor(t_data *data, t_cmd *cmd) { int exit_code; char **env; @@ -81,7 +78,7 @@ static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd) env = env_to_strs(data->env); if (env == NULL) return (1); - exit_code = ft_executor(cmd, env, fd); + exit_code = ft_executor(data, cmd, env); ft_closer(cmd->fd_in); ft_closer(cmd->fd_out); ft_freer_tab_ultimate(1, env); @@ -111,7 +108,7 @@ int ft_cmds_executor(t_data *data) } if (content->fd_in[0] == -2 || content->fd_out[0] == -2) ft_mega_closer(content->fd_in, content->fd_out); - else if (ft_cmd_executor(data, content, fds[0])) + else if (ft_cmd_executor(data, content)) return (1); current = current->next; } diff --git a/redirection/heredoc.c b/redirection/heredoc.c index f6c83ca..ab1fdc8 100644 --- a/redirection/heredoc.c +++ b/redirection/heredoc.c @@ -6,7 +6,7 @@ /* By: cchauvet