Merge pull request #21564 from yuwata/errno-eagain-eintr

tree-wide: introduce ERRNO_IS_TRANSIENT() and use it
This commit is contained in:
Yu Watanabe
2021-12-01 12:52:27 +09:00
committed by GitHub
30 changed files with 129 additions and 108 deletions
+21 -18
View File
@@ -153,15 +153,16 @@ static int ask_password_keyring(const char *keyname, AskPasswordFlags flags, cha
return -EUNATCH;
r = lookup_key(keyname, &serial);
if (ERRNO_IS_NOT_SUPPORTED(r) || r == -EPERM) /* when retrieving the distinction between "kernel or
* container manager don't support or allow this" and
* "no matching key known" doesn't matter. Note that we
* propagate EACCESS here (even if EPERM not) since
* that is used if the keyring is available but we lack
* access to the key. */
return -ENOKEY;
if (r < 0)
if (r < 0) {
/* when retrieving the distinction between "kernel or container manager don't support
* or allow this" and "no matching key known" doesn't matter. Note that we propagate
* EACCESS here (even if EPERM not) since that is used if the keyring is available but
* we lack access to the key. */
if (ERRNO_IS_NOT_SUPPORTED(r) || r == -EPERM)
return -ENOKEY;
return r;
}
return retrieve_key(serial, ret);
}
@@ -290,12 +291,13 @@ int ask_password_plymouth(
k = read(fd, buffer + p, sizeof(buffer) - p);
if (k < 0) {
if (IN_SET(errno, EINTR, EAGAIN))
if (ERRNO_IS_TRANSIENT(errno))
continue;
r = -errno;
goto finish;
} else if (k == 0) {
}
if (k == 0) {
r = -EIO;
goto finish;
}
@@ -521,7 +523,7 @@ int ask_password_tty(
n = read(ttyfd >= 0 ? ttyfd : STDIN_FILENO, &c, 1);
if (n < 0) {
if (IN_SET(errno, EINTR, EAGAIN))
if (ERRNO_IS_TRANSIENT(errno))
continue;
r = -errno;
@@ -881,20 +883,21 @@ int ask_password_agent(
};
n = recvmsg_safe(socket_fd, &msghdr, 0);
if (IN_SET(n, -EAGAIN, -EINTR))
continue;
if (n == -EXFULL) {
log_debug("Got message with truncated control data, ignoring.");
continue;
}
if (n < 0) {
if (ERRNO_IS_TRANSIENT(n))
continue;
if (n == -EXFULL) {
log_debug("Got message with truncated control data, ignoring.");
continue;
}
r = (int) n;
goto finish;
}
cmsg_close_all(&msghdr);
if (n <= 0) {
if (n == 0) {
log_debug("Message too short");
continue;
}
+3 -2
View File
@@ -10,6 +10,7 @@
#include <unistd.h>
#include "barrier.h"
#include "errno-util.h"
#include "fd-util.h"
#include "io-util.h"
#include "macro.h"
@@ -178,7 +179,7 @@ static bool barrier_write(Barrier *b, uint64_t buf) {
assert(b->me >= 0);
do {
len = write(b->me, &buf, sizeof(buf));
} while (len < 0 && IN_SET(errno, EAGAIN, EINTR));
} while (len < 0 && ERRNO_IS_TRANSIENT(errno));
if (len != sizeof(buf))
goto error;
@@ -230,7 +231,7 @@ static bool barrier_read(Barrier *b, int64_t comp) {
/* events on @them signal new data for us */
len = read(b->them, &buf, sizeof(buf));
if (len < 0 && IN_SET(errno, EAGAIN, EINTR))
if (len < 0 && ERRNO_IS_TRANSIENT(errno))
continue;
if (len != sizeof(buf))