summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@apple.com>2012-01-04 10:33:29 -0800
committerJeremy Huddleston <jeremyhu@apple.com>2012-01-10 00:32:46 -0800
commit70bb9e28d37fff4ead4d0a2c672af77059765fa4 (patch)
tree76431d0844b631d04ff5cf6989b4e7213d4d8f29
parent6dd231d37c036d182e789f0af37ee5417792ad4e (diff)
Treat unexpected returned events from poll as errors
Inspired by libxcb's f0565e8f06aadf760a9065a97b8cf5ab9cbd18de Resolves https://bugs.freedesktop.org/show_bug.cgi?id=20048 Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r--src/NextEvent.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/NextEvent.c b/src/NextEvent.c
index b1f7bc7..c8c9dd5 100644
--- a/src/NextEvent.c
+++ b/src/NextEvent.c
@@ -356,7 +356,21 @@ static int IoWait (
return Select (wf->nfds, &wf->rmask, &wf->wmask, &wf->emask,
wt->wait_time_ptr);
#else
- return poll (wf->fdlist, wf->fdlistlen, wt->poll_wait);
+ int ret = poll (wf->fdlist, wf->fdlistlen, wt->poll_wait);
+ /* If poll() returns an event we didn't expect, such as POLLNVAL, treat
+ * it as if it failed. */
+ if(ret >= 0) {
+ nfds_t i;
+ for (i=0; i < wf->fdlistlen; i++) {
+ struct pollfd *fd = &wf->fdlist[i];
+ if (fd->revents & ~fd->events) {
+ ret = -1;
+ errno = EIO;
+ break;
+ }
+ }
+ }
+ return ret;
#endif
}