From b3d06b9226db96fddb6bb45a4708e2e8d413d91d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 30 Nov 2021 03:33:55 +0900 Subject: [PATCH] libsystemd: ignore both EINTR and EAGAIN --- src/libsystemd/sd-bus/bus-socket.c | 20 +++++++++++--------- src/libsystemd/sd-device/device-monitor.c | 2 +- src/libsystemd/sd-resolve/sd-resolve.c | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index bce123ae1c6..14951ccb330 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -149,7 +149,7 @@ static int bus_socket_write_auth(sd_bus *b) { } if (k < 0) - return errno == EAGAIN ? 0 : -errno; + return ERRNO_IS_TRANSIENT(errno) ? 0 : -errno; iovec_advance(b->auth_iovec, &b->auth_index, (size_t) k); return 1; @@ -301,7 +301,7 @@ static int verify_external_token(sd_bus *b, const char *p, size_t l) { uid_t u; int r; - /* We don't do any real authentication here. Instead, if + /* We don't do any real authentication here. Instead, if * the owner of this bus wanted authentication they should have * checked SO_PEERCRED before even creating the bus object. */ @@ -565,10 +565,11 @@ static int bus_socket_read_auth(sd_bus *b) { } else handle_cmsg = true; } - if (k == -EAGAIN) - return 0; - if (k < 0) + if (k < 0) { + if (ERRNO_IS_TRANSIENT(k)) + return 0; return (int) k; + } if (k == 0) { if (handle_cmsg) cmsg_close_all(&mh); /* paranoia, we shouldn't have gotten any fds on EOF */ @@ -1073,7 +1074,7 @@ int bus_socket_write_message(sd_bus *bus, sd_bus_message *m, size_t *idx) { } if (k < 0) - return errno == EAGAIN ? 0 : -errno; + return ERRNO_IS_TRANSIENT(errno) ? 0 : -errno; *idx += (size_t) k; return 1; @@ -1230,10 +1231,11 @@ int bus_socket_read_message(sd_bus *bus) { } else handle_cmsg = true; } - if (k == -EAGAIN) - return 0; - if (k < 0) + if (k < 0) { + if (ERRNO_IS_TRANSIENT(k)) + return 0; return (int) k; + } if (k == 0) { if (handle_cmsg) cmsg_close_all(&mh); /* On EOF we shouldn't have gotten an fd, but let's make sure */ diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index a446c27583e..524d10b9d80 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -445,7 +445,7 @@ int device_monitor_receive_device(sd_device_monitor *m, sd_device **ret) { buflen = recvmsg(m->sock, &smsg, 0); if (buflen < 0) { - if (errno != EINTR) + if (ERRNO_IS_TRANSIENT(errno)) log_debug_errno(errno, "sd-device-monitor: Failed to receive message: %m"); return -errno; } diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c index ad637bcf1db..fdc09ff20f7 100644 --- a/src/libsystemd/sd-resolve/sd-resolve.c +++ b/src/libsystemd/sd-resolve/sd-resolve.c @@ -418,7 +418,7 @@ static void* thread_worker(void *p) { length = recv(resolve->fds[REQUEST_RECV_FD], &buf, sizeof buf, 0); if (length < 0) { - if (errno == EINTR) + if (ERRNO_IS_TRANSIENT(errno)) continue; break; @@ -847,7 +847,7 @@ _public_ int sd_resolve_process(sd_resolve *resolve) { l = recv(resolve->fds[RESPONSE_RECV_FD], &buf, sizeof buf, 0); if (l < 0) { - if (errno == EAGAIN) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return -errno; -- 2.47.3