close cmd fd after each exec

This commit is contained in:
lperrey
2021-12-20 18:10:53 +01:00
parent 0cfb13595c
commit e138e6550b
3 changed files with 22 additions and 16 deletions

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 23:53:17 by lperrey #+# #+# */
/* Updated: 2021/12/18 14:15:13 by lperrey ### ########.fr */
/* Updated: 2021/12/20 18:06:15 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -57,22 +57,27 @@ void close_pipeline_fd(t_cmd *pipeline[])
i = 0;
while (pipeline[i])
{
if (pipeline[i]->fd_in != STDIN_FILENO && pipeline[i]->fd_in > 0)
{
if (close(pipeline[i]->fd_in) == -1)
perror("close()");
pipeline[i]->fd_in = 0;
}
if (pipeline[i]->fd_out != STDOUT_FILENO && pipeline[i]->fd_out > 0)
{
if (close(pipeline[i]->fd_out) == -1)
perror("close()");
pipeline[i]->fd_out = 0;
}
close_cmd_fd(pipeline[i]);
i++;
}
}
void close_cmd_fd(t_cmd *cmd)
{
if (cmd->fd_in != STDIN_FILENO && cmd->fd_in > 0)
{
if (close(cmd->fd_in) == -1)
perror("close()");
cmd->fd_in = 0;
}
if (cmd->fd_out != STDOUT_FILENO && cmd->fd_out > 0)
{
if (close(cmd->fd_out) == -1)
perror("close()");
cmd->fd_out = 0;
}
}
void close_stdio(void)
{
if (close(STDIN_FILENO) == -1)