]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus-util: improve logging when we can't connect to the bus 17967/head
authorLennart Poettering <lennart@poettering.net>
Mon, 14 Dec 2020 15:36:00 +0000 (16:36 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 15 Dec 2020 17:01:23 +0000 (18:01 +0100)
Previously, we'd already have explicit logging for the case where
$XDG_RUNTIME_DIR is not set. Let's also add some explicit logging for
the EPERM/ACCESS case. Let's also in both cases suggest the
--machine=<user>@.host syntax.

And while we are at it, let's remove side-effects from the macro.

By checking for both the EPERM/EACCES case and the $XDG_RUNTIME_DIR case
we will now catch both the cases where people use "su" to issue a
"systemctl --user" operation, and those where they (more correctly, but
still not good enough) call "su -".

Fixes: #17901
src/shared/bus-util.h

index a02d82a52ea1d923fdc2c315b289d25e9872c48f..27dd6c19c083fbb6b17cda652e3c4892cebe64c6 100644 (file)
@@ -9,6 +9,7 @@
 #include "sd-bus.h"
 #include "sd-event.h"
 
+#include "errno-util.h"
 #include "macro.h"
 #include "string-util.h"
 #include "time-util.h"
@@ -39,13 +40,21 @@ int bus_connect_transport(BusTransport transport, const char *host, bool user, s
 int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
 
 #define bus_log_address_error(r)                                        \
-        log_error_errno(r,                                              \
-                r == -ENOMEDIUM ? "Failed to set bus address: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined" : \
-                                  "Failed to set bus address: %m")
+        ({                                                              \
+                int _k = (r);                                           \
+                log_error_errno(_k,                                     \
+                                _k == -ENOMEDIUM ? "Failed to set bus address: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)" : \
+                                                   "Failed to set bus address: %m"); \
+        })
+
 #define bus_log_connect_error(r)                                        \
-        log_error_errno(r,                                              \
-                r == -ENOMEDIUM ? "Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined" : \
-                                  "Failed to connect to bus: %m")
+        ({                                                              \
+                int _k = (r);                                           \
+                log_error_errno(_k,                                     \
+                                _k == -ENOMEDIUM       ? "Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)" : \
+                                ERRNO_IS_PRIVILEGE(_k) ? "Failed to connect to bus: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)" : \
+                                                         "Failed to connect to bus: %m"); \
+        })
 
 #define bus_log_parse_error(r)                                  \
         log_error_errno(r, "Failed to parse bus message: %m")