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