diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-11-04 10:41:47 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-11-04 11:00:54 +0100 |
commit | 10a7340a97f383e72a0a58e06bfbd673f347f095 (patch) | |
tree | e3a0363d0318d12ef727935a3fcc5b6023d9f53f | |
parent | fb293b3c0f2f0e24d088a6ccaf3bd051301754af (diff) | |
download | systemd-10a7340a97f383e72a0a58e06bfbd673f347f095.tar.gz |
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.
-rw-r--r-- | src/analyze/analyze.c | 18 | ||||
-rw-r--r-- | src/busctl/busctl.c | 6 | ||||
-rw-r--r-- | src/cgls/cgls.c | 2 | ||||
-rw-r--r-- | src/home/homectl.c | 2 | ||||
-rw-r--r-- | src/hostname/hostnamectl.c | 2 | ||||
-rw-r--r-- | src/locale/localectl.c | 2 | ||||
-rw-r--r-- | src/login/inhibit.c | 2 | ||||
-rw-r--r-- | src/login/loginctl.c | 2 | ||||
-rw-r--r-- | src/machine/machinectl.c | 2 | ||||
-rw-r--r-- | src/mount/mount-tool.c | 2 | ||||
-rw-r--r-- | src/portable/portablectl.c | 2 | ||||
-rw-r--r-- | src/run/run.c | 2 | ||||
-rw-r--r-- | src/shared/bus-util.c | 11 | ||||
-rw-r--r-- | src/shared/bus-util.h | 2 | ||||
-rw-r--r-- | src/shared/cgroup-show.c | 2 | ||||
-rw-r--r-- | src/systemctl/systemctl-util.c | 2 | ||||
-rw-r--r-- | src/timedate/timedatectl.c | 2 |
17 files changed, 33 insertions, 30 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index c6a0f8efc3..f3b103a5bc 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -639,7 +639,7 @@ static int analyze_plot(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, &use_full_bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); n = acquire_boot_times(bus, &boot); if (n < 0) @@ -1034,7 +1034,7 @@ static int analyze_critical_chain(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, NULL); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); n = acquire_time_data(bus, ×); if (n <= 0) @@ -1076,7 +1076,7 @@ static int analyze_blame(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, NULL); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); n = acquire_time_data(bus, ×); if (n <= 0) @@ -1133,7 +1133,7 @@ static int analyze_time(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, NULL); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); r = pretty_boot_time(bus, &buf); if (r < 0) @@ -1270,7 +1270,7 @@ static int dot(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, NULL); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); r = expand_patterns(bus, strv_skip(argv, 1), &expanded_patterns); if (r < 0) @@ -1347,7 +1347,7 @@ static int dump(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, NULL); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); (void) pager_open(arg_pager_flags); @@ -1416,7 +1416,7 @@ static int verb_log_control(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, NULL); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); return verb_log_control_common(bus, "org.freedesktop.systemd1", argv[0], argc == 2 ? argv[1] : NULL); } @@ -2228,7 +2228,7 @@ static int service_watchdogs(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, NULL); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); if (argc == 1) { /* get ServiceWatchdogs */ @@ -2268,7 +2268,7 @@ static int do_security(int argc, char *argv[], void *userdata) { r = acquire_bus(&bus, NULL); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); (void) pager_open(arg_pager_flags); diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 2dbef89e4c..b5cd9749cc 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -102,7 +102,7 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) { if (arg_address) r = sd_bus_set_address(bus, arg_address); - else { + else switch (arg_transport) { case BUS_TRANSPORT_LOCAL: @@ -123,13 +123,13 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) { default: assert_not_reached(); } - } + if (r < 0) return bus_log_address_error(r, arg_transport); r = sd_bus_start(bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); *ret = TAKE_PTR(bus); diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c index e2c746f7e7..487c90823e 100644 --- a/src/cgls/cgls.c +++ b/src/cgls/cgls.c @@ -216,7 +216,7 @@ static int run(int argc, char *argv[]) { arg_show_unit == SHOW_UNIT_USER, &bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL); } q = show_cgroup_get_unit_path_and_warn(bus, *name, &cgroup); diff --git a/src/home/homectl.c b/src/home/homectl.c index 4f1aebfe30..d3605cf308 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -104,7 +104,7 @@ static int acquire_bus(sd_bus **bus) { r = bus_connect_transport(arg_transport, arg_host, false, bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); (void) sd_bus_set_allow_interactive_authorization(*bus, arg_ask_password); diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index bc78070131..26869a8d71 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -660,7 +660,7 @@ static int run(int argc, char *argv[]) { r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); return hostnamectl_main(bus, argc, argv); } diff --git a/src/locale/localectl.c b/src/locale/localectl.c index 7e63976dfc..bc4e37da31 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -512,7 +512,7 @@ static int run(int argc, char *argv[]) { r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); return localectl_main(bus, argc, argv); } diff --git a/src/login/inhibit.c b/src/login/inhibit.c index ff5a5d06f5..49aaf68c4d 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -283,7 +283,7 @@ static int run(int argc, char *argv[]) { r = sd_bus_default_system(&bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL); if (arg_action == ACTION_LIST) return print_inhibitors(bus); diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 846a31012e..46e7652ecb 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -1468,7 +1468,7 @@ static int run(int argc, char *argv[]) { r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index d18374dda0..73eb9056ff 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -2869,7 +2869,7 @@ static int run(int argc, char *argv[]) { r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index d8034202dc..1ce9756f31 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -1458,7 +1458,7 @@ static int run(int argc, char* argv[]) { r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); if (arg_action == ACTION_UMOUNT) return action_umount(bus, argc, argv); diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c index ec625161a4..e601ee5d8f 100644 --- a/src/portable/portablectl.c +++ b/src/portable/portablectl.c @@ -220,7 +220,7 @@ static int acquire_bus(sd_bus **bus) { r = bus_connect_transport(arg_transport, arg_host, false, bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); (void) sd_bus_set_allow_interactive_authorization(*bus, arg_ask_password); diff --git a/src/run/run.c b/src/run/run.c index bf2bd29bc0..42c4e1b46b 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -1760,7 +1760,7 @@ static int run(int argc, char* argv[]) { else r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); if (arg_scope) r = start_transient_scope(bus); 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) diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c index d0c514e467..ae02af280e 100644 --- a/src/systemctl/systemctl-util.c +++ b/src/systemctl/systemctl-util.c @@ -53,7 +53,7 @@ int acquire_bus(BusFocus focus, sd_bus **ret) { else r = bus_connect_transport(arg_transport, arg_host, user, &buses[focus]); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); (void) sd_bus_set_allow_interactive_authorization(buses[focus], arg_ask_password); } diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c index d9767ba564..ebe4b59620 100644 --- a/src/timedate/timedatectl.c +++ b/src/timedate/timedatectl.c @@ -1038,7 +1038,7 @@ static int run(int argc, char *argv[]) { r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) - return bus_log_connect_error(r); + return bus_log_connect_error(r, arg_transport); return timedatectl_main(bus, argc, argv); } |