From 0f2d351f790516bc3f1158d964c5f83f339addb2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 10 Jun 2020 11:43:40 +0200 Subject: tree-wide: port to fd_wait_for_event() Prompted by the discussion on #16110, let's migrate more code to fd_wait_for_event(). This only leaves 7 places where we call into poll()/poll() directly in our entire codebase. (one of which is fd_wait_for_event() itself) --- src/basic/io-util.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'src/basic/io-util.c') diff --git a/src/basic/io-util.c b/src/basic/io-util.c index 4b3d1c814f..18baadb1fe 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -11,10 +11,6 @@ #include "time-util.h" int flush_fd(int fd) { - struct pollfd pollfd = { - .fd = fd, - .events = POLLIN, - }; int count = 0; /* Read from the specified file descriptor, until POLLIN is not set anymore, throwing away everything @@ -27,22 +23,18 @@ int flush_fd(int fd) { ssize_t l; int r; - r = poll(&pollfd, 1, 0); + r = fd_wait_for_event(fd, POLLIN, 0); if (r < 0) { - if (errno == EINTR) + if (r == -EINTR) continue; - return -errno; + return r; } if (r == 0) return count; - if (pollfd.revents & POLLNVAL) - return -EBADF; - l = read(fd, buf, sizeof(buf)); if (l < 0) { - if (errno == EINTR) continue; @@ -158,24 +150,15 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) { } int pipe_eof(int fd) { - struct pollfd pollfd = { - .fd = fd, - .events = POLLIN|POLLHUP, - }; - int r; - r = poll(&pollfd, 1, 0); + r = fd_wait_for_event(fd, POLLIN, 0); if (r < 0) - return -errno; - + return r; if (r == 0) return 0; - if (pollfd.revents & POLLNVAL) - return -EBADF; - - return pollfd.revents & POLLHUP; + return !!(r & POLLHUP); } int fd_wait_for_event(int fd, int event, usec_t t) { -- cgit v1.2.1