diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-05 10:21:43 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-05 10:21:43 +0000 |
| commit | c0dc27b0e94d8aca60fc47c9dee09eb170cb79dd (patch) | |
| tree | bfd7bde12746fb871a6437d90821dfd02707dae6 | |
| parent | 6d852035446ff5db6d5d5c0cd1dacf84db1a3709 (diff) | |
add exit_code for process signal'd
| -rw-r--r-- | include/handler.h | 2 | ||||
| -rw-r--r-- | src/handler.cc | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/include/handler.h b/include/handler.h index 8878eec..71db1b9 100644 --- a/include/handler.h +++ b/include/handler.h @@ -25,6 +25,8 @@ extern sigset_t inline std::atomic_int exit_code, exit_required_pid; +inline constexpr int SIGNAL_EXIT_CODE_BASE = 128; + void signal_init(); handler_t *Signal(int signum, handler_t *handler); void sigchld_handler(int sig); diff --git a/src/handler.cc b/src/handler.cc index f611784..7dc96a8 100644 --- a/src/handler.cc +++ b/src/handler.cc @@ -70,6 +70,7 @@ void sigchld_handler([[maybe_unused]] int sig) while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) { // signal'd or stopped or normally quit + // print terminated/stopped message if (WIFSIGNALED(status) || WIFSTOPPED(status)) { int jid = pid2jid(pid); @@ -88,12 +89,12 @@ void sigchld_handler([[maybe_unused]] int sig) safe_print("\n"); } + // handle job table + // and save exit/signal code + // stopped if (WIFSTOPPED(status)) { - // safe_debug("suspended pid: "); - // safe_debug(pid); - // safe_debug("\n"); safe_output("Process suspended PID: ", pid, "\n"); sigset_t prev_inner; block_all(&prev_inner); @@ -109,7 +110,7 @@ void sigchld_handler([[maybe_unused]] int sig) deletejob(pid); sigprocmask(SIG_SETMASK, &prev_inner, nullptr); - // normally quit + // terminated normally // so that exit code should be available if (WIFEXITED(status)) { @@ -120,6 +121,17 @@ void sigchld_handler([[maybe_unused]] int sig) safe_logger("sigchld_handler: required PID detected: ", pid, "\n"); } } + // if signal'd + else if (WIFSIGNALED(status)) + { + safe_output("Signal code: ", WTERMSIG(status), "\n"); + if (pid == exit_required_pid) + { + exit_code = SIGNAL_EXIT_CODE_BASE + WTERMSIG(status); + safe_logger("sigchld_handler: required PID detected: ", pid, "\n"); + } + } + } } |
