]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: downgrade log level of ECONNREFUSED from system dbus.service
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 29 Nov 2024 17:56:06 +0000 (02:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 11 Dec 2024 09:08:26 +0000 (18:08 +0900)
To suppress log message when 'systemctl poweroff' or friends invoked in
rescue shell, which does not have dbus.service.

src/shared/bus-util.c
src/shared/bus-util.h
src/systemctl/systemctl-logind.c
src/systemctl/systemctl-util.c
src/systemctl/systemctl-util.h

index ff80e580fc3ea4cde7f8fdd468ba0a3511ad1cdb..8313dfdd14e8d9fbb2396e2d0e58cc8c2701846a 100644 (file)
@@ -51,14 +51,14 @@ int bus_log_address_error(int r, BusTransport transport) {
                                       "Failed to set bus address: %m");
 }
 
-int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope) {
+int bus_log_connect_full(int log_level, int r, BusTransport transport, RuntimeScope scope) {
         bool hint_vars = transport == BUS_TRANSPORT_LOCAL && r == -ENOMEDIUM,
              hint_addr = transport == BUS_TRANSPORT_LOCAL && ERRNO_IS_PRIVILEGE(r);
 
-        return log_error_errno(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)" :
-                               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)" :
-                                           "Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport));
+        return log_full_errno(log_level, 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)" :
+                              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)" :
+                                          "Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport));
 }
 
 int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) {
index fbccb24314fe4c2a2d412f0afe62cbb93d75c7dd..e1908ecbaafff4c433428d5ffbe6779951e5f9d0 100644 (file)
@@ -48,7 +48,10 @@ int bus_connect_transport(BusTransport transport, const char *host, RuntimeScope
 int bus_connect_transport_systemd(BusTransport transport, const char *host, RuntimeScope runtime_scope, sd_bus **bus);
 
 int bus_log_address_error(int r, BusTransport transport);
-int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope);
+int bus_log_connect_full(int log_level, int r, BusTransport transport, RuntimeScope scope);
+static inline int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope) {
+        return bus_log_connect_full(LOG_ERR, r, transport, scope);
+}
 
 #define bus_log_parse_error(r)                                  \
         log_error_errno(r, "Failed to parse bus message: %m")
index 1258852a0167cd467cbd91276dc76d188882d5dd..e54067397aa09564ee618897c5a5186e84685e62 100644 (file)
@@ -66,7 +66,7 @@ int logind_reboot(enum action a) {
         if (!actions[a])
                 return -EINVAL;
 
-        r = acquire_bus(BUS_FULL, &bus);
+        r = acquire_bus_full(BUS_FULL, /* graceful = */ true, &bus);
         if (r < 0)
                 return r;
 
@@ -151,7 +151,7 @@ int logind_check_inhibitors(enum action a) {
         if (arg_transport != BUS_TRANSPORT_LOCAL)
                 return 0;
 
-        r = acquire_bus(BUS_FULL, &bus);
+        r = acquire_bus_full(BUS_FULL, /* graceful = */ true, &bus);
         if (r == -ECONNREFUSED && geteuid() == 0)
                 return 0; /* When D-Bus is not running, allow root to force a shutdown. E.g. when running at
                            * the emergency console. */
index 4674f0f36ffa7caa9c4d02e0146a0df2f2cef9d3..ecff2453e6255970f2852c1a6b13531e948c6b18 100644 (file)
@@ -32,7 +32,7 @@
 
 static sd_bus *buses[_BUS_FOCUS_MAX] = {};
 
-int acquire_bus(BusFocus focus, sd_bus **ret) {
+int acquire_bus_full(BusFocus focus, bool graceful, sd_bus **ret) {
         int r;
 
         assert(focus < _BUS_FOCUS_MAX);
@@ -54,7 +54,8 @@ int acquire_bus(BusFocus focus, sd_bus **ret) {
                 else
                         r = bus_connect_transport(arg_transport, arg_host, arg_runtime_scope, &buses[focus]);
                 if (r < 0)
-                        return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
+                        return bus_log_connect_full(graceful && focus == BUS_FULL && r == -ECONNREFUSED ? LOG_DEBUG : LOG_ERR,
+                                                    r, arg_transport, arg_runtime_scope);
 
                 (void) sd_bus_set_allow_interactive_authorization(buses[focus], arg_ask_password);
         }
index a950dde51552beb3897076f8366db17a92105403..96543a7b5eaf3aea5417441aaa8a40ed37e9a723 100644 (file)
@@ -13,7 +13,10 @@ typedef enum BusFocus {
         _BUS_FOCUS_MAX
 } BusFocus;
 
-int acquire_bus(BusFocus focus, sd_bus **ret);
+int acquire_bus_full(BusFocus focus, bool graceful, sd_bus **ret);
+static inline int acquire_bus(BusFocus focus, sd_bus **ret) {
+        return acquire_bus_full(focus, false, ret);
+}
 void release_busses(void);
 
 void ask_password_agent_open_maybe(void);