summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-04 10:41:47 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-04 11:00:54 +0100
commit10a7340a97f383e72a0a58e06bfbd673f347f095 (patch)
treee3a0363d0318d12ef727935a3fcc5b6023d9f53f /src/shared
parentbusctl: do not print hint about -M if -M is already used (diff)
downloadsystemd-10a7340a97f383e72a0a58e06bfbd673f347f095.tar.xz
systemd-10a7340a97f383e72a0a58e06bfbd673f347f095.zip
tree-wide: do not print hint about -M if -M is already used
(Or when -H is used, since -H and -M are incompatible.) Note that the slightly unusual form with separate boolean variables (hint_vars, hint_addr) instead of e.g. a const char* variable to hold the message, because this way we don't trigger the warning about non-literal format.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/bus-util.c11
-rw-r--r--src/shared/bus-util.h2
-rw-r--r--src/shared/cgroup-show.c2
3 files changed, 9 insertions, 6 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 8568135a4a..4a2b7684bc 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -42,11 +42,14 @@ int bus_log_address_error(int r, BusTransport transport) {
"Failed to set bus address: %m");
}
-int bus_log_connect_error(int r) {
+int bus_log_connect_error(int r, BusTransport transport) {
+ bool hint_vars = transport == BUS_TRANSPORT_LOCAL && r == -ENOMEDIUM,
+ hint_addr = transport == BUS_TRANSPORT_LOCAL && ERRNO_IS_PRIVILEGE(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=<user>@.host --user to connect to bus of other user)" :
- ERRNO_IS_PRIVILEGE(r) ? "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");
+ r == hint_vars ? "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)" :
+ r == hint_addr ? "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");
}
int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) {
diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h
index 4f0d186f95..00514e359f 100644
--- a/src/shared/bus-util.h
+++ b/src/shared/bus-util.h
@@ -40,7 +40,7 @@ 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);
int bus_log_address_error(int r, BusTransport transport);
-int bus_log_connect_error(int r);
+int bus_log_connect_error(int r, BusTransport transport);
#define bus_log_parse_error(r) \
log_error_errno(r, "Failed to parse bus message: %m")
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index c3eaf5387f..40bc2bff05 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -447,7 +447,7 @@ int show_cgroup_get_path_and_warn(
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
if (r < 0)
- return bus_log_connect_error(r);
+ return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
r = show_cgroup_get_unit_path_and_warn(bus, unit, &root);
if (r < 0)