diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-05-18 02:00:01 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-18 02:57:38 +0200 |
commit | df74a9222f4e40d7b9ba41c77d443490c97fd333 (patch) | |
tree | 3b81bf13a5a7dc9c3a02af9af692651bee06662c /Kernel/Process.cpp | |
parent | 8f3022b5c17bfd1f796de5e7a40adada6aaea429 (diff) | |
download | serenity-df74a9222f4e40d7b9ba41c77d443490c97fd333.zip |
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.
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r-- | Kernel/Process.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 4063a2263b..ea5cd64935 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -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, ¤t->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); |