From 1ecb46724cae151606bc825f0e39f14d4dfe1a0e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 14 Dec 2020 16:36:00 +0100 Subject: [PATCH] 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=@.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 | 21 +++++++++++++++------ 1 file 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=@.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=@.host --user to connect to bus of other user)" : \ + ERRNO_IS_PRIVILEGE(_k) ? "Failed to connect to bus: Operation not permitted (consider using --machine=@.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")