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