diff --git a/src/basic/errno-util.h b/src/basic/errno-util.h index 8cd7de5bc8..09abf0b751 100644 --- a/src/basic/errno-util.h +++ b/src/basic/errno-util.h @@ -70,6 +70,13 @@ static inline int errno_or_else(int fallback) { return -abs(fallback); } +/* For send()/recv() or read()/write(). */ +static inline bool ERRNO_IS_TRANSIENT(int r) { + return IN_SET(abs(r), + EAGAIN, + EINTR); +} + /* Hint #1: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5. * * Hint #2: The kernel sends e.g., EHOSTUNREACH or ENONET to userspace in some ICMP error cases. See the @@ -100,10 +107,8 @@ static inline bool ERRNO_IS_DISCONNECT(int r) { * the accept(2) man page. */ static inline bool ERRNO_IS_ACCEPT_AGAIN(int r) { return ERRNO_IS_DISCONNECT(r) || - IN_SET(abs(r), - EAGAIN, - EINTR, - EOPNOTSUPP); + ERRNO_IS_TRANSIENT(r) || + abs(r) == EOPNOTSUPP; } /* Resource exhaustion, could be our fault or general system trouble */ diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 8ef354ee9a..79bb33df84 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -453,7 +453,7 @@ int acquire_terminal( l = read(notify, &buffer, sizeof(buffer)); if (l < 0) { - if (IN_SET(errno, EINTR, EAGAIN)) + if (ERRNO_IS_TRANSIENT(errno)) continue; return -errno; diff --git a/src/core/cgroup.c b/src/core/cgroup.c index c942db8d05..396de12c4f 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -3191,7 +3191,7 @@ static int on_cgroup_inotify_event(sd_event_source *s, int fd, uint32_t revents, l = read(fd, &buffer, sizeof(buffer)); if (l < 0) { - if (IN_SET(errno, EINTR, EAGAIN)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return log_error_errno(errno, "Failed to read control group inotify events: %m"); diff --git a/src/core/manager.c b/src/core/manager.c index c94f032cc0..780b153913 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2445,18 +2445,19 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t } n = recvmsg_safe(m->notify_fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC|MSG_TRUNC); - if (IN_SET(n, -EAGAIN, -EINTR)) - return 0; /* Spurious wakeup, try again */ - if (n == -EXFULL) { - log_warning("Got message with truncated control data (too many fds sent?), ignoring."); - return 0; - } - if (n < 0) + if (n < 0) { + if (ERRNO_IS_TRANSIENT(n)) + return 0; /* Spurious wakeup, try again */ + if (n == -EXFULL) { + log_warning("Got message with truncated control data (too many fds sent?), ignoring."); + return 0; + } /* If this is any other, real error, then let's stop processing this socket. This of course * means we won't take notification messages anymore, but that's still better than busy * looping around this: being woken up over and over again but being unable to actually read * the message off the socket. */ return log_error_errno(n, "Failed to receive notification message: %m"); + } CMSG_FOREACH(cmsg, &msghdr) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { @@ -2716,19 +2717,18 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t } n = read(m->signal_fd, &sfsi, sizeof(sfsi)); - if (n != sizeof(sfsi)) { - if (n >= 0) { - log_warning("Truncated read from signal fd (%zu bytes), ignoring!", n); - return 0; - } - - if (IN_SET(errno, EINTR, EAGAIN)) + if (n < 0) { + if (ERRNO_IS_TRANSIENT(errno)) return 0; /* We return an error here, which will kill this handler, * to avoid a busy loop on read error. */ return log_error_errno(errno, "Reading from signal fd failed: %m"); } + if (n != sizeof(sfsi)) { + log_warning("Truncated read from signal fd (%zu bytes), ignoring!", n); + return 0; + } log_received_signal(sfsi.ssi_signo == SIGCHLD || (sfsi.ssi_signo == SIGTERM && MANAGER_IS_USER(m)) @@ -4263,7 +4263,7 @@ int manager_dispatch_user_lookup_fd(sd_event_source *source, int fd, uint32_t re l = recv(fd, &buffer, sizeof(buffer), MSG_DONTWAIT); if (l < 0) { - if (IN_SET(errno, EINTR, EAGAIN)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return log_error_errno(errno, "Failed to read from user lookup fd: %m"); diff --git a/src/core/path.c b/src/core/path.c index 999cecc96c..29ec66fd4d 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -184,7 +184,7 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) { l = read(s->inotify_fd, &buffer, sizeof(buffer)); if (l < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return log_error_errno(errno, "Failed to read inotify event: %m"); diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 65d7d98dbc..d49fcedb57 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1122,10 +1122,11 @@ static int on_notify_socket(sd_event_source *s, int fd, uint32_t revents, void * assert(m); n = read_datagram(fd, &sender, &datagram, &passed_fd); - if (IN_SET(n, -EAGAIN, -EINTR)) - return 0; - if (n < 0) + if (n < 0) { + if (ERRNO_IS_TRANSIENT(n)) + return 0; return log_error_errno(n, "Failed to read notify datagram: %m"); + } if (sender.pid <= 0) { log_warning("Received notify datagram without valid sender PID, ignoring."); diff --git a/src/import/importd.c b/src/import/importd.c index 66771f63e2..125b2dc808 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -567,10 +567,11 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void int r; n = recvmsg_safe(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); - if (IN_SET(n, -EAGAIN, -EINTR)) - return 0; - if (n < 0) + if (n < 0) { + if (ERRNO_IS_TRANSIENT(n)) + return 0; return (int) n; + } cmsg_close_all(&msghdr); diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index a9b745772b..1b79e9366c 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -326,7 +326,7 @@ static int server_read_dev_kmsg(Server *s) { return 0; } - if (IN_SET(errno, EAGAIN, EINTR, EPIPE)) + if (ERRNO_IS_TRANSIENT(errno) || errno == EPIPE) return 0; return log_error_errno(errno, "Failed to read from /dev/kmsg: %m"); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 8e2990190b..5ba9b3765b 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -1317,14 +1317,15 @@ int server_process_datagram( iovec = IOVEC_MAKE(s->buffer, MALLOC_ELEMENTSOF(s->buffer) - 1); /* Leave room for trailing NUL we add later */ n = recvmsg_safe(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); - if (IN_SET(n, -EINTR, -EAGAIN)) - return 0; - if (n == -EXFULL) { - log_warning("Got message with truncated control data (too many fds sent?), ignoring."); - return 0; - } - if (n < 0) + if (n < 0) { + if (ERRNO_IS_TRANSIENT(n)) + return 0; + if (n == -EXFULL) { + log_warning("Got message with truncated control data (too many fds sent?), ignoring."); + return 0; + } return log_error_errno(n, "recvmsg() failed: %m"); + } CMSG_FOREACH(cmsg, &msghdr) if (cmsg->cmsg_level == SOL_SOCKET && diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 26909840da..d94b1df02d 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -588,7 +588,7 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents, l = recvmsg(s->fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); if (l < 0) { - if (IN_SET(errno, EINTR, EAGAIN)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; log_warning_errno(errno, "Failed to read from stream: %m"); diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 45c2351c53..14cbde133f 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -1945,7 +1945,7 @@ static int client_receive_message_udp( len = recv(fd, message, buflen, 0); if (len < 0) { /* see comment above for why we shouldn't error out on ENETDOWN. */ - if (IN_SET(errno, EAGAIN, EINTR, ENETDOWN)) + if (ERRNO_IS_TRANSIENT(errno) || errno == ENETDOWN) return 0; return log_dhcp_client_errno(client, errno, @@ -2035,12 +2035,12 @@ static int client_receive_message_raw( iov = IOVEC_MAKE(packet, buflen); len = recvmsg_safe(fd, &msg, 0); - if (IN_SET(len, -EAGAIN, -EINTR, -ENETDOWN)) - return 0; - if (len < 0) + if (len < 0) { + if (ERRNO_IS_TRANSIENT(len) || len == -ENETDOWN) + return 0; return log_dhcp_client_errno(client, len, "Could not receive message from raw socket: %m"); - + } if ((size_t) len < sizeof(DHCPPacket)) return 0; diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 261818b46a..f535e316f9 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -1206,10 +1206,12 @@ static int server_receive_message(sd_event_source *s, int fd, iov = IOVEC_MAKE(message, datagram_size); len = recvmsg_safe(fd, &msg, 0); - if (IN_SET(len, -EAGAIN, -EINTR)) - return 0; - if (len < 0) + if (len < 0) { + if (ERRNO_IS_TRANSIENT(len)) + return 0; return len; + } + if ((size_t) len < sizeof(DHCPMessage)) return 0; diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 4035a1c784..29c8f78a8f 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -1479,10 +1479,10 @@ static int client_receive_message( len = recvmsg_safe(fd, &msg, MSG_DONTWAIT); if (len < 0) { /* see comment above for why we shouldn't error out on ENETDOWN. */ - if (IN_SET(errno, EAGAIN, EINTR, ENETDOWN)) + if (ERRNO_IS_TRANSIENT(len) || len == -ENETDOWN) return 0; - return log_dhcp6_client_errno(client, errno, "Could not receive message from UDP socket: %m"); + return log_dhcp6_client_errno(client, len, "Could not receive message from UDP socket: %m"); } if ((size_t) len < sizeof(DHCP6Message)) { diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c index 0a975fbbad..9b35d2c48e 100644 --- a/src/libsystemd-network/sd-ipv4acd.c +++ b/src/libsystemd-network/sd-ipv4acd.c @@ -362,7 +362,7 @@ static int ipv4acd_on_packet( n = recv(fd, &packet, sizeof(struct ether_arp), 0); if (n < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; log_ipv4acd_errno(acd, errno, "Failed to read ARP packet: %m"); diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 761e4b3128..4caed52a98 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -212,7 +212,7 @@ static int lldp_rx_receive_datagram(sd_event_source *s, int fd, uint32_t revents length = recv(fd, LLDP_NEIGHBOR_RAW(n), n->raw_size, MSG_DONTWAIT); if (length < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; log_lldp_rx_errno(lldp_rx, errno, "Failed to read LLDP datagram, ignoring: %m"); diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index bce123ae1c..14951ccb33 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 a446c27583..524d10b9d8 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-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 3c916f2466..dd257eadfe 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -3142,7 +3142,7 @@ static int flush_timer(sd_event *e, int fd, uint32_t events, usec_t *next) { ss = read(fd, &x, sizeof(x)); if (ss < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return -errno; @@ -3348,7 +3348,7 @@ static int process_signal(sd_event *e, struct signal_data *d, uint32_t events, i n = read(d->fd, &si, sizeof(si)); if (n < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return -errno; @@ -3402,7 +3402,7 @@ static int event_inotify_data_read(sd_event *e, struct inotify_data *d, uint32_t n = read(d->fd, &d->buffer, sizeof(d->buffer)); if (n < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return -errno; diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 738c697468..4861726673 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -2698,7 +2698,7 @@ _public_ int sd_journal_process(sd_journal *j) { l = read(j->inotify_fd, &buffer, sizeof(buffer)); if (l < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return got_something ? determine_change(j) : SD_JOURNAL_NOP; return -errno; diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 888b5bcf35..7197cb4daa 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -235,12 +235,13 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *ret_mcast_gr assert(iov); n = recvmsg_safe(fd, &msg, MSG_TRUNC | (peek ? MSG_PEEK : 0)); - if (n == -ENOBUFS) - return log_debug_errno(n, "sd-netlink: kernel receive buffer overrun"); - if (IN_SET(n, -EAGAIN, -EINTR)) - return 0; - if (n < 0) + if (n < 0) { + if (n == -ENOBUFS) + return log_debug_errno(n, "sd-netlink: kernel receive buffer overrun"); + if (ERRNO_IS_TRANSIENT(n)) + return 0; return (int) n; + } if (sender.nl.nl_pid != 0) { /* not from the kernel, ignore */ diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index dc48e91837..1f32a1eb46 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -462,7 +462,7 @@ _public_ int sd_network_monitor_flush(sd_network_monitor *m) { l = read(fd, &buffer, sizeof(buffer)); if (l < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return -errno; diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c index ad637bcf1d..fdc09ff20f 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; diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 4765882836..8f17ab8810 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -4211,14 +4211,15 @@ static int nspawn_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t r } n = recvmsg_safe(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); - if (IN_SET(n, -EAGAIN, -EINTR)) - return 0; - if (n == -EXFULL) { - log_warning("Got message with truncated control data (too many fds sent?), ignoring."); - return 0; - } - if (n < 0) + if (n < 0) { + if (ERRNO_IS_TRANSIENT(n)) + return 0; + if (n == -EXFULL) { + log_warning("Got message with truncated control data (too many fds sent?), ignoring."); + return 0; + } return log_warning_errno(n, "Couldn't read notification socket: %m"); + } cmsg_close_all(&msghdr); diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index 719f6219bf..f48e2a8029 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -323,7 +323,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use ssize_t ss = dns_stream_writev(s, iov, ELEMENTSOF(iov), 0); if (ss < 0) { - if (!IN_SET(-ss, EINTR, EAGAIN)) + if (!ERRNO_IS_TRANSIENT(ss)) return dns_stream_complete(s, -ss); } else { progressed = true; @@ -347,7 +347,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use ss = dns_stream_read(s, (uint8_t*) &s->read_size + s->n_read, sizeof(s->read_size) - s->n_read); if (ss < 0) { - if (!IN_SET(-ss, EINTR, EAGAIN)) + if (!ERRNO_IS_TRANSIENT(ss)) return dns_stream_complete(s, -ss); } else if (ss == 0) return dns_stream_complete(s, ECONNRESET); @@ -400,7 +400,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use (uint8_t*) DNS_PACKET_DATA(s->read_packet) + s->n_read - sizeof(s->read_size), sizeof(s->read_size) + be16toh(s->read_size) - s->n_read); if (ss < 0) { - if (!IN_SET(-ss, EINTR, EAGAIN)) + if (!ERRNO_IS_TRANSIENT(ss)) return dns_stream_complete(s, -ss); } else if (ss == 0) return dns_stream_complete(s, ECONNRESET); diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 431093ad01..6b32ee4cf0 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -792,10 +792,13 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) { iov = IOVEC_MAKE(DNS_PACKET_DATA(p), p->allocated); l = recvmsg_safe(fd, &mh, 0); - if (IN_SET(l, -EAGAIN, -EINTR)) - return 0; - if (l <= 0) + if (l < 0) { + if (ERRNO_IS_TRANSIENT(l)) + return 0; return l; + } + if (l == 0) + return 0; assert(!(mh.msg_flags & MSG_TRUNC)); diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 07e301276f..17474fe0be 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -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; } diff --git a/src/shared/barrier.c b/src/shared/barrier.c index 87061f55d7..cbe54a60cd 100644 --- a/src/shared/barrier.c +++ b/src/shared/barrier.c @@ -10,6 +10,7 @@ #include #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)) diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index aba483449a..7e9ab19666 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -190,7 +190,7 @@ static int connection_shovel( } else if (z == 0 || ERRNO_IS_DISCONNECT(errno)) { *from_source = sd_event_source_unref(*from_source); *from = safe_close(*from); - } else if (!IN_SET(errno, EAGAIN, EINTR)) + } else if (!ERRNO_IS_TRANSIENT(errno)) return log_error_errno(errno, "Failed to splice: %m"); } @@ -202,7 +202,7 @@ static int connection_shovel( } else if (z == 0 || ERRNO_IS_DISCONNECT(errno)) { *to_source = sd_event_source_unref(*to_source); *to = safe_close(*to); - } else if (!IN_SET(errno, EAGAIN, EINTR)) + } else if (!ERRNO_IS_TRANSIENT(errno)) return log_error_errno(errno, "Failed to splice: %m"); } } while (shoveled); diff --git a/src/timesync/wait-sync.c b/src/timesync/wait-sync.c index 606b0160a4..f42e6496bb 100644 --- a/src/timesync/wait-sync.c +++ b/src/timesync/wait-sync.c @@ -85,7 +85,7 @@ static int inotify_handler(sd_event_source *s, l = read(fd, &buffer, sizeof(buffer)); if (l < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return log_warning_errno(errno, "Lost access to inotify: %m"); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index d37652db67..8380d674c5 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1349,7 +1349,7 @@ static int on_inotify(sd_event_source *s, int fd, uint32_t revents, void *userda l = read(fd, &buffer, sizeof(buffer)); if (l < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 1; return log_error_errno(errno, "Failed to read inotify fd: %m");