summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
authorPatrick Mooney <pmooney@pfmooney.com>2017-01-31 01:33:09 +0000
committerPatrick Mooney <pmooney@oxide.computer>2020-07-07 18:20:26 +0000
commitf4f9009fc79529ef8f45e7a31acd2ce4ca86a276 (patch)
treee047231acbae0e7c294f2986d8454f73ef6a2c70 /usr/src/lib/libc
parent95e434b588459fbd3ca313889cc0223436f1b0cd (diff)
downloadillumos-joyent-f4f9009fc79529ef8f45e7a31acd2ce4ca86a276.tar.gz
12912 epoll mishandles excessive timeout negativity
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Ryan Zezeski <ryan.zeseski@joyent.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/port/sys/epoll.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/usr/src/lib/libc/port/sys/epoll.c b/usr/src/lib/libc/port/sys/epoll.c
index 34cb151135..e510b0b247 100644
--- a/usr/src/lib/libc/port/sys/epoll.c
+++ b/usr/src/lib/libc/port/sys/epoll.c
@@ -10,7 +10,7 @@
*/
/*
- * Copyright 2016 Joyent, Inc.
+ * Copyright 2017 Joyent, Inc.
*/
#include <sys/types.h>
@@ -64,6 +64,15 @@
#define EPOLLSWIZZLED \
(EPOLLRDHUP | EPOLLONESHOT | EPOLLET | EPOLLWRBAND | EPOLLWRNORM)
+/*
+ * The defined behavior for epoll_wait/epoll_pwait when using a timeout less
+ * than 0 is to wait for events until they arrive (or interrupted by a signal).
+ * While poll(7d) operates in this manner for a timeout of -1, using other
+ * negative values results in an immediate timeout, as if it had been set to 0.
+ * For that reason, negative values are clamped to -1.
+ */
+#define EPOLL_TIMEOUT_CLAMP(t) (((t) < -1) ? -1 : (t))
+
int
epoll_create(int size)
{
@@ -209,7 +218,7 @@ epoll_wait(int epfd, struct epoll_event *events,
}
arg.dp_nfds = maxevents;
- arg.dp_timeout = timeout;
+ arg.dp_timeout = EPOLL_TIMEOUT_CLAMP(timeout);
arg.dp_fds = (pollfd_t *)events;
return (ioctl(epfd, DP_POLL, &arg));
@@ -227,7 +236,7 @@ epoll_pwait(int epfd, struct epoll_event *events,
}
arg.dp_nfds = maxevents;
- arg.dp_timeout = timeout;
+ arg.dp_timeout = EPOLL_TIMEOUT_CLAMP(timeout);
arg.dp_fds = (pollfd_t *)events;
arg.dp_setp = (sigset_t *)sigmask;