teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 34728.patch

613b6e
From 871ee2f08715f8fae441786db04ba8497822f79a Mon Sep 17 00:00:00 2001
613b6e
From: Daan De Meyer <daan.j.demeyer@gmail.com>
613b6e
Date: Tue, 8 Oct 2024 16:22:58 +0200
613b6e
Subject: [PATCH 1/3] bus-util: Log more information when connecting to a bus
613b6e
 socket fails
613b6e
613b6e
Let's log about which bus we're trying to connect to and what transport
613b6e
we're using to do it.
613b6e
613b6e
(cherry picked from commit d8a77d55e6ad7f251ae0eb6758af6bba111095df)
613b6e
---
613b6e
 src/analyze/analyze-blame.c             |  2 +-
613b6e
 src/analyze/analyze-critical-chain.c    |  2 +-
613b6e
 src/analyze/analyze-dot.c               |  2 +-
613b6e
 src/analyze/analyze-dump.c              |  2 +-
613b6e
 src/analyze/analyze-fdstore.c           |  2 +-
613b6e
 src/analyze/analyze-log-control.c       |  2 +-
613b6e
 src/analyze/analyze-malloc.c            |  2 +-
613b6e
 src/analyze/analyze-plot.c              |  2 +-
613b6e
 src/analyze/analyze-security.c          |  2 +-
613b6e
 src/analyze/analyze-service-watchdogs.c |  2 +-
613b6e
 src/analyze/analyze-time.c              |  2 +-
613b6e
 src/busctl/busctl.c                     |  2 +-
613b6e
 src/cgls/cgls.c                         |  9 ++++-----
613b6e
 src/firstboot/firstboot.c               |  4 ++--
613b6e
 src/home/homectl.c                      |  2 +-
613b6e
 src/hostname/hostnamectl.c              |  2 +-
613b6e
 src/import/importctl.c                  |  2 +-
613b6e
 src/locale/localectl.c                  |  2 +-
613b6e
 src/login/inhibit.c                     |  2 +-
613b6e
 src/login/loginctl.c                    |  2 +-
613b6e
 src/machine/machinectl.c                |  2 +-
613b6e
 src/mount/mount-tool.c                  |  2 +-
613b6e
 src/portable/portablectl.c              |  2 +-
613b6e
 src/run/run.c                           |  2 +-
613b6e
 src/shared/bus-util.c                   | 18 ++++++++++++++----
613b6e
 src/shared/bus-util.h                   |  4 +++-
613b6e
 src/shared/cgroup-show.c                |  2 +-
613b6e
 src/systemctl/systemctl-util.c          |  2 +-
613b6e
 src/timedate/timedatectl.c              |  2 +-
613b6e
 29 files changed, 48 insertions(+), 37 deletions(-)
