From: Zbigniew Jędrzejewski-Szmek Date: Thu, 4 Nov 2021 09:37:11 +0000 (+0100) Subject: shared/bus-util: make bus_log_*_error() functions functions X-Git-Tag: v250-rc1~358^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=237fbb67194bee720d95cb0ab20821e1822e8ce4;p=thirdparty%2Fsystemd.git shared/bus-util: make bus_log_*_error() functions functions They were defined as macros, but they are a bit too complicated for this, so it's getting unwieldy. We can make them functions without any loss. --- diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 942a59be88c..75e89ab5dc9 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -34,6 +34,19 @@ static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_ return 1; } +int bus_log_address_error(int r) { + return log_error_errno(r, + r == -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"); +} + +int bus_log_connect_error(int r) { + return log_error_errno(r, + r == -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(r) ? "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"); +} + int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) { const char *match; const char *unique; diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h index e0d4d5d915c..3a65851fa59 100644 --- a/src/shared/bus-util.h +++ b/src/shared/bus-util.h @@ -39,22 +39,8 @@ int bus_connect_user_systemd(sd_bus **_bus); int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus); int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus); -#define bus_log_address_error(r) \ - ({ \ - 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) \ - ({ \ - 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"); \ - }) +int bus_log_address_error(int r); +int bus_log_connect_error(int r); #define bus_log_parse_error(r) \ log_error_errno(r, "Failed to parse bus message: %m")