From dec27e5e6fad25fedd9203087b8107242369dd2b Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 6 Jul 2020 19:30:55 +0430 Subject: [PATCH] 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. --- Shell/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Shell/main.cpp b/Shell/main.cpp index 743bab0d4d..0939de5eb3 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -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.