From 431bbde6dfffcf51f48981255e0d04091cc9d0b1 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Mon, 25 May 2020 13:23:41 +0300 Subject: [PATCH] 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 4402207b983b6ad4e317ef5affa4a78f10903a26), 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. --- Kernel/Scheduler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 1c3f3b19fc..76156bd283 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -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();