Merge pull request #21564 from yuwata/errno-eagain-eintr
tree-wide: introduce ERRNO_IS_TRANSIENT() and use it
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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
@@ -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
@@ -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
@@ -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");
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+8
-7
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user