From 23b6e7ea2b39f2640d9bb43f6567e7fb1c058094 Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Sat, 31 Oct 2026 12:20:32 +0100 Subject: [PATCH 1/3] fix where sigint signal didnt output \n before showing prompt --- src/executor/process.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/executor/process.c b/src/executor/process.c index 8f3d698..ca92b09 100644 --- a/src/executor/process.c +++ b/src/executor/process.c @@ -41,6 +41,8 @@ void wait_pid(t_shell *shell, pid_t *pid, int nb_cmd) { if (WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT) write(2, "Quit (core dumped)\n", 19); + if (WTERMSIG(status) == SIGINT) + write(2, "\n", 1); if (WIFSIGNALED(status)) shell->exit_status = EXIT_SIGNAL_BASE + WTERMSIG(status); else From 6eccc1b1112003710276e8a374de720fc5df10b4 Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Sat, 31 Oct 2026 12:25:05 +0100 Subject: [PATCH 2/3] prevent leak when directory was not found, cwd was not freed --- src/builtins/builtin_cd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builtins/builtin_cd.c b/src/builtins/builtin_cd.c index d2b70e9..3585c55 100644 --- a/src/builtins/builtin_cd.c +++ b/src/builtins/builtin_cd.c @@ -59,7 +59,7 @@ static int change_dir(t_shell *shell, char *path) { write(2, "minishell: cd: ", 15); perror(shell->cmds->cmd_args[1]); - return (1); + return (free(cwd), 1); } if (set_env(envp, cwd, "OLDPWD=")) return (1); From 723a2f0e65343979106bfbd5c31ce57b9df9bcd4 Mon Sep 17 00:00:00 2001 From: ruipedro-pinheiro Date: Sat, 31 Oct 2026 12:44:27 +0100 Subject: [PATCH 3/3] add \n even if the last child is not siging but other before do --- src/executor/process.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/executor/process.c b/src/executor/process.c index ca92b09..605573a 100644 --- a/src/executor/process.c +++ b/src/executor/process.c @@ -25,30 +25,43 @@ void childs_exit(t_shell *shell, int i, int *fd, int code) exit(code); } +static bool get_caught_pid(pid_t *pid, int *status, int i, pid_t last_pid) +{ + pid_t caugth_pid; + + caugth_pid = waitpid(pid[i], status, 0); + if (caugth_pid == last_pid) + return (true); + return (false); +} + void wait_pid(t_shell *shell, pid_t *pid, int nb_cmd) { int status; int i; - pid_t caugth_pid; pid_t last_pid; + bool is_child_sigint; + status = 0; last_pid = pid[nb_cmd - 1]; i = -1; + is_child_sigint = false; while (++i < nb_cmd) { - caugth_pid = waitpid(pid[i], &status, 0); - if (caugth_pid == last_pid) + if (get_caught_pid(pid, &status, i, last_pid)) { if (WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT) write(2, "Quit (core dumped)\n", 19); - if (WTERMSIG(status) == SIGINT) - write(2, "\n", 1); if (WIFSIGNALED(status)) shell->exit_status = EXIT_SIGNAL_BASE + WTERMSIG(status); else shell->exit_status = WEXITSTATUS(status); } + if (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT) + is_child_sigint = true; } + if (is_child_sigint) + write(2, "\n", 1); } static void run_child(t_shell *shell, int i, int *fd, t_cmd *current)