diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-05-11 18:24:10 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-05-11 18:24:10 +0200 |
commit | c5bcbb21b970081c15fb8295ae0e97cfa46f02be (patch) | |
tree | 40810424e208a589b64d6d106981b5d10b06d63a | |
parent | Nigga what (diff) | |
download | 42-minishell-c5bcbb21b970081c15fb8295ae0e97cfa46f02be.tar.gz 42-minishell-c5bcbb21b970081c15fb8295ae0e97cfa46f02be.tar.bz2 42-minishell-c5bcbb21b970081c15fb8295ae0e97cfa46f02be.tar.xz 42-minishell-c5bcbb21b970081c15fb8295ae0e97cfa46f02be.tar.zst 42-minishell-c5bcbb21b970081c15fb8295ae0e97cfa46f02be.zip |
Segv but it's ok
-rw-r--r-- | src/ft_e_externs_pipes.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/ft_e_externs_pipes.c b/src/ft_e_externs_pipes.c index 3d21832..521eb90 100644 --- a/src/ft_e_externs_pipes.c +++ b/src/ft_e_externs_pipes.c @@ -46,9 +46,8 @@ static void pipe(pipefd); if ((pid = fork()) == 0) { - dup2(pipefd[FT_WRITE_END], STDOUT_FILENO); close(pipefd[FT_READ_END]); - close(pipefd[FT_WRITE_END]); + dup2(pipefd[FT_WRITE_END], STDOUT_FILENO); ft_e_extern_child(fullpath[0], ptr->one, msh); } else if (pid < 0) @@ -59,9 +58,8 @@ static void { if ((pid = fork()) == 0) { - dup2(pipefd[FT_READ_END], STDIN_FILENO); close(pipefd[FT_WRITE_END]); - close(pipefd[FT_READ_END]); + dup2(pipefd[FT_READ_END], STDIN_FILENO); ft_e_extern_child(fullpath[1], ptr->next->one, msh); } else if (pid < 0) @@ -83,32 +81,38 @@ void ft_e_externs_pipes(struct s_lpipes *ptr, t_msh *msh) { - struct s_lpipes *p_ptr; + struct s_lpipes *head; + struct s_lpipes *rptr; char **envpath; char **fullpath; size_t i; - p_ptr = ptr; + head = ptr; + rptr = ptr; if (!(fullpath = (char**)malloc(3 * sizeof(char*)))) return ; fullpath[2] = NULL; i = 0; - while (i < 2) + while (rptr != NULL) { - if (ft_ischarset("/.", p_ptr->one->com[0])) - { - if (!(fullpath[i] = ft_strdup(p_ptr->one->com))) - return ; - } - else if ((envpath = ft_get_env_path(msh)) != NULL) + while (i < 2) { - fullpath[i] = ft_search_in_path(p_ptr->one->com, envpath, msh); - ft_delwords(envpath); + if (ft_ischarset("/.", ptr->one->com[0])) + { + if (!(fullpath[i] = ft_strdup(ptr->one->com))) + return ; + } + else if ((envpath = ft_get_env_path(msh)) != NULL) + { + fullpath[i] = ft_search_in_path(ptr->one->com, envpath, msh); + ft_delwords(envpath); + } + /* TODO: deal if not found etc */ + ptr = ptr->next; + i++; } - /* TODO: deal if not found etc */ - p_ptr = p_ptr->next; - i++; + ft_exec_path((const char**)fullpath, rptr, msh); + rptr = rptr->next; } - ft_exec_path((const char**)fullpath, ptr, msh); ft_delwords(fullpath); } |