From 2fe6c1f9791b7bb3de02fde7ba31a6f0534edbc6 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 11 May 2020 17:08:01 +0200 Subject: Tryna pipe(2) --- src/ft_e_externs_pipes.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/ft_e_externs_pipes.c') diff --git a/src/ft_e_externs_pipes.c b/src/ft_e_externs_pipes.c index d4d648d..a54e565 100644 --- a/src/ft_e_externs_pipes.c +++ b/src/ft_e_externs_pipes.c @@ -53,22 +53,23 @@ static void { /* TODO: handle fork failed */ } - if ((pid = fork()) == 0) + else { - close(pipefd[1]); - dup2(pipefd[0], STDIN_FILENO); - ft_e_extern_child(fullpath[1], ptr->next->one, msh); - } - /* else */ - /* { */ - close(pipefd[0]); - close(pipefd[1]); - while (wait(&status) != pid) - ; - while (wait(&status) != pid) - ; + if ((pid = fork()) == 0) + { + close(pipefd[1]); + dup2(pipefd[0], STDIN_FILENO); + ft_e_extern_child(fullpath[1], ptr->next->one, msh); + } + else + { + close(pipefd[0]); + close(pipefd[1]); + waitpid(-1, &status, 0); + } + waitpid(-1, &status, 0); msh->ret = WEXITSTATUS(status); - /* } */ + } } void -- cgit v1.2.3