ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
bd1529
From 6a50c735a3bbf98d06fbfa7815f7bdc14ea96f9f Mon Sep 17 00:00:00 2001
bd1529
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
bd1529
Date: Wed, 14 Oct 2020 14:03:13 +0200
bd1529
Subject: [PATCH] sd-bus: break the loop in bus_ensure_running() if the bus is
bd1529
 not connecting
bd1529
bd1529
This might fix #17025:
bd1529
> the call trace is
bd1529
> bus_ensure_running -> sd_bus_process -> bus_process_internal -> process_closeing --> sd_bus_close
bd1529
>                                                                                  |
bd1529
>                                                                                  \-> process_match
bd1529
bd1529
We ended doing callouts to the Disconnected matches from bus_ensure_running()
bd1529
and shouldn't. bus_ensure_running() should never do callouts. This change
bd1529
should fix this however: once we notice that the connection is going down we
bd1529
will now fail instantly with ENOTOCONN instead of calling any callbacks.
bd1529
bd1529
(cherry picked from commit 93a59b1ae5d3bcb0ec1488ebc13d0d1ff4d1729a)
bd1529
bd1529
Resolves: #1885553
bd1529
---
bd1529
 src/libsystemd/sd-bus/sd-bus.c | 5 +++--
bd1529
 1 file changed, 3 insertions(+), 2 deletions(-)
bd1529
bd1529
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
bd1529
index a3509f7e89..c65e24b2d1 100644
bd1529
--- a/src/libsystemd/sd-bus/sd-bus.c
bd1529
+++ b/src/libsystemd/sd-bus/sd-bus.c
bd1529
@@ -2059,12 +2059,13 @@ int bus_ensure_running(sd_bus *bus) {
bd1529
 
bd1529
         assert(bus);
bd1529
 
bd1529
-        if (IN_SET(bus->state, BUS_UNSET, BUS_CLOSED, BUS_CLOSING))
bd1529
-                return -ENOTCONN;
bd1529
         if (bus->state == BUS_RUNNING)
bd1529
                 return 1;
bd1529
 
bd1529
         for (;;) {
bd1529
+                if (IN_SET(bus->state, BUS_UNSET, BUS_CLOSED, BUS_CLOSING))
bd1529
+                        return -ENOTCONN;
bd1529
+
bd1529
                 r = sd_bus_process(bus, NULL);
bd1529
                 if (r < 0)
bd1529
                         return r;