ac3a84
From cd822ff6ef904e3e25060e77556670784b0b1aea Mon Sep 17 00:00:00 2001
ac3a84
From: Lennart Poettering <lennart@poettering.net>
ac3a84
Date: Tue, 22 Nov 2022 13:00:48 +0100
ac3a84
Subject: [PATCH] sd-netlink: handle EINTR from poll() gracefully, as success
ac3a84
ac3a84
(cherry picked from commit 69858785335afffc51bc03127beb53332c0fb983)
ac3a84
ac3a84
Related: #2137584
ac3a84
---
ac3a84
 src/libsystemd/sd-netlink/sd-netlink.c | 7 ++++++-
ac3a84
 1 file changed, 6 insertions(+), 1 deletion(-)
ac3a84
ac3a84
diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c
ac3a84
index feb751a848..b99abae640 100644
ac3a84
--- a/src/libsystemd/sd-netlink/sd-netlink.c
ac3a84
+++ b/src/libsystemd/sd-netlink/sd-netlink.c
ac3a84
@@ -464,13 +464,18 @@ static int netlink_poll(sd_netlink *nl, bool need_more, usec_t timeout_usec) {
ac3a84
 }
ac3a84
 
ac3a84
 int sd_netlink_wait(sd_netlink *nl, uint64_t timeout_usec) {
ac3a84
+        int r;
ac3a84
+
ac3a84
         assert_return(nl, -EINVAL);
ac3a84
         assert_return(!netlink_pid_changed(nl), -ECHILD);
ac3a84
 
ac3a84
         if (nl->rqueue_size > 0)
ac3a84
                 return 0;
ac3a84
 
ac3a84
-        return netlink_poll(nl, false, timeout_usec);
ac3a84
+        r = netlink_poll(nl, false, timeout_usec);
ac3a84
+        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 */
ac3a84
+                return 1;
ac3a84
+        return r;
ac3a84
 }
ac3a84
 
ac3a84
 static int timeout_compare(const void *a, const void *b) {