diff --git a/kernel/src/sys/poll.cpp b/kernel/src/sys/poll.cpp index 96a77b75..42d99fff 100644 --- a/kernel/src/sys/poll.cpp +++ b/kernel/src/sys/poll.cpp @@ -1,3 +1,4 @@ +#include "Log.h" #include "fs/VFS.h" #include "memory/MemoryManager.h" #include "sys/Syscall.h" @@ -24,6 +25,7 @@ Result sys_poll(Registers* regs, SyscallArgs args) auto maybe_inode = current->resolve_fd(fd); if (maybe_inode.has_error()) { + kwarnln("poll: fd %lu (%d) is not valid, storing POLLNVAL", i, fd); kfds[i].revents |= POLLNVAL; TRY(inodes.try_append({})); } @@ -32,7 +34,7 @@ Result sys_poll(Registers* regs, SyscallArgs args) } bool infinite = timeout < 0; - int fds_with_events; + nfds_t fds_with_events; do { fds_with_events = 0; @@ -51,7 +53,7 @@ Result sys_poll(Registers* regs, SyscallArgs args) if (!fds_with_events && (timeout > 0 || infinite)) { kernel_sleep(10); - timeout -= (int)current->sleep_ticks_left; + timeout -= (10 - (int)current->sleep_ticks_left); if (current->interrupted) { guard.deactivate(); @@ -62,7 +64,9 @@ Result sys_poll(Registers* regs, SyscallArgs args) } continue; } - } while (false); + + break; + } while (1); MemoryManager::copy_to_user(fds, kfds, nfds * sizeof(pollfd)); diff --git a/libc/include/bits/poll.h b/libc/include/bits/poll.h index 83f46a77..35600ed8 100644 --- a/libc/include/bits/poll.h +++ b/libc/include/bits/poll.h @@ -5,9 +5,9 @@ #include -#define POLLIN 0 -#define POLLERR 1 -#define POLLNVAL 2 +#define POLLIN (1 << 0) +#define POLLERR (1 << 1) +#define POLLNVAL (1 << 2) typedef __u64_t nfds_t;