diff options
-rw-r--r-- | src/ft_e_externs_pipes.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/ft_e_externs_pipes.c b/src/ft_e_externs_pipes.c index 277abb4..c9268ac 100644 --- a/src/ft_e_externs_pipes.c +++ b/src/ft_e_externs_pipes.c @@ -15,6 +15,8 @@ #include <stdlib.h> #include <stdint.h> #include <unistd.h> +#include <string.h> +#include <errno.h> #include "ft_d_define.h" #include "ft_e_externs_next.h" @@ -70,15 +72,16 @@ static void i++; } i = 0; - while (i < pipes) + while (i <= pipes) { - pid = fork(); - if (pid == 0) + if ((pid = fork()) == 0) { if (i != 0) dup2(fd[i - 1][FT_WRITE_END], STDIN_FILENO); if (i != pipes) + { dup2(fd[i][FT_READ_END], STDOUT_FILENO); + } j = 0; while (j < pipes) { @@ -98,6 +101,9 @@ static void close(fd[i][FT_READ_END]); i++; } + /* while (wait(&status) != pid) */ + /* ; */ + /* msh->ret = WEXITSTATUS(status); */ waitpid(pid, &status, 0); msh->ret = WEXITSTATUS(status); } @@ -116,9 +122,9 @@ void head = ptr; rptr = ptr; pipes = ft_e_get_pipes_count(head); - if (!(fullpath = (char**)malloc((pipes + 1) * sizeof(char*)))) + if (!(fullpath = (char **)malloc((pipes + 2) * sizeof(char *)))) ft_fail_alloc(msh); - fullpath[pipes] = NULL; + fullpath[pipes + 1] = NULL; i = 0; while (rptr != NULL) { @@ -137,11 +143,6 @@ void rptr = rptr->next; } i = 0; - while (fullpath[i]) - { - ft_printf("[%s]\n", fullpath[i]); - i++; - } ft_exec_path((const char**)fullpath, head, msh); ft_delwords(fullpath); } |