1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

Shell: Handle the case where the child we're waiting for doesn't exist

Normally, this should not happen, as the child should stay around until
we do a waitid on it.
This commit is contained in:
AnotherTest 2020-07-06 19:30:55 +04:30 committed by Andreas Kling
parent e91dd14fab
commit dec27e5e6f

View file

@ -78,6 +78,16 @@ int main(int argc, char** argv)
for (auto& job : jobs) {
int wstatus = 0;
auto child_pid = waitpid(job.value->pid(), &wstatus, WNOHANG);
if (child_pid < 0) {
if (errno == ECHILD) {
// The child process went away before we could process its death, just assume it exited all ok.
// FIXME: This should never happen, the child should stay around until we do the waitpid above.
dbg() << "Child process gone, cannot get exit code for " << job.key;
child_pid = job.value->pid();
} else {
ASSERT_NOT_REACHED();
}
}
#ifndef __serenity__
if (child_pid == 0) {
// Linux: if child didn't "change state", but existed.