From 032bd9a2ff8f15f29a4d9cc7ec6accfea7315ce8 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Thu, 29 Aug 2024 18:22:30 +0200 Subject: [PATCH] Implement signal handling for execution It may need some additional output. --- src/execution.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/execution.c b/src/execution.c index a3ba582..d9dfe11 100644 --- a/src/execution.c +++ b/src/execution.c @@ -6,7 +6,7 @@ /* By: lnikolov size) + { + child_pid = *(pid_t *)ft_vec_access(child_pids, i); + kill(child_pid, sig_num); + ++i; + } + return ; +} + void wait_for_return(t_execution_env *env) { pid_t last_pid; @@ -987,8 +1002,11 @@ void wait_for_return(t_execution_env *env) return ; last_pid = *(pid_t *)ft_vec_access(&env->child_pids, env->child_pids.size - 1); waitpid(last_pid, &status, 0); - if (WIFEXITED(status)) - env->ret_val = WEXITSTATUS(status); + 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); } ft_vec_free(&env->child_pids, NULL); return ; @@ -998,6 +1016,8 @@ int ex_pipeline(t_parse_tree_node *pipeline, t_execution_env *env, int depth) { int pipe_fds[2]; + if (g_last_signal != 0) + return (0); if (pipeline->children.size == 1) { if (ex_command(ft_vec_access(&pipeline->children, 0), env)) @@ -1045,5 +1065,10 @@ int execute(t_tree *parse_tree, t_execution_env *env) int res; res = ex_program(parse_tree, env); + if (g_last_signal != 0) + { + env->ret_val = 128 + g_last_signal; + g_last_signal = 0; + } return (res); } -- 2.30.2