summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-12-14 16:36:00 +0100
committerLennart Poettering <lennart@poettering.net>2020-12-15 18:01:23 +0100
commit1ecb46724cae151606bc825f0e39f14d4dfe1a0e (patch)
treeb2789d3f88e09a0c741f6439153abb086be45868
parentcedfd142dea105b37223ad24d784494bfae83dc5 (diff)
downloadsystemd-1ecb46724cae151606bc825f0e39f14d4dfe1a0e.tar.gz
bus-util: improve logging when we can't connect to the bus
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
-rw-r--r--src/shared/bus-util.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h
index a02d82a52e..27dd6c19c0 100644
--- a/src/shared/bus-util.h
+++ b/src/shared/bus-util.h
@@ -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")