diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-01-30 20:49:41 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-01-30 20:56:43 +0100 |
commit | 1334ca42c672320cd7113cbcbc253cd93bf158b8 (patch) | |
tree | 2c3e48e73cc37090203df733c501158d8e63c239 /src | |
parent | 6628a2d8b18030dd3ebc714f65e7af90bd0b711a (diff) |
Correctly return errors caused bu sub-process signals such as segfaults and aborts.
Diffstat (limited to 'src')
-rw-r--r-- | src/execute.cc | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/execute.cc b/src/execute.cc index 17f8714..a905efc 100644 --- a/src/execute.cc +++ b/src/execute.cc @@ -48,12 +48,38 @@ int parent_waitpid(pid_t pid) { int status{}; - if(waitpid(pid, &status, 0) != pid) + auto rc_pid = waitpid(pid, &status, 0); + + if(rc_pid > 0) { - return 1; + if(WIFEXITED(status)) + { + // Child exited with normally + return WEXITSTATUS(status); + } + if(WIFSIGNALED(status)) + { + // Child exited via signal (segfault, abort, ...) + std::cerr << strsignal(status) << '\n'; + return WTERMSIG(status); + } + } + else + { // No PID returned, this is an error + if(errno == ECHILD) + { + // No children exist. + return 1; + } + else + { + // Unexpected error. + abort(); + } } - return WEXITSTATUS(status); + // Should never happen... + return 1; } } // namespace :: |