Merge pull request #25483 from poettering/ppoll-usec-eintr

ppoll() + EINTR fixes
This commit is contained in:
Yu Watanabe
2022-11-24 09:42:48 +09:00
committed by GitHub
11 changed files with 101 additions and 39 deletions
+4 -1
View File
@@ -1308,8 +1308,11 @@ int bus_socket_process_opening(sd_bus *b) {
assert(b->state == BUS_OPENING);
events = fd_wait_for_event(b->output_fd, POLLOUT, 0);
if (events < 0)
if (events < 0) {
if (ERRNO_IS_TRANSIENT(events))
return 0;
return events;
}
if (!(events & (POLLOUT|POLLERR|POLLHUP)))
return 0;
+15 -3
View File
@@ -2465,8 +2465,11 @@ _public_ int sd_bus_call(
left = UINT64_MAX;
r = bus_poll(bus, true, left);
if (r < 0)
if (r < 0) {
if (ERRNO_IS_TRANSIENT(r))
continue;
goto fail;
}
if (r == 0) {
r = -ETIMEDOUT;
goto fail;
@@ -3321,6 +3324,7 @@ static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec) {
}
_public_ int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec) {
int r;
assert_return(bus, -EINVAL);
assert_return(bus = bus_resolve(bus), -ENOPKG);
@@ -3335,7 +3339,11 @@ _public_ int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec) {
if (bus->rqueue_size > 0)
return 0;
return bus_poll(bus, false, timeout_usec);
r = bus_poll(bus, false, timeout_usec);
if (r < 0 && ERRNO_IS_TRANSIENT(r))
return 1; /* treat EINTR as success, but let's exit, so that the caller will call back into us soon. */
return r;
}
_public_ int sd_bus_flush(sd_bus *bus) {
@@ -3377,8 +3385,12 @@ _public_ int sd_bus_flush(sd_bus *bus) {
return 0;
r = bus_poll(bus, false, UINT64_MAX);
if (r < 0)
if (r < 0) {
if (ERRNO_IS_TRANSIENT(r))
continue;
return r;
}
}
}
+6 -1
View File
@@ -464,13 +464,18 @@ static int netlink_poll(sd_netlink *nl, bool need_more, usec_t timeout_usec) {
}
int sd_netlink_wait(sd_netlink *nl, uint64_t timeout_usec) {
int r;
assert_return(nl, -EINVAL);
assert_return(!netlink_pid_changed(nl), -ECHILD);
if (nl->rqueue_size > 0)
return 0;
return netlink_poll(nl, false, timeout_usec);
r = netlink_poll(nl, false, timeout_usec);
if (r < 0 && ERRNO_IS_TRANSIENT(r)) /* Convert EINTR to "something happened" and give user a chance to run some code before calling back into us */
return 1;
return r;
}
static int timeout_compare(const void *a, const void *b) {