613b6e
613b6e
diff --git a/src/analyze/analyze-blame.c b/src/analyze/analyze-blame.c
613b6e
index 81e5c590b9cc2..4d78ed405d7d4 100644
613b6e
--- a/src/analyze/analyze-blame.c
613b6e
+++ b/src/analyze/analyze-blame.c
613b6e
@@ -14,7 +14,7 @@ int verb_blame(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         n = acquire_time_data(bus, /* require_finished = */ false, ×);
613b6e
         if (n <= 0)
613b6e
diff --git a/src/analyze/analyze-critical-chain.c b/src/analyze/analyze-critical-chain.c
613b6e
index 7d78de3d388d1..03c014d4023e6 100644
613b6e
--- a/src/analyze/analyze-critical-chain.c
613b6e
+++ b/src/analyze/analyze-critical-chain.c
613b6e
@@ -200,7 +200,7 @@ int verb_critical_chain(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         n = acquire_time_data(bus, /* require_finished = */ true, ×);
613b6e
         if (n <= 0)
613b6e
diff --git a/src/analyze/analyze-dot.c b/src/analyze/analyze-dot.c
613b6e
index 9e92d59bceeee..b93bf4a9a5bb0 100644
613b6e
--- a/src/analyze/analyze-dot.c
613b6e
+++ b/src/analyze/analyze-dot.c
613b6e
@@ -149,7 +149,7 @@ int verb_dot(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         r = expand_patterns(bus, strv_skip(argv, 1), &expanded_patterns);
613b6e
         if (r < 0)
613b6e
diff --git a/src/analyze/analyze-dump.c b/src/analyze/analyze-dump.c
613b6e
index 2642582903b09..4ee547ed4c969 100644
613b6e
--- a/src/analyze/analyze-dump.c
613b6e
+++ b/src/analyze/analyze-dump.c
613b6e
@@ -123,7 +123,7 @@ int verb_dump(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         pager_open(arg_pager_flags);
613b6e
 
613b6e
diff --git a/src/analyze/analyze-fdstore.c b/src/analyze/analyze-fdstore.c
613b6e
index 8ada6d4e73e1f..1f4adb7089ab0 100644
613b6e
--- a/src/analyze/analyze-fdstore.c
613b6e
+++ b/src/analyze/analyze-fdstore.c
613b6e
@@ -98,7 +98,7 @@ int verb_fdstore(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         STRV_FOREACH(arg, strv_skip(argv, 1)) {
613b6e
                 r = dump_fdstore(bus, *arg);
613b6e
diff --git a/src/analyze/analyze-log-control.c b/src/analyze/analyze-log-control.c
613b6e
index cead0e833f5da..854cf6cb806c2 100644
613b6e
--- a/src/analyze/analyze-log-control.c
613b6e
+++ b/src/analyze/analyze-log-control.c
613b6e
@@ -12,7 +12,7 @@ int verb_log_control(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         r = verb_log_control_common(bus, "org.freedesktop.systemd1", argv[0], argc == 2 ? argv[1] : NULL);
613b6e
         if (r < 0)
613b6e
diff --git a/src/analyze/analyze-malloc.c b/src/analyze/analyze-malloc.c
613b6e
index 5e6ff5bb9627c..514526d14256a 100644
613b6e
--- a/src/analyze/analyze-malloc.c
613b6e
+++ b/src/analyze/analyze-malloc.c
613b6e
@@ -43,7 +43,7 @@ int verb_malloc(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         r = sd_bus_can_send(bus, SD_BUS_TYPE_UNIX_FD);
613b6e
         if (r < 0)
613b6e
diff --git a/src/analyze/analyze-plot.c b/src/analyze/analyze-plot.c
613b6e
index e271296b6875b..ce67c092c37cd 100644
613b6e
--- a/src/analyze/analyze-plot.c
613b6e
+++ b/src/analyze/analyze-plot.c
613b6e
@@ -468,7 +468,7 @@ int verb_plot(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, &use_full_bus);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         n = acquire_boot_times(bus, /* require_finished = */ true, &boot);
613b6e
         if (n < 0)
613b6e
diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c
613b6e
index 3d7b647a6f361..d3ba975107297 100644
613b6e
--- a/src/analyze/analyze-security.c
613b6e
+++ b/src/analyze/analyze-security.c
613b6e
@@ -2904,7 +2904,7 @@ int verb_security(int argc, char *argv[], void *userdata) {
613b6e
         if (!arg_offline) {
613b6e
                 r = acquire_bus(&bus, NULL);
613b6e
                 if (r < 0)
613b6e
-                        return bus_log_connect_error(r, arg_transport);
613b6e
+                        return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
         }
613b6e
 
613b6e
         pager_open(arg_pager_flags);
613b6e
diff --git a/src/analyze/analyze-service-watchdogs.c b/src/analyze/analyze-service-watchdogs.c
613b6e
index 6535eb1a894f7..b1fad4328caa5 100644
613b6e
--- a/src/analyze/analyze-service-watchdogs.c
613b6e
+++ b/src/analyze/analyze-service-watchdogs.c
613b6e
@@ -16,7 +16,7 @@ int verb_service_watchdogs(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         if (argc == 1) {
613b6e
                 /* get ServiceWatchdogs */
613b6e
diff --git a/src/analyze/analyze-time.c b/src/analyze/analyze-time.c
613b6e
index c233b1f08558e..8135112dec42b 100644
613b6e
--- a/src/analyze/analyze-time.c
613b6e
+++ b/src/analyze/analyze-time.c
613b6e
@@ -11,7 +11,7 @@ int verb_time(int argc, char *argv[], void *userdata) {
613b6e
 
613b6e
         r = acquire_bus(&bus, NULL);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         r = pretty_boot_time(bus, &buf;;
613b6e
         if (r < 0)
613b6e
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
613b6e
index 8db9076997232..bbd36c1dc42bc 100644
613b6e
--- a/src/busctl/busctl.c
613b6e
+++ b/src/busctl/busctl.c
613b6e
@@ -152,7 +152,7 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) {
613b6e
 
613b6e
         r = sd_bus_start(bus);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         *ret = TAKE_PTR(bus);
613b6e
 
613b6e
diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c
613b6e
index 70fa260246929..1dcd316cdb379 100644
613b6e
--- a/src/cgls/cgls.c
613b6e
+++ b/src/cgls/cgls.c
613b6e
@@ -221,13 +221,12 @@ static int run(int argc, char *argv[]) {
613b6e
                                         return log_error_errno(r, "Failed to mangle unit name: %m");
613b6e
 
613b6e
                                 if (!bus) {
613b6e
+                                        RuntimeScope scope = arg_show_unit == SHOW_UNIT_USER ? RUNTIME_SCOPE_USER : RUNTIME_SCOPE_SYSTEM;
613b6e
+
613b6e
                                         /* Connect to the bus only if necessary */
613b6e
-                                        r = bus_connect_transport_systemd(
613b6e
-                                                        BUS_TRANSPORT_LOCAL, NULL,
613b6e
-                                                        arg_show_unit == SHOW_UNIT_USER ? RUNTIME_SCOPE_USER : RUNTIME_SCOPE_SYSTEM,
613b6e
-                                                        &bus;;
613b6e
+                                        r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, scope, &bus;;
613b6e
                                         if (r < 0)
613b6e
-                                                return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
613b6e
+                                                return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, scope);
613b6e
                                 }
613b6e
 
613b6e
                                 q = show_cgroup_get_unit_path_and_warn(bus, unit_name, &cgroup);
613b6e
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
613b6e
index 0dbdfc663871f..3b732b38609ab 100644
613b6e
--- a/src/firstboot/firstboot.c
613b6e
+++ b/src/firstboot/firstboot.c
613b6e
@@ -1616,7 +1616,7 @@ static int reload_system_manager(sd_bus **bus) {
613b6e
         if (!*bus) {
613b6e
                 r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, RUNTIME_SCOPE_SYSTEM, bus);
613b6e
                 if (r < 0)
613b6e
-                        return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
613b6e
+                        return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
613b6e
         }
613b6e
 
613b6e
         r = bus_service_manager_reload(*bus);
613b6e
@@ -1639,7 +1639,7 @@ static int reload_vconsole(sd_bus **bus) {
613b6e
         if (!*bus) {
613b6e
                 r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, RUNTIME_SCOPE_SYSTEM, bus);
613b6e
                 if (r < 0)
613b6e
-                        return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
613b6e
+                        return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
613b6e
         }
613b6e
 
613b6e
         r = bus_wait_for_jobs_new(*bus, &w);
613b6e
diff --git a/src/home/homectl.c b/src/home/homectl.c
613b6e
index 346daa1195ccd..36e3bf729948f 100644
613b6e
--- a/src/home/homectl.c
613b6e
+++ b/src/home/homectl.c
613b6e
@@ -134,7 +134,7 @@ static int acquire_bus(sd_bus **bus) {
613b6e
 
613b6e
         r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, bus);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         (void) sd_bus_set_allow_interactive_authorization(*bus, arg_ask_password);
613b6e
 
613b6e
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
613b6e
index d1c4d476f66b9..ead0cc4da6e82 100644
613b6e
--- a/src/hostname/hostnamectl.c
613b6e
+++ b/src/hostname/hostnamectl.c
613b6e
@@ -813,7 +813,7 @@ static int run(int argc, char *argv[]) {
613b6e
 
613b6e
         r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         return hostnamectl_main(bus, argc, argv);
613b6e
 }
613b6e
diff --git a/src/import/importctl.c b/src/import/importctl.c
613b6e
index f939d80815dca..da9e5b62d23d6 100644
613b6e
--- a/src/import/importctl.c
613b6e
+++ b/src/import/importctl.c
613b6e
@@ -1235,7 +1235,7 @@ static int run(int argc, char *argv[]) {
613b6e
 
613b6e
         r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
613b6e
 
613b6e
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
613b6e
index 32354027f1755..2fb4657fe24fb 100644
613b6e
--- a/src/locale/localectl.c
613b6e
+++ b/src/locale/localectl.c
613b6e
@@ -527,7 +527,7 @@ static int run(int argc, char *argv[]) {
613b6e
 
613b6e
         r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         return localectl_main(bus, argc, argv);
613b6e
 }
613b6e
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
613b6e
index 4682830d198a8..e060c614004b1 100644
613b6e
--- a/src/login/inhibit.c
613b6e
+++ b/src/login/inhibit.c
613b6e
@@ -265,7 +265,7 @@ static int run(int argc, char *argv[]) {
613b6e
 
613b6e
         r = sd_bus_default_system(&bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
613b6e
+                return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         if (arg_action == ACTION_LIST)
613b6e
                 return print_inhibitors(bus);
613b6e
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
613b6e
index cf3bff437a0bc..e950bfc985ff5 100644
613b6e
--- a/src/login/loginctl.c
613b6e
+++ b/src/login/loginctl.c
613b6e
@@ -1727,7 +1727,7 @@ static int run(int argc, char *argv[]) {
613b6e
 
613b6e
         r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
613b6e
 
613b6e
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
613b6e
index 1b63e6d203786..b9105f298b6b1 100644
613b6e
--- a/src/machine/machinectl.c
613b6e
+++ b/src/machine/machinectl.c
613b6e
@@ -2446,7 +2446,7 @@ static int run(int argc, char *argv[]) {
613b6e
 
613b6e
         r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
613b6e
 
613b6e
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c
613b6e
index fcebdcaf18c9b..b991bed714896 100644
613b6e
--- a/src/mount/mount-tool.c
613b6e
+++ b/src/mount/mount-tool.c
613b6e
@@ -1503,7 +1503,7 @@ static int run(int argc, char* argv[]) {
613b6e
 
613b6e
         r = bus_connect_transport_systemd(arg_transport, arg_host, arg_runtime_scope, &bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         if (arg_action == ACTION_UMOUNT)
613b6e
                 return action_umount(bus, argc, argv);
613b6e
diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c
613b6e
index 57b930d6cba41..2681cf4dd2070 100644
613b6e
--- a/src/portable/portablectl.c
613b6e
+++ b/src/portable/portablectl.c
613b6e
@@ -229,7 +229,7 @@ static int acquire_bus(sd_bus **bus) {
613b6e
 
613b6e
         r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, bus);
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         (void) sd_bus_set_allow_interactive_authorization(*bus, arg_ask_password);
613b6e
 
613b6e
diff --git a/src/run/run.c b/src/run/run.c
613b6e
index ba7bb2148a15f..3a7102e32923b 100644
613b6e
--- a/src/run/run.c
613b6e
+++ b/src/run/run.c
613b6e
@@ -2405,7 +2405,7 @@ static int run(int argc, char* argv[]) {
613b6e
         else
613b6e
                 r = bus_connect_transport_systemd(arg_transport, arg_host, arg_runtime_scope, &bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
         if (arg_scope)
613b6e
                 return start_transient_scope(bus);
613b6e
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
613b6e
index 30f9602b1edbc..f347ea604ec25 100644
613b6e
--- a/src/shared/bus-util.c
613b6e
+++ b/src/shared/bus-util.c
613b6e
@@ -28,6 +28,7 @@
613b6e
 #include "path-util.h"
613b6e
 #include "socket-util.h"
613b6e
 #include "stdio-util.h"
613b6e
+#include "string-table.h"
613b6e
 #include "uid-classification.h"
613b6e
 
613b6e
 static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
613b6e
@@ -49,14 +50,14 @@ int bus_log_address_error(int r, BusTransport transport) {
613b6e
                                       "Failed to set bus address: %m");
613b6e
 }
613b6e
 
613b6e
-int bus_log_connect_error(int r, BusTransport transport) {
613b6e
+int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope) {
613b6e
         bool hint_vars = transport == BUS_TRANSPORT_LOCAL && r == -ENOMEDIUM,
613b6e
              hint_addr = transport == BUS_TRANSPORT_LOCAL && ERRNO_IS_PRIVILEGE(r);
613b6e
 
613b6e
         return log_error_errno(r,
613b6e
-                               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)" :
613b6e
-                               r == hint_addr ? "Failed to connect to bus: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)" :
613b6e
-                                                "Failed to connect to bus: %m");
613b6e
+                               r == hint_vars ? "Failed to connect to %s scope bus via %s transport: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)" :
613b6e
+                               r == hint_addr ? "Failed to connect to %s scope bus via %s transport: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)" :
613b6e
+                                                "Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport));
613b6e
 }
613b6e
 
613b6e
 int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) {
613b6e
@@ -926,3 +927,12 @@ int bus_message_read_id128(sd_bus_message *m, sd_id128_t *ret) {
613b6e
                 return -EINVAL;
613b6e
         }
613b6e
 }
613b6e
+
613b6e
+static const char* const bus_transport_table[] = {
613b6e
+        [BUS_TRANSPORT_LOCAL]   = "local",
613b6e
+        [BUS_TRANSPORT_REMOTE]  = "remote",
613b6e
+        [BUS_TRANSPORT_MACHINE] = "machine",
613b6e
+        [BUS_TRANSPORT_CAPSULE] = "capsule",
613b6e
+};
613b6e
+
613b6e
+DEFINE_STRING_TABLE_LOOKUP_TO_STRING(bus_transport, BusTransport);
613b6e
diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h
613b6e
index 9c6f01d8eb846..fbccb24314fe4 100644
613b6e
--- a/src/shared/bus-util.h
613b6e
+++ b/src/shared/bus-util.h
613b6e
@@ -48,7 +48,7 @@ int bus_connect_transport(BusTransport transport, const char *host, RuntimeScope
613b6e
 int bus_connect_transport_systemd(BusTransport transport, const char *host, RuntimeScope runtime_scope, sd_bus **bus);
613b6e
 
613b6e
 int bus_log_address_error(int r, BusTransport transport);
613b6e
-int bus_log_connect_error(int r, BusTransport transport);
613b6e
+int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope);
613b6e
 
613b6e
 #define bus_log_parse_error(r)                                  \
613b6e
         log_error_errno(r, "Failed to parse bus message: %m")
613b6e
@@ -84,3 +84,5 @@ int bus_creds_get_pidref(sd_bus_creds *c, PidRef *ret);
613b6e
 int bus_query_sender_pidref(sd_bus_message *m, PidRef *ret);
613b6e
 
613b6e
 int bus_message_read_id128(sd_bus_message *m, sd_id128_t *ret);
613b6e
+
613b6e
+const char* bus_transport_to_string(BusTransport transport) _const_;
613b6e
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
613b6e
index 87177316da8f9..96826ac7d8e87 100644
613b6e
--- a/src/shared/cgroup-show.c
613b6e
+++ b/src/shared/cgroup-show.c
613b6e
@@ -433,7 +433,7 @@ int show_cgroup_get_path_and_warn(
613b6e
 
613b6e
                 r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, RUNTIME_SCOPE_SYSTEM, &bus;;
613b6e
                 if (r < 0)
613b6e
-                        return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
613b6e
+                        return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
                 r = show_cgroup_get_unit_path_and_warn(bus, unit, &root);
613b6e
                 if (r < 0)
613b6e
diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c
613b6e
index 38e1f23740ed6..18c8823e3fe70 100644
613b6e
--- a/src/systemctl/systemctl-util.c
613b6e
+++ b/src/systemctl/systemctl-util.c
613b6e
@@ -54,7 +54,7 @@ int acquire_bus(BusFocus focus, sd_bus **ret) {
613b6e
                 else
613b6e
                         r = bus_connect_transport(arg_transport, arg_host, arg_runtime_scope, &buses[focus]);
613b6e
                 if (r < 0)
613b6e
-                        return bus_log_connect_error(r, arg_transport);
613b6e
+                        return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
613b6e
 
613b6e
                 (void) sd_bus_set_allow_interactive_authorization(buses[focus], arg_ask_password);
613b6e
         }
613b6e
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
613b6e
index 46ec6b31bc46a..db9f3b22b9b5e 100644
613b6e
--- a/src/timedate/timedatectl.c
613b6e
+++ b/src/timedate/timedatectl.c
613b6e
@@ -1031,7 +1031,7 @@ static int run(int argc, char *argv[]) {
613b6e
 
613b6e
         r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus;;
613b6e
         if (r < 0)
613b6e
-                return bus_log_connect_error(r, arg_transport);
613b6e
+                return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
613b6e
 
613b6e
         return timedatectl_main(bus, argc, argv);
613b6e
 }
613b6e
613b6e
From 31e38b55b2e4bb1aa42fe106ea14df8e82758303 Mon Sep 17 00:00:00 2001
613b6e
From: Daan De Meyer <daan.j.demeyer@gmail.com>
613b6e
Date: Tue, 8 Oct 2024 16:25:52 +0200
613b6e
Subject: [PATCH 2/3] core: Bump log level of reexecute request to notice
613b6e
613b6e
A daemon-reload is important enough to deserve logging at notice
613b6e
level.
613b6e
613b6e
(cherry picked from commit 4ee41be82507348fbbc9d3ab28aae6330eb51663)
613b6e
---
613b6e
 src/core/dbus-manager.c | 8 ++++----
613b6e
 1 file changed, 4 insertions(+), 4 deletions(-)
613b6e
613b6e
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
613b6e
index 7da35a803c62c..2412bd1aab742 100644
613b6e
--- a/src/core/dbus-manager.c
613b6e
+++ b/src/core/dbus-manager.c
613b6e
@@ -1571,10 +1571,10 @@ static void log_caller(sd_bus_message *message, Manager *manager, const char *me
613b6e
         (void) sd_bus_creds_get_comm(creds, &comm);
613b6e
         caller = manager_get_unit_by_pid(manager, pid);
613b6e
 
613b6e
-        log_info("%s requested from client PID " PID_FMT "%s%s%s%s%s%s...",
613b6e
-                 method, pid,
613b6e
-                 comm ? " ('" : "", strempty(comm), comm ? "')" : "",
613b6e
-                 caller ? " (unit " : "", caller ? caller->id : "", caller ? ")" : "");
613b6e
+        log_notice("%s requested from client PID " PID_FMT "%s%s%s%s%s%s...",
613b6e
+                   method, pid,
613b6e
+                   comm ? " ('" : "", strempty(comm), comm ? "')" : "",
613b6e
+                   caller ? " (unit " : "", caller ? caller->id : "", caller ? ")" : "");
613b6e
 }
613b6e
 
613b6e
 static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) {
613b6e
613b6e
From 814be7116dda14074749253d94b83387ceff0ff1 Mon Sep 17 00:00:00 2001
613b6e
From: Daan De Meyer <daan.j.demeyer@gmail.com>
613b6e
Date: Tue, 8 Oct 2024 16:28:25 +0200
613b6e
Subject: [PATCH 3/3] core: Log in more scenarios about which process initiated
613b6e
 an operation
613b6e
613b6e
Exit/Reboot/Poweroff and similar operations are invasive enough that
613b6e
logging about who initiated them is very useful to debug issues.
613b6e
613b6e
(cherry picked from commit acb0f501f4291efce82bcf89d4ad92b6a895f4fa)
613b6e
---
613b6e
 src/core/dbus-manager.c | 12 ++++++++++++
613b6e
 1 file changed, 12 insertions(+)
613b6e
613b6e
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
613b6e
index 2412bd1aab742..0c1260f2d9cbe 100644
613b6e
--- a/src/core/dbus-manager.c
613b6e
+++ b/src/core/dbus-manager.c
613b6e
@@ -1671,6 +1671,8 @@ static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *er
613b6e
         if (r < 0)
613b6e
                 return r;
613b6e
 
613b6e
+        log_caller(message, m, "Exit");
613b6e
+
613b6e
         /* Exit() (in contrast to SetExitCode()) is actually allowed even if
613b6e
          * we are running on the host. It will fall back on reboot() in
613b6e
          * systemd-shutdown if it cannot do the exit() because it isn't a
613b6e
@@ -1695,6 +1697,8 @@ static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *
613b6e
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
613b6e
                                          "Reboot is only supported for system managers.");
613b6e
 
613b6e
+        log_caller(message, m, "Reboot");
613b6e
+
613b6e
         m->objective = MANAGER_REBOOT;
613b6e
 
613b6e
         return sd_bus_reply_method_return(message, NULL);
613b6e
@@ -1737,6 +1741,8 @@ static int method_soft_reboot(sd_bus_message *message, void *userdata, sd_bus_er
613b6e
                         return -ENOMEM;
613b6e
         }
613b6e
 
613b6e
+        log_caller(message, m, "Soft reboot");
613b6e
+
613b6e
         free_and_replace(m->switch_root, rt);
613b6e
         m->objective = MANAGER_SOFT_REBOOT;
613b6e
 
613b6e
@@ -1757,6 +1763,8 @@ static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error
613b6e
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
613b6e
                                          "Powering off is only supported for system managers.");
613b6e
 
613b6e
+        log_caller(message, m, "Poweroff");
613b6e
+
613b6e
         m->objective = MANAGER_POWEROFF;
613b6e
 
613b6e
         return sd_bus_reply_method_return(message, NULL);
613b6e
@@ -1776,6 +1784,8 @@ static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *er
613b6e
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
613b6e
                                          "Halt is only supported for system managers.");
613b6e
 
613b6e
+        log_caller(message, m, "Halt");
613b6e
+
613b6e
         m->objective = MANAGER_HALT;
613b6e
 
613b6e
         return sd_bus_reply_method_return(message, NULL);
613b6e
@@ -1795,6 +1805,8 @@ static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *e
613b6e
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
613b6e
                                          "KExec is only supported for system managers.");
613b6e
 
613b6e
+        log_caller(message, m, "Kexec");
613b6e
+
613b6e
         m->objective = MANAGER_KEXEC;
613b6e
 
613b6e
         return sd_bus_reply_method_return(message, NULL);