mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
Process: Fix select/poll EINTR
Check for EINTR before doing anything with the passed sets, otherwise we zero them out which means a re-call with the same sets won't work.
This commit is contained in:
parent
29a62558c4
commit
a1eff3daba
1 changed files with 8 additions and 16 deletions
|
@ -1837,9 +1837,10 @@ int Process::sys$select(const Syscall::SC_select_params* params)
|
||||||
dbgprintf("%s<%u> selecting on (read:%u, write:%u), timeout=%p\n", name().characters(), pid(), rfds.size(), wfds.size(), params->timeout);
|
dbgprintf("%s<%u> selecting on (read:%u, write:%u), timeout=%p\n", name().characters(), pid(), rfds.size(), wfds.size(), params->timeout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Thread::BlockResult block_res = Thread::BlockResult::WokeNormally;
|
if (!params->timeout || select_has_timeout) {
|
||||||
if (!params->timeout || select_has_timeout)
|
if (current->block<Thread::SelectBlocker>(timeout, select_has_timeout, rfds, wfds, efds) == Thread::BlockResult::InterruptedBySignal)
|
||||||
block_res = current->block<Thread::SelectBlocker>(timeout, select_has_timeout, rfds, wfds, efds);
|
return -EINTR;
|
||||||
|
}
|
||||||
|
|
||||||
int marked_fd_count = 0;
|
int marked_fd_count = 0;
|
||||||
auto mark_fds = [&](auto* fds, auto& vector, auto should_mark) {
|
auto mark_fds = [&](auto* fds, auto& vector, auto should_mark) {
|
||||||
|
@ -1857,11 +1858,6 @@ int Process::sys$select(const Syscall::SC_select_params* params)
|
||||||
mark_fds(params->writefds, wfds, [](auto& description) { return description.can_write(); });
|
mark_fds(params->writefds, wfds, [](auto& description) { return description.can_write(); });
|
||||||
// FIXME: We should also mark params->exceptfds as appropriate.
|
// FIXME: We should also mark params->exceptfds as appropriate.
|
||||||
|
|
||||||
if (marked_fd_count == 0) {
|
|
||||||
if (block_res == Thread::BlockResult::InterruptedBySignal)
|
|
||||||
return -EINTR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return marked_fd_count;
|
return marked_fd_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1899,9 +1895,10 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout)
|
||||||
dbgprintf("%s<%u> polling on (read:%u, write:%u), timeout=%d\n", name().characters(), pid(), rfds.size(), wfds.size(), timeout);
|
dbgprintf("%s<%u> polling on (read:%u, write:%u), timeout=%d\n", name().characters(), pid(), rfds.size(), wfds.size(), timeout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Thread::BlockResult block_res = Thread::BlockResult::WokeNormally;
|
if (has_timeout|| timeout < 0) {
|
||||||
if (has_timeout|| timeout < 0)
|
if (current->block<Thread::SelectBlocker>(actual_timeout, has_timeout, rfds, wfds, Thread::SelectBlocker::FDVector()) == Thread::BlockResult::InterruptedBySignal)
|
||||||
block_res = current->block<Thread::SelectBlocker>(actual_timeout, has_timeout, rfds, wfds, Thread::SelectBlocker::FDVector());
|
return -EINTR;
|
||||||
|
}
|
||||||
|
|
||||||
int fds_with_revents = 0;
|
int fds_with_revents = 0;
|
||||||
|
|
||||||
|
@ -1921,11 +1918,6 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout)
|
||||||
++fds_with_revents;
|
++fds_with_revents;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fds_with_revents == 0) {
|
|
||||||
if (block_res != Thread::BlockResult::InterruptedBySignal)
|
|
||||||
return -EINTR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fds_with_revents;
|
return fds_with_revents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue