ryantimwilson / rpms / systemd

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