From: Lukas Jiriste Date: Sun, 1 Sep 2024 08:20:58 +0000 (+0200) Subject: Make shell wait for processes to end after signal X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=0290132ca0095e5c99e189af53428f09f7fb5d4d;p=42%2Fminishell.git Make shell wait for processes to end after signal Before the shell would send the signal to children and assume they terminated. Now it actually still waits for them to terminate. --- diff --git a/src/execution.c b/src/execution.c index 0fd24fd..8ee7e80 100644 --- a/src/execution.c +++ b/src/execution.c @@ -6,7 +6,7 @@ /* By: lnikolov size; while (i > 0) { --i; pid = *(pid_t *)ft_vec_access(child_pids, i); - waitpid(pid, NULL, 0); + if (g_last_signal == 0) + waitpid(pid, NULL, 0); if (g_last_signal) { + sig_num = g_last_signal; + g_last_signal = 0; killall(child_pids, g_last_signal); - return ; + i = child_pids->size; } ft_vec_forget(child_pids, i); } ft_vec_free(child_pids, NULL); + if (g_last_signal == 0) + g_last_signal = sig_num; + return ; } void wait_for_return(t_execution_env *env) @@ -1087,8 +1095,6 @@ void wait_for_return(t_execution_env *env) last_pid = *(pid_t *)ft_vec_access(&env->child_pids, env->child_pids.size - 1); waitpid(last_pid, &status, 0); - if (g_last_signal != 0) - killall(&env->child_pids, g_last_signal); if (g_last_signal == 0) if (WIFEXITED(status)) env->ret_val = WEXITSTATUS(status);