Blame SOURCES/0605-dbus-propagate-errors-from-bus_init_system-and-bus_i.patch

17b0f1
From ac8fd4f713c1861e8a62fd811b2e79acbee5db31 Mon Sep 17 00:00:00 2001
17b0f1
From: Michal Sekletar <msekleta@redhat.com>
17b0f1
Date: Wed, 10 Jan 2018 17:22:12 +0100
17b0f1
Subject: [PATCH] dbus: propagate errors from bus_init_system() and
17b0f1
 bus_init_api()
17b0f1
17b0f1
The aim of this change is to make sure that we properly log about all
17b0f1
D-Bus connection problems. After all, we only ever attempt to get on the
17b0f1
bus if dbus-daemon is around, so any failure in the process should be
17b0f1
treated as an error.
17b0f1
17b0f1
bus_init_system() is only called from bus_init() and in
17b0f1
bus_init() we have a bool flag which governs whether we should attempt
17b0f1
to connect to the system bus or not.
17b0f1
Hence if we are in bus_init_system() then it is clear we got called from
17b0f1
a context where connection to the bus is actually required and therefore
17b0f1
shouldn't be treated as the "best effort" type of operation. Same
17b0f1
applies to bus_init_api().
17b0f1
17b0f1
We make use of those error codes in bus_init() and log high level
17b0f1
message that informs admin about what is going on (and is easy to spot
17b0f1
and makes sense to an end user).
17b0f1
17b0f1
Also "retrying later" bit is actually a lie. We won't retry unless we
17b0f1
are explicitly told to reconnect via SIGUSR1 or re-executed. This is
17b0f1
because bus_init() is always called from the context where dbus-daemon
17b0f1
is already around and hence bus_init() won't be called again from
17b0f1
unit_notify().
17b0f1
17b0f1
Fixes #7782
17b0f1
17b0f1
(cherry picked from commit dc7118ba094415d8de3812881cc5cbe2e3cac73e)
17b0f1
17b0f1
Resolves: #1541061
17b0f1
---
17b0f1
 src/core/dbus.c | 46 +++++++++++++++++-----------------------------
17b0f1
 1 file changed, 17 insertions(+), 29 deletions(-)
17b0f1
17b0f1
diff --git a/src/core/dbus.c b/src/core/dbus.c
17b0f1
index 0061211faa..d551eab016 100644
17b0f1
--- a/src/core/dbus.c
17b0f1
+++ b/src/core/dbus.c
17b0f1
@@ -811,27 +811,21 @@ static int bus_init_api(Manager *m) {
17b0f1
                 else
17b0f1
                         r = sd_bus_open_user(&bus;;
17b0f1
 
17b0f1
-                if (r < 0) {
17b0f1
-                        log_debug("Failed to connect to API bus, retrying later...");
17b0f1
-                        return 0;
17b0f1
-                }
17b0f1
+                if (r < 0)
17b0f1
+                        return log_error_errno(r, "Failed to connect to API bus: %m");
17b0f1
 
17b0f1
                 r = sd_bus_attach_event(bus, m->event, SD_EVENT_PRIORITY_NORMAL);
17b0f1
-                if (r < 0) {
17b0f1
-                        log_error_errno(r, "Failed to attach API bus to event loop: %m");
17b0f1
-                        return 0;
17b0f1
-                }
17b0f1
+                if (r < 0)
17b0f1
+                        return log_error_errno(r, "Failed to attach API bus to event loop: %m");
17b0f1
 
17b0f1
                 r = bus_setup_disconnected_match(m, bus);
17b0f1
                 if (r < 0)
17b0f1
-                        return 0;
17b0f1
+                        return r;
17b0f1
         }
17b0f1
 
17b0f1
         r = bus_setup_api(m, bus);
17b0f1
-        if (r < 0) {
17b0f1
-                log_error_errno(r, "Failed to set up API bus: %m");
17b0f1
-                return 0;
17b0f1
-        }
17b0f1
+        if (r < 0)
17b0f1
+                return log_error_errno(r, "Failed to set up API bus: %m");
17b0f1
 
17b0f1
         m->api_bus = bus;
17b0f1
         bus = NULL;
17b0f1
@@ -880,26 +874,20 @@ static int bus_init_system(Manager *m) {
17b0f1
         }
17b0f1
 
17b0f1
         r = sd_bus_open_system(&bus;;
17b0f1
-        if (r < 0) {
17b0f1
-                log_debug("Failed to connect to system bus, retrying later...");
17b0f1
-                return 0;
17b0f1
-        }
17b0f1
+        if (r < 0)
17b0f1
+                return log_error_errno(r, "Failed to connect to system bus: %m");
17b0f1
 
17b0f1
         r = bus_setup_disconnected_match(m, bus);
17b0f1
         if (r < 0)
17b0f1
-                return 0;
17b0f1
+                return r;
17b0f1
 
17b0f1
         r = sd_bus_attach_event(bus, m->event, SD_EVENT_PRIORITY_NORMAL);
17b0f1
-        if (r < 0) {
17b0f1
-                log_error_errno(r, "Failed to attach system bus to event loop: %m");
17b0f1
-                return 0;
17b0f1
-        }
17b0f1
+        if (r < 0)
17b0f1
+                return log_error_errno(r, "Failed to attach system bus to event loop: %m");
17b0f1
 
17b0f1
         r = bus_setup_system(m, bus);
17b0f1
-        if (r < 0) {
17b0f1
-                log_error_errno(r, "Failed to set up system bus: %m");
17b0f1
-                return 0;
17b0f1
-        }
17b0f1
+        if (r < 0)
17b0f1
+                return log_error_errno(r, "Failed to set up system bus: %m");
17b0f1
 
17b0f1
         m->system_bus = bus;
17b0f1
         bus = NULL;
17b0f1
@@ -984,16 +972,16 @@ int bus_init(Manager *m, bool try_bus_connect) {
17b0f1
         if (try_bus_connect) {
17b0f1
                 r = bus_init_system(m);
17b0f1
                 if (r < 0)
17b0f1
-                        return r;
17b0f1
+                        return log_error_errno(r, "Failed to initialize D-Bus connection: %m");
17b0f1
 
17b0f1
                 r = bus_init_api(m);
17b0f1
                 if (r < 0)
17b0f1
-                        return r;
17b0f1
+                        return log_error_errno(r, "Error occured during D-Bus APIs initialization: %m");
17b0f1
         }
17b0f1
 
17b0f1
         r = bus_init_private(m);
17b0f1
         if (r < 0)
17b0f1
-                return r;
17b0f1
+                return log_error_errno(r, "Failed to create private D-Bus server: %m");
17b0f1
 
17b0f1
         return 0;
17b0f1
 }