Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/builtins/builtin_cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 18 additions & 3 deletions src/executor/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,30 @@ 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);
Expand All @@ -46,7 +57,11 @@ void wait_pid(t_shell *shell, pid_t *pid, int nb_cmd)
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)
Expand Down
Loading