ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
ac3a84
From e95dd8e99188377bb6351fc0a4ceb4e790612044 Mon Sep 17 00:00:00 2001
ac3a84
From: Lennart Poettering <lennart@poettering.net>
ac3a84
Date: Tue, 22 Nov 2022 12:42:46 +0100
ac3a84
Subject: [PATCH] varlink: also handle EINTR gracefully when waiting for EIO
ac3a84
 via ppoll()
ac3a84
ac3a84
(cherry picked from commit 6976bf5cd614761eb4bd57d39e24f7eca1d6b863)
ac3a84
ac3a84
Related: #2137584
ac3a84
---
ac3a84
 src/shared/varlink.c | 11 +++++++++--
ac3a84
 1 file changed, 9 insertions(+), 2 deletions(-)
ac3a84
ac3a84
diff --git a/src/shared/varlink.c b/src/shared/varlink.c
ac3a84
index 4f7ac97689..4d2cfee491 100644
ac3a84
--- a/src/shared/varlink.c
ac3a84
+++ b/src/shared/varlink.c
ac3a84
@@ -1025,7 +1025,7 @@ static void handle_revents(Varlink *v, int revents) {
ac3a84
                 if ((revents & (POLLOUT|POLLHUP)) == 0)
ac3a84
                         return;
ac3a84
 
ac3a84
-                varlink_log(v, "Anynchronous connection completed.");
ac3a84
+                varlink_log(v, "Asynchronous connection completed.");
ac3a84
                 v->connecting = false;
ac3a84
         } else {
ac3a84
                 /* Note that we don't care much about POLLIN/POLLOUT here, we'll just try reading and writing
ac3a84
@@ -1075,6 +1075,9 @@ int varlink_wait(Varlink *v, usec_t timeout) {
ac3a84
                 return events;
ac3a84
 
ac3a84
         r = fd_wait_for_event(fd, events, t);
ac3a84
+        if (r < 0 && ERRNO_IS_TRANSIENT(r)) /* Treat EINTR as not a timeout, but also nothing happened, and
ac3a84
+                                             * the caller gets a chance to call back into us */
ac3a84
+                return 1;
ac3a84
         if (r <= 0)
ac3a84
                 return r;
ac3a84
 
ac3a84
@@ -1161,8 +1164,12 @@ int varlink_flush(Varlink *v) {
ac3a84
                 }
ac3a84
 
ac3a84
                 r = fd_wait_for_event(v->fd, POLLOUT, USEC_INFINITY);
ac3a84
-                if (r < 0)
ac3a84
+                if (r < 0) {
ac3a84
+                        if (ERRNO_IS_TRANSIENT(r))
ac3a84
+                                continue;
ac3a84
+
ac3a84
                         return varlink_log_errno(v, r, "Poll failed on fd: %m");
ac3a84
+                }
ac3a84
 
ac3a84
                 assert(r != 0);
ac3a84