diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-03-04 17:23:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-04 17:23:17 +0100 |
commit | 9706d27cbeb66d7db425c959a8368e0aaded86d4 (patch) | |
tree | 959211a990b5d4d888a887d98e3fcb72a7423b92 /src/shared | |
parent | install: include OS headers before our own definition (diff) | |
parent | tree-wide: use ppoll_usec() (diff) | |
download | systemd-9706d27cbeb66d7db425c959a8368e0aaded86d4.tar.xz systemd-9706d27cbeb66d7db425c959a8368e0aaded86d4.zip |
Merge pull request #18840 from yuwata/libudev-monitor-tiny-cleanup
io-util: introduce ppoll_usec()
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/ask-password-api.c | 107 | ||||
-rw-r--r-- | src/shared/barrier.c | 14 |
2 files changed, 35 insertions, 86 deletions
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index bd33bdd2c5..7137eb3130 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -4,7 +4,6 @@ #include <fcntl.h> #include <inttypes.h> #include <limits.h> -#include <poll.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> @@ -276,44 +275,28 @@ int ask_password_plymouth( pollfd[POLL_INOTIFY].events = POLLIN; for (;;) { - int sleep_for = -1, j; + usec_t timeout; - if (until > 0) { - usec_t y; - - y = now(CLOCK_MONOTONIC); - - if (y > until) { - r = -ETIME; - goto finish; - } - - sleep_for = (int) ((until - y) / USEC_PER_MSEC); - } + if (until > 0) + timeout = usec_sub_unsigned(until, now(CLOCK_MONOTONIC)); + else + timeout = USEC_INFINITY; if (flag_file && access(flag_file, F_OK) < 0) { r = -errno; goto finish; } - j = poll(pollfd, notify >= 0 ? 2 : 1, sleep_for); - if (j < 0) { - if (errno == EINTR) - continue; - - r = -errno; + r = ppoll_usec(pollfd, notify >= 0 ? 2 : 1, timeout); + if (r == -EINTR) + continue; + if (r < 0) goto finish; - } else if (j == 0) { + if (r == 0) { r = -ETIME; goto finish; } - if (pollfd[POLL_SOCKET].revents & POLLNVAL || - (notify >= 0 && pollfd[POLL_INOTIFY].revents & POLLNVAL)) { - r = -EBADF; - goto finish; - } - if (notify >= 0 && pollfd[POLL_INOTIFY].revents != 0) (void) flush_fd(notify); @@ -513,21 +496,13 @@ int ask_password_tty( for (;;) { _cleanup_(erase_char) char c; - int sleep_for = -1, k; + usec_t timeout; ssize_t n; - if (until > 0) { - usec_t y; - - y = now(CLOCK_MONOTONIC); - - if (y > until) { - r = -ETIME; - goto finish; - } - - sleep_for = (int) DIV_ROUND_UP(until - y, USEC_PER_MSEC); - } + if (until > 0) + timeout = usec_sub_unsigned(until, now(CLOCK_MONOTONIC)); + else + timeout = USEC_INFINITY; if (flag_file) if (access(flag_file, F_OK) < 0) { @@ -535,24 +510,16 @@ int ask_password_tty( goto finish; } - k = poll(pollfd, notify >= 0 ? 2 : 1, sleep_for); - if (k < 0) { - if (errno == EINTR) - continue; - - r = -errno; + r = ppoll_usec(pollfd, notify >= 0 ? 2 : 1, timeout); + if (r == -EINTR) + continue; + if (r < 0) goto finish; - } else if (k == 0) { + if (r == 0) { r = -ETIME; goto finish; } - if ((pollfd[POLL_TTY].revents & POLLNVAL) || - (notify >= 0 && (pollfd[POLL_INOTIFY].revents & POLLNVAL))) { - r = -EBADF; - goto finish; - } - if (notify >= 0 && pollfd[POLL_INOTIFY].revents != 0 && keyname) { (void) flush_fd(notify); @@ -875,38 +842,24 @@ int ask_password_agent( char passphrase[LINE_MAX+1]; struct iovec iovec; struct ucred *ucred; + usec_t timeout; ssize_t n; - int k; - usec_t t; - - t = now(CLOCK_MONOTONIC); - - if (until > 0 && until <= t) { - r = -ETIME; - goto finish; - } - k = poll(pollfd, notify >= 0 ? _FD_MAX : _FD_MAX - 1, until > 0 ? (int) ((until-t)/USEC_PER_MSEC) : -1); - if (k < 0) { - if (errno == EINTR) - continue; + if (until > 0) + timeout = usec_sub_unsigned(until, now(CLOCK_MONOTONIC)); + else + timeout = USEC_INFINITY; - r = -errno; + r = ppoll_usec(pollfd, notify >= 0 ? _FD_MAX : _FD_MAX - 1, timeout); + if (r == -EINTR) + continue; + if (r < 0) goto finish; - } - - if (k <= 0) { + if (r == 0) { r = -ETIME; goto finish; } - if (pollfd[FD_SOCKET].revents & POLLNVAL || - pollfd[FD_SIGNAL].revents & POLLNVAL || - (notify >= 0 && pollfd[FD_INOTIFY].revents & POLLNVAL)) { - r = -EBADF; - goto finish; - } - if (pollfd[FD_SIGNAL].revents & POLLIN) { r = -EINTR; goto finish; diff --git a/src/shared/barrier.c b/src/shared/barrier.c index 271bba8cde..2864c1b8f9 100644 --- a/src/shared/barrier.c +++ b/src/shared/barrier.c @@ -2,7 +2,6 @@ #include <errno.h> #include <fcntl.h> -#include <poll.h> #include <stdbool.h> #include <stdint.h> #include <stdlib.h> @@ -12,6 +11,7 @@ #include "barrier.h" #include "fd-util.h" +#include "io-util.h" #include "macro.h" /** @@ -219,14 +219,10 @@ static bool barrier_read(Barrier *b, int64_t comp) { uint64_t buf; int r; - r = poll(pfd, ELEMENTSOF(pfd), -1); - if (r < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) - continue; - goto error; - } - if (pfd[0].revents & POLLNVAL || - pfd[1].revents & POLLNVAL) + r = ppoll_usec(pfd, ELEMENTSOF(pfd), USEC_INFINITY); + if (r == -EINTR) + continue; + if (r < 0) goto error; if (pfd[1].revents) { |