From 123283d840d744c3e59692255680e72ca452ffee Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Sat, 18 May 2019 03:59:48 +0200 Subject: [PATCH] Kernel: Fix poll() with timeout --- Kernel/Process.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index aa794962ec..ea03e9d62d 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1854,9 +1854,27 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout) current->m_select_write_fds.append(fds[i].fd); } - // FIXME: this should set m_select_timeout, right? - if (timeout < 0) + if (timeout >= 0) { + // poll is in ms, we want s/us. + struct timeval tvtimeout; + tvtimeout.tv_sec = 0; + while (timeout >= 1000) { + tvtimeout.tv_sec += 1; + timeout -= 1000; + } + tvtimeout.tv_usec = timeout * 1000; + + struct timeval now; + kgettimeofday(now); + AK::timeval_add(&now, &tvtimeout, ¤t->m_select_timeout); + current->m_select_has_timeout = true; + } else { + current->m_select_has_timeout = false; + } + + if (current->m_select_has_timeout || timeout < 0) { current->block(Thread::State::BlockedSelect); + } int fds_with_revents = 0;