]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: refuse dbus activation if dbus is not running 27579/head
authorMike Yuan <me@yhndnzj.com>
Mon, 8 May 2023 16:07:45 +0000 (00:07 +0800)
committerMike Yuan <me@yhndnzj.com>
Mon, 8 May 2023 17:42:25 +0000 (01:42 +0800)
dbus-broker issues StartUnit directly for activation requests,
so let's add a check on bus state in bus_unit_queue_job to refuse
that if dbus is not running.

Replaces #27570
Closes #26799

src/core/dbus-unit.c
src/core/dbus.c

index dd36cae860d8a8763c9b1f88657a48fc176eb7ef..5b89c7658665249c548c2d16a240df6b3639901f 100644 (file)
@@ -21,6 +21,7 @@
 #include "path-util.h"
 #include "process-util.h"
 #include "selinux-access.h"
+#include "service.h"
 #include "signal-util.h"
 #include "special.h"
 #include "string-table.h"
@@ -1876,6 +1877,12 @@ int bus_unit_queue_job(
             (type == JOB_RELOAD_OR_START && job_type_collapse(type, u) == JOB_START && u->refuse_manual_start))
                 return sd_bus_error_setf(error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only (it is configured to refuse manual start/stop).", u->id);
 
+        /* dbus-broker issues StartUnit for activation requests, so let's apply the same check
+         * used in signal_activation_request(). */
+        if (type == JOB_START && u->type == UNIT_SERVICE &&
+            SERVICE(u)->type == SERVICE_DBUS && !manager_dbus_is_running(u->manager))
+                return sd_bus_error_set(error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is not running.");
+
         r = sd_bus_message_new_method_return(message, &reply);
         if (r < 0)
                 return r;
index 9ce9ddc8f2a9056391adf1ca65a4291f5a2b1d23..2f5feeaec342ff5389a5fbfe8cab091ad6553ec5 100644 (file)
@@ -160,9 +160,8 @@ static int signal_activation_request(sd_bus_message *message, void *userdata, sd
                 return 0;
         }
 
-        if (manager_unit_inactive_or_pending(m, SPECIAL_DBUS_SERVICE) ||
-            manager_unit_inactive_or_pending(m, SPECIAL_DBUS_SOCKET)) {
-                r = sd_bus_error_set(&error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is shutting down.");
+        if (!manager_dbus_is_running(m)) {
+                r = sd_bus_error_set(&error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is not running.");
                 goto failed;
         }