tree-wide: use ppoll_usec()
This commit is contained in:
@@ -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)
|
||||
timeout = usec_sub_unsigned(until, now(CLOCK_MONOTONIC));
|
||||
else
|
||||
timeout = USEC_INFINITY;
|
||||
|
||||
if (until > 0 && until <= t) {
|
||||
r = ppoll_usec(pollfd, notify >= 0 ? _FD_MAX : _FD_MAX - 1, timeout);
|
||||
if (r == -EINTR)
|
||||
continue;
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
if (r == 0) {
|
||||
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;
|
||||
|
||||
r = -errno;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (k <= 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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user