1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-03 13:47:04 +03:00

resolved: handle -EINTR returned from fd_wait_for_event() better

We might get signals for various reasons (for example, somebody asking
us to reload caches via a signal), hence let's handle this gracefully.
This commit is contained in:
Lennart Poettering 2022-11-22 12:28:19 +01:00
parent 6985878533
commit 6d66a22168

View File

@ -868,11 +868,14 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
}
static int sendmsg_loop(int fd, struct msghdr *mh, int flags) {
usec_t end;
int r;
assert(fd >= 0);
assert(mh);
end = usec_add(now(CLOCK_MONOTONIC), SEND_TIMEOUT_USEC);
for (;;) {
if (sendmsg(fd, mh, flags) >= 0)
return 0;
@ -881,20 +884,26 @@ static int sendmsg_loop(int fd, struct msghdr *mh, int flags) {
if (errno != EAGAIN)
return -errno;
r = fd_wait_for_event(fd, POLLOUT, SEND_TIMEOUT_USEC);
if (r < 0)
r = fd_wait_for_event(fd, POLLOUT, LESS_BY(end, now(CLOCK_MONOTONIC)));
if (r < 0) {
if (ERRNO_IS_TRANSIENT(r))
continue;
return r;
}
if (r == 0)
return -ETIMEDOUT;
}
}
static int write_loop(int fd, void *message, size_t length) {
usec_t end;
int r;
assert(fd >= 0);
assert(message);
end = usec_add(now(CLOCK_MONOTONIC), SEND_TIMEOUT_USEC);
for (;;) {
if (write(fd, message, length) >= 0)
return 0;
@ -903,9 +912,12 @@ static int write_loop(int fd, void *message, size_t length) {
if (errno != EAGAIN)
return -errno;
r = fd_wait_for_event(fd, POLLOUT, SEND_TIMEOUT_USEC);
if (r < 0)
r = fd_wait_for_event(fd, POLLOUT, LESS_BY(end, now(CLOCK_MONOTONIC)));
if (r < 0) {
if (ERRNO_IS_TRANSIENT(r))
continue;
return r;
}
if (r == 0)
return -ETIMEDOUT;
}