c'est encore cassé mais un peut moins
This commit is contained in:
45
srcs/pipe.c
45
srcs/pipe.c
@ -6,25 +6,24 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/07 18:49:09 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/13 13:21:52 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void close_pipe_fds(t_msh *msh, int i)
|
||||
void close_pipe_fds(t_msh *msh)
|
||||
{
|
||||
if (i != 0)
|
||||
if (msh->in_fd > 2)
|
||||
{
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
if (msh->out_fd > 2)
|
||||
close(msh->out_fd);
|
||||
}
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->out_fd);
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
printf("close in");
|
||||
}
|
||||
if (msh->out_fd > 2)
|
||||
{
|
||||
close(msh->out_fd);
|
||||
printf("close out");
|
||||
}
|
||||
//double close
|
||||
}
|
||||
|
||||
@ -57,7 +56,7 @@ void child(t_msh *msh, char **cmd_args, int i)
|
||||
if (msh->out_type == PIPE || msh->out_type == RED_O
|
||||
|| msh->out_type == RED_O_APP)
|
||||
redirect_output(msh);
|
||||
close_pipe_fds(msh, i);
|
||||
close_pipe_fds(msh);
|
||||
execute_command(msh, cmd_args);
|
||||
close(0);
|
||||
close(1);
|
||||
@ -70,22 +69,26 @@ void parent(t_msh *msh, int i, int cmd_count)
|
||||
{
|
||||
//signal(SIGINT, signal_handler_command);
|
||||
signal(SIGQUIT, signal_handler_command);
|
||||
(void)msh;
|
||||
(void) i;
|
||||
(void) cmd_count;
|
||||
printf("i : %d\n", i);
|
||||
if (i != 0)
|
||||
{
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
if (msh->out_fd > 2)
|
||||
close(msh->out_fd);
|
||||
if (msh->fds[i - 1][0] > 2)
|
||||
close(msh->fds[i - 1][0]);
|
||||
if (msh->fds[i - 1][1] > 2)
|
||||
close(msh->fds[i - 1][1]);
|
||||
}
|
||||
if (i == cmd_count - 1)
|
||||
{
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
if (msh->out_fd > 2)
|
||||
close(msh->out_fd);
|
||||
if (msh->fds[i][0] > 2)
|
||||
close(msh->fds[i][0]);
|
||||
if (msh->fds[i][1] > 2)
|
||||
close(msh->fds[i][1]);
|
||||
}
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
if (msh->out_fd > 2)
|
||||
close(msh->out_fd);
|
||||
close(msh->out_fd);
|
||||
}
|
||||
|
Reference in New Issue
Block a user