From 93e157bb48e8139e3988b7e0d3deca80dafd51b1 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 27 Aug 2020 15:49:11 +0200 Subject: In progress --- src/e_externs_pipes.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/e_externs_pipes.c') diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c index 858e60f..320b31d 100644 --- a/src/e_externs_pipes.c +++ b/src/e_externs_pipes.c @@ -26,6 +26,7 @@ #include "s_line.h" #include "s_lpipes.h" #include "s_struct.h" +#include "u_utils.h" static uint8_t get_builtin_id(const char com[], @@ -55,8 +56,10 @@ static void { bu_id = get_builtin_id(ptr->bin, msh); ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); + u_eof_fd(msh->fd); s_line_clear(&msh->curr); s_destroy(msh); + ft_memdel((void*)&fullpath); exit(ret); } else @@ -82,13 +85,13 @@ static size_t static void exec_path(const char *fullpath[], - struct s_lpipes *head, - t_msh *msh) + struct s_lpipes *head, + t_msh *msh) { + int fd[256][2]; size_t pipes; size_t i; size_t j; - int fd[256][2]; int pid; int status; @@ -147,7 +150,7 @@ void head = ptr; rptr = ptr; pipes = e_get_pipes_count(head); - if (!(fullpath = (char **)malloc((pipes + 2) * sizeof(char *)))) + if ((fullpath = (char **)malloc((pipes + 2) * sizeof(char *))) == NULL) f_alloc_and_destroy_msh(msh); fullpath[pipes + 1] = NULL; i = 0; -- cgit v1.2.3 From 515c77bb410d6d2e10d8f11de3ee4986739757ee Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 27 Aug 2020 16:05:40 +0200 Subject: TODO update --- src/e_externs_pipes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/e_externs_pipes.c') diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c index 320b31d..6f24435 100644 --- a/src/e_externs_pipes.c +++ b/src/e_externs_pipes.c @@ -44,7 +44,7 @@ static uint8_t } static void - e_extern_child(const char *fullpath, + e_pipe_child(const char *fullpath, t_com *ptr, t_msh *msh) { @@ -119,7 +119,7 @@ static void close(fd[j][FT_READ_END]); j++; } - e_extern_child(fullpath[i], head->com, msh); + e_pipe_child(fullpath[i], head->com, msh); } head = head->next; i++; -- cgit v1.2.3 From abc749bfb38ce6c1cfb818bbc0da1cfbd0451bfe Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 27 Aug 2020 16:14:40 +0200 Subject: Freed pipe leaks on builtins --- src/e_externs_pipes.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/e_externs_pipes.c') diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c index 6f24435..f6243e5 100644 --- a/src/e_externs_pipes.c +++ b/src/e_externs_pipes.c @@ -44,26 +44,28 @@ static uint8_t } static void - e_pipe_child(const char *fullpath, - t_com *ptr, - t_msh *msh) + e_pipe_child(char *fullpath[], + uint8_t pipe_id, + t_com *ptr, + t_msh *msh) { uint8_t bu_id; uint8_t ret; dup_redirs(ptr, msh); - if (ft_strncmp(fullpath, "builtin", 8) == 0) + if (ft_strncmp(fullpath[pipe_id], "builtin", 8) == 0) { bu_id = get_builtin_id(ptr->bin, msh); ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); u_eof_fd(msh->fd); + s_lpipes_clear(&msh->curr->pipes); s_line_clear(&msh->curr); s_destroy(msh); - ft_memdel((void*)&fullpath); + ft_delwords(fullpath); exit(ret); } else - execve(fullpath, ptr->argv, msh->envp); + execve(fullpath[pipe_id], ptr->argv, msh->envp); /* TODO: handle execve failed */ } @@ -84,7 +86,7 @@ static size_t } static void - exec_path(const char *fullpath[], + e_pipe_exec_path(char *fullpath[], struct s_lpipes *head, t_msh *msh) { @@ -119,7 +121,7 @@ static void close(fd[j][FT_READ_END]); j++; } - e_pipe_child(fullpath[i], head->com, msh); + e_pipe_child(fullpath, i, head->com, msh); } head = head->next; i++; @@ -177,6 +179,6 @@ void rptr = rptr->next; } i = 0; - exec_path((const char**)fullpath, head, msh); + e_pipe_exec_path(fullpath, head, msh); ft_delwords(fullpath); } -- cgit v1.2.3 From d742075e1af0c063ef9677f157263c0d45253f73 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 19:32:40 +0200 Subject: Rework in progress --- src/e_externs_pipes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/e_externs_pipes.c') diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c index f6243e5..e6252e4 100644 --- a/src/e_externs_pipes.c +++ b/src/e_externs_pipes.c @@ -58,7 +58,7 @@ static void bu_id = get_builtin_id(ptr->bin, msh); ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); u_eof_fd(msh->fd); - s_lpipes_clear(&msh->curr->pipes); + s_lpipes_clear(&msh->pipes); s_line_clear(&msh->curr); s_destroy(msh); ft_delwords(fullpath); -- cgit v1.2.3 From ca2e36781039eb7e9901ccde395600e7af87ff4f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 15 Sep 2020 19:59:41 +0200 Subject: Huge fixes and stack stuff --- src/e_externs_pipes.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/e_externs_pipes.c') diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c index e6252e4..05a2cf7 100644 --- a/src/e_externs_pipes.c +++ b/src/e_externs_pipes.c @@ -16,16 +16,17 @@ #include #include #include +#include #include #include "d_define.h" -#include "e_externs_next.h" #include "f_fail.h" #include "m_redirs.h" #include "s_destroy.h" #include "s_line.h" #include "s_lpipes.h" #include "s_struct.h" +#include "u_path.h" #include "u_utils.h" static uint8_t @@ -143,8 +144,8 @@ void { struct s_lpipes *head; struct s_lpipes *rptr; - char **envpath; char **fullpath; + char tmp[PATH_MAX]; size_t i; size_t pipes; uint8_t bu_id; @@ -163,7 +164,7 @@ void if ((fullpath[i] = ft_strdup(rptr->com->bin)) == NULL) f_alloc_and_destroy_msh(msh); } - else if ((envpath = get_env_path(msh)) != NULL) + else { if ((bu_id = get_builtin_id(rptr->com->bin, msh)) < FT_BUILTINS_COUNT) @@ -172,8 +173,10 @@ void f_alloc_and_destroy_msh(msh); } else - fullpath[i] = search_in_path(rptr->com->bin, envpath, msh); - ft_delwords(envpath); + { + u_search_in_path(tmp, rptr->com->bin, PATH_MAX, msh); + fullpath[i] = ft_strdup(tmp); + } } i++; rptr = rptr->next; -- cgit v1.2.3 From 33a5806163fb91e4a72e188a9933ada20395f4e9 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 15 Sep 2020 20:44:45 +0200 Subject: Builtins ref toked --- src/e_externs_pipes.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'src/e_externs_pipes.c') diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c index 05a2cf7..ca843d0 100644 --- a/src/e_externs_pipes.c +++ b/src/e_externs_pipes.c @@ -29,21 +29,6 @@ #include "u_path.h" #include "u_utils.h" -static uint8_t - get_builtin_id(const char com[], - t_msh *msh) -{ - uint8_t i; - - i = 0; - while (msh->bu_ref[i] && ft_strncmp(com, msh->bu_ref[i], - ft_strlen(msh->bu_ref[i]) + 1) != 0) - { - i++; - } - return (i); -} - static void e_pipe_child(char *fullpath[], uint8_t pipe_id, @@ -56,7 +41,7 @@ static void dup_redirs(ptr, msh); if (ft_strncmp(fullpath[pipe_id], "builtin", 8) == 0) { - bu_id = get_builtin_id(ptr->bin, msh); + bu_id = u_get_builtin_id(ptr->bin); ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); u_eof_fd(msh->fd); s_lpipes_clear(&msh->pipes); @@ -166,7 +151,7 @@ void } else { - if ((bu_id = get_builtin_id(rptr->com->bin, msh)) + if ((bu_id = u_get_builtin_id(rptr->com->bin)) < FT_BUILTINS_COUNT) { if ((fullpath[i] = ft_strdup("builtin")) == NULL) -- cgit v1.2.3