Kernel: Fix returning random children from waitid(WNOHANG)

In case WNOHANG was specified, we want to always set should_unblock to
true (which we do since commit 4402207b98), not
wait_finished -- the latter causes us to immediately return this child to our
caller, which is not what we want -- perhaps we should return another child
which has actually exited or stopped, or nobody at all.

To avoid confusion, also rename wait_finished to fits_the_spec.

This fixes service keepalive functionality in SystemServer.
This commit is contained in:
Sergey Bugaev 2020-05-25 13:23:41 +03:00 committed by Andreas Kling
parent 2c2ce5be64
commit 431bbde6df
Notes: sideshowbarker 2024-07-19 06:09:36 +09:00

View file

@ -273,11 +273,10 @@ bool Thread::WaitBlocker::should_unblock(Thread& thread, time_t, long)
});
}
bool wait_finished = ((m_wait_options & WEXITED) && child_exited)
|| ((m_wait_options & WSTOPPED) && child_stopped)
|| (m_wait_options & WNOHANG);
bool fits_the_spec = ((m_wait_options & WEXITED) && child_exited)
|| ((m_wait_options & WSTOPPED) && child_stopped);
if (!wait_finished)
if (!fits_the_spec)
return IterationDecision::Continue;
m_waitee_pid = child.pid();