summaryrefslogtreecommitdiff
path: root/src/execute.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/execute.cc')
-rw-r--r--src/execute.cc32
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 ::