fix: all fds is now in childreen
This commit is contained in:
parent
d9ae113b94
commit
a7e75bb163
11
cmd/cmd.c
11
cmd/cmd.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/21 22:27:28 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/31 16:31:41 by alouis-j ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -31,3 +31,12 @@ void ft_cmddel(void *ptr)
|
||||
close(content->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);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/28 15:47:02 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/31 16:32:14 by alouis-j ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,5 +26,6 @@ typedef struct s_cmd
|
||||
} t_cmd;
|
||||
|
||||
void ft_cmddel(void *content);
|
||||
void ft_cmdcloser(void *ptr);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/28 15:50:23 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/28 15:50:24 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/31 16:33:24 by alouis-j ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,4 +17,5 @@
|
||||
# include "./cmd.h"
|
||||
# include "../libftx/libftx.h"
|
||||
# include "../data/data.h"
|
||||
# include "../utils/utils.h"
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/30 14:03:07 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/31 16:32:38 by alouis-j ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -41,7 +41,7 @@ static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
|
||||
return (return_code);
|
||||
}
|
||||
|
||||
static bool ft_executor(t_cmd *cmd, char **env, int fd)
|
||||
static bool ft_executor(t_data *data, t_cmd *cmd, char **env)
|
||||
{
|
||||
if (cmd->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;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/31 15:31:58 by alouis-j ### ########.fr */
|
||||
/* Updated: 2023/03/31 16:19:48 by alouis-j ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -73,12 +73,14 @@ int ft_heredoc(t_data *data, char *stop)
|
||||
break ;
|
||||
else if (return_code)
|
||||
{
|
||||
close(*ft_get_heredoc())
|
||||
*ft_get_heredoc() = -1;
|
||||
close(*ft_get_heredoc());
|
||||
return (-2);
|
||||
}
|
||||
}
|
||||
close(*ft_get_heredoc())
|
||||
close(fds[1]);
|
||||
close(*ft_get_heredoc());
|
||||
*ft_get_heredoc() = -1;
|
||||
*ft_get_heredoc() = -1;
|
||||
close(fds[1]);
|
||||
return (fds[0]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user