summary refs log tree commit diff
path: root/sys_util/src/poll.rs
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2018-03-28 17:16:20 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-03-29 21:59:45 -0700
commit1028f53ed2bcdc3088f73f59f268f3e99d5c06c9 (patch)
tree6c996bfd396519d434f796dd61e150c4c71a0fe4 /sys_util/src/poll.rs
parent3afab33a8d797433b6742963ac34e5cf1a57bf64 (diff)
downloadcrosvm-1028f53ed2bcdc3088f73f59f268f3e99d5c06c9.tar
crosvm-1028f53ed2bcdc3088f73f59f268f3e99d5c06c9.tar.gz
crosvm-1028f53ed2bcdc3088f73f59f268f3e99d5c06c9.tar.bz2
crosvm-1028f53ed2bcdc3088f73f59f268f3e99d5c06c9.tar.lz
crosvm-1028f53ed2bcdc3088f73f59f268f3e99d5c06c9.tar.xz
crosvm-1028f53ed2bcdc3088f73f59f268f3e99d5c06c9.tar.zst
crosvm-1028f53ed2bcdc3088f73f59f268f3e99d5c06c9.zip
sys_util: have Poller return token on POLLHUP
If POLLHUP is filtered out of the returned tokens, the caller of
Poller::poll will likely just put the same (token, fd) in the next call
to poll which will return instantly. This degrades into a busy poll loop
without the chance for the caller to change the poll list.

Instead, this change changes the filter to return tokens on POLLHUP so
that the caller will hopefully notice the FD associated with the token
has been hungup and will close it.

BUG=chromium:816692
TEST=None

Change-Id: Ie36d8a647a5fd7faabfd57a562205f75c77991e7
Reviewed-on: https://chromium-review.googlesource.com/985616
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'sys_util/src/poll.rs')
-rw-r--r--sys_util/src/poll.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/sys_util/src/poll.rs b/sys_util/src/poll.rs
index 762c5e4..d8ea45d 100644
--- a/sys_util/src/poll.rs
+++ b/sys_util/src/poll.rs
@@ -16,7 +16,7 @@ use std::thread;
 use std::time::Duration;
 
 use libc::{c_int, c_long, timespec, time_t, nfds_t, sigset_t, pollfd, syscall, SYS_ppoll, POLLIN,
-           EPOLL_CLOEXEC, EPOLLIN, EPOLLHUP, EPOLL_CTL_ADD, EPOLL_CTL_MOD, EPOLL_CTL_DEL,
+           POLLHUP, EPOLL_CLOEXEC, EPOLLIN, EPOLLHUP, EPOLL_CTL_ADD, EPOLL_CTL_MOD, EPOLL_CTL_DEL,
            epoll_create1, epoll_ctl, epoll_wait, epoll_event};
 
 use {Result, errno_result};
@@ -140,7 +140,7 @@ impl Poller {
 
         self.tokens.clear();
         for (pollfd, pollable) in self.pollfds.iter().zip(pollables.iter()) {
-            if (pollfd.revents & POLLIN) != 0 {
+            if (pollfd.revents & (POLLIN | POLLHUP)) != 0 {
                 self.tokens.push(pollable.0);
             }
         }