Kernel: Fix timeout support in select

The scheduler expects m_select_timeout to act as a deadline. That is, it
should contain the time that a task should wake at -- but we were
directly copying the time from userspace, which meant that it always
returned virtually immediately.

At the same time, fix CEventLoop to not rely on the broken select behavior
by subtracting the current time from the time of the nearest timer.
This commit is contained in:
Robin Burchell 2019-05-18 02:00:01 +02:00 committed by Andreas Kling
commit df74a9222f
Notes: sideshowbarker 2024-07-19 14:02:53 +09:00
4 changed files with 40 additions and 15 deletions

View file

@ -21,6 +21,7 @@
#include <Kernel/TTY/MasterPTY.h>
#include <Kernel/ELF/exec_elf.h>
#include <AK/StringBuilder.h>
#include <AK/Time.h>
#include <Kernel/SharedMemory.h>
#include <Kernel/ProcessTracer.h>
@ -1735,7 +1736,9 @@ int Process::sys$select(const Syscall::SC_select_params* params)
(void)exceptfds;
if (timeout) {
current->m_select_timeout = *timeout;
struct timeval now;
kgettimeofday(now);
AK::timeval_add(&now, timeout, &current->m_select_timeout);
current->m_select_has_timeout = true;
} else {
current->m_select_has_timeout = false;
@ -1829,6 +1832,7 @@ 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)
current->block(Thread::State::BlockedSelect);