From d7374347258248c4552a4863893aabf6ebb0feee Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Thu, 29 Oct 2026 15:12:49 +0100 Subject: [PATCH 1/6] better way to close fds 0 and 1 --- src/builtins/builtins.c | 4 +--- src/executor/process.c | 11 ++++------- src/main.c | 5 ++++- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/builtins/builtins.c b/src/builtins/builtins.c index 3fc2e9e..2015ffe 100644 --- a/src/builtins/builtins.c +++ b/src/builtins/builtins.c @@ -6,7 +6,7 @@ /* By: chguerre is_exitting) - (close(0), close(1)); return (code); } diff --git a/src/executor/process.c b/src/executor/process.c index 8884cd3..e0e46e5 100644 --- a/src/executor/process.c +++ b/src/executor/process.c @@ -6,7 +6,7 @@ /* By: chguerre prevfd != -1) close(shell->prevfd); if (i < shell->cmd_count - 1) - { - close(fd[0]); - close(fd[1]); - } + (void)fd; if (shell->pids != NULL) free(shell->pids); ft_strfree(shell->env); @@ -76,8 +73,8 @@ static void run_child(t_shell *shell, int i, int *fd, t_cmd *current) childs_exit(shell, i, fd, 127); } if ((execve(current->path, current->cmd_args, shell->env)) == -1) - (perror(current->cmd_args[0]), - childs_exit(shell, i, fd, 126 + (errno == ENOENT))); + (perror(current->cmd_args[0]), childs_exit(shell, i, fd, 126 + + (errno == ENOENT))); } int fork_setup(t_shell *shell, int i, int *fd, t_cmd *current) diff --git a/src/main.c b/src/main.c index 8d30796..4c456ff 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,8 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: chguerre +#+ +:+ +#+ */ +/* By: chguerre +#+ +:+ + +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/10/16 14:06:14 by rpinheir #+# #+# */ /* Updated: 2026/10/22 16:19:18 by rpinheir ### ########.ch */ @@ -89,5 +90,7 @@ int main(int ac, char **av, char **env) if (shell.cmds) free_cmds(shell.cmds); ft_strfree(shell.env); + close(0); + close(1); return (shell.exit_status); } From e044bfe64d7e408e5159940a5057cad2dd58a985 Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Thu, 29 Oct 2026 15:13:54 +0100 Subject: [PATCH 2/6] pass it to the prompt --- src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 4c456ff..7cc129b 100644 --- a/src/main.c +++ b/src/main.c @@ -72,6 +72,8 @@ void show_prompt(t_shell *shell) else if (line[0] && entry_exec(line, shell) == 1) continue ; } + close(0); + close(1); } int main(int ac, char **av, char **env) @@ -90,7 +92,5 @@ int main(int ac, char **av, char **env) if (shell.cmds) free_cmds(shell.cmds); ft_strfree(shell.env); - close(0); - close(1); return (shell.exit_status); } From 9da1157ec913adaca8d0d194659f1fdc61e30fe2 Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Thu, 29 Oct 2026 15:30:04 +0100 Subject: [PATCH 3/6] fix where perror modifies errno before if statement --- src/executor/process.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/executor/process.c b/src/executor/process.c index e0e46e5..7fe5819 100644 --- a/src/executor/process.c +++ b/src/executor/process.c @@ -6,7 +6,7 @@ /* By: chguerre path, current->cmd_args, shell->env)) == -1) - (perror(current->cmd_args[0]), childs_exit(shell, i, fd, 126 - + (errno == ENOENT))); + execve(current->path, current->cmd_args, shell->env); + code = errno; + perror(current->cmd_args[0]); + childs_exit(shell, i, fd, 126 + (code == ENOENT)); } int fork_setup(t_shell *shell, int i, int *fd, t_cmd *current) From dbc6de201dd4fd83d8ca981c1a419c425707d31f Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Thu, 29 Oct 2026 15:34:07 +0100 Subject: [PATCH 4/6] using forbidded function --- src/builtins/builtin_unset.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/builtins/builtin_unset.c b/src/builtins/builtin_unset.c index 8ac5d33..473f294 100644 --- a/src/builtins/builtin_unset.c +++ b/src/builtins/builtin_unset.c @@ -6,7 +6,7 @@ /* By: chguerre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/10/22 21:14:24 by chguerre #+# #+# */ -/* Updated: 2026/10/26 20:48:58 by chguerre ### ########.fr */ +/* Updated: 2026/10/29 15:33:37 by rpinheir ### ########.ch */ /* */ /* ************************************************************************** */ @@ -27,9 +27,9 @@ int filter_envp(t_shell *shell, char **cmd_args) i = 1; while (cmd_args[i]) { - keylen = strlen(cmd_args[i]); - if (shell->env[j] != NULL && ft_strncmp(shell->env[j], - cmd_args[i], keylen) == 0 && shell->env[j][keylen] == '=' ) + keylen = ft_strlen(cmd_args[i]); + if (shell->env[j] != NULL && ft_strncmp(shell->env[j], cmd_args[i], + keylen) == 0 && shell->env[j][keylen] == '=') { finded++; (free(shell->env[j]), shell->env[j] = NULL); From 8f758579d84f20924d165105bf93ade43578911a Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Thu, 29 Oct 2026 15:49:57 +0100 Subject: [PATCH 5/6] remove unused struct members --- inc/struct.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/inc/struct.h b/inc/struct.h index fb8ad6c..835a644 100644 --- a/inc/struct.h +++ b/inc/struct.h @@ -6,7 +6,7 @@ /* By: rpinheir +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/10/16 14:09:15 by rpinheir #+# #+# */ -/* Updated: 2026/10/16 14:42:36 by rpinheir ### ########.ch */ +/* Updated: 2026/10/29 15:35:14 by rpinheir ### ########.ch */ /* */ /* ************************************************************************** */ @@ -15,8 +15,8 @@ # define EXIT_SIGNAL_BASE 128 # define WS_SEP '\001' -# include "libft/libft.h" # include "enum.h" +# include "libft/libft.h" typedef struct s_token { @@ -25,7 +25,7 @@ typedef struct s_token bool is_quoted; char *value; struct s_token *next; -} t_token; +} t_token; typedef struct s_redir { @@ -33,7 +33,7 @@ typedef struct s_redir char *file; struct s_redir *next; bool is_quoted; -} t_redir; +} t_redir; typedef struct s_cmd { @@ -41,13 +41,11 @@ typedef struct s_cmd char *path; t_redir *redirections; struct s_cmd *next; -} t_cmd; +} t_cmd; typedef struct s_shell { - pid_t hereid; int prevfd; - int wread[2]; int cmd_count; pid_t *pids; t_cmd *cmds; @@ -55,6 +53,6 @@ typedef struct s_shell char **env; long long exit_status; bool is_exitting; -} t_shell; +} t_shell; #endif From 62c3645245af54afd8592e830253eb5c2d4d89b3 Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Thu, 29 Oct 2026 15:50:30 +0100 Subject: [PATCH 6/6] clean child_exit if and fd's --- src/executor/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/executor/process.c b/src/executor/process.c index 7fe5819..8f3d698 100644 --- a/src/executor/process.c +++ b/src/executor/process.c @@ -6,7 +6,7 @@ /* By: chguerre prevfd != -1) close(shell->prevfd); - if (i < shell->cmd_count - 1) - (void)fd; + (void)fd; + (void)i; if (shell->pids != NULL) free(shell->pids); ft_strfree(shell->env);