tree-wide: use ERRNO_IS_TRANSIENT()

This commit is contained in:
Yu Watanabe
2021-11-30 23:06:43 +09:00
parent 7aad83580f
commit 8add30a03c
26 changed files with 96 additions and 83 deletions
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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");
+15 -15
View File
@@ -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");
+1 -1
View File
@@ -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");
+4 -3
View File
@@ -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.");
+4 -3
View File
@@ -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);
+1 -1
View File
@@ -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");
+8 -7
View File
@@ -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 &&
+1 -1
View File
@@ -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");
+5 -5
View File
@@ -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;
+5 -3
View File
@@ -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;
+1 -1
View File
@@ -1479,7 +1479,7 @@ 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(len, -EAGAIN, -EINTR, -ENETDOWN))
if (ERRNO_IS_TRANSIENT(len) || len == -ENETDOWN)
return 0;
return log_dhcp6_client_errno(client, len, "Could not receive message from UDP socket: %m");
+1 -1
View File
@@ -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");
+1 -1
View File
@@ -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");
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -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;
+6 -5
View File
@@ -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 */
+1 -1
View File
@@ -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;
+8 -7
View File
@@ -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);
+3 -3
View File
@@ -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);
+6 -3
View File
@@ -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));
+12 -10
View File
@@ -291,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;
}
@@ -522,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;
@@ -882,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))
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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");
+1 -1
View File
@@ -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");