summaryrefslogtreecommitdiff
path: root/src/basic/io-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-06-10 11:43:40 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2020-06-10 20:06:10 +0200
commit0f2d351f790516bc3f1158d964c5f83f339addb2 (patch)
treef9df08ab66c5c7be26c92e1767d39835cc9f472c /src/basic/io-util.c
parent24bd74ae03efc98272236bd0a98a1d7d090d540c (diff)
downloadsystemd-0f2d351f790516bc3f1158d964c5f83f339addb2.tar.gz
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)
Diffstat (limited to 'src/basic/io-util.c')
-rw-r--r--src/basic/io-util.c29
1 files changed, 6 insertions, 23 deletions
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) {