summaryrefslogtreecommitdiffstats
path: root/src/core/dbus-unit.c
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2023-05-08 18:07:45 +0200
committerMike Yuan <me@yhndnzj.com>2023-05-08 19:42:25 +0200
commit53964fd26b4a01191609ffc064aa8ccccd28e377 (patch)
treece6b975ba328f637c1f17d9ff831bd4401d197d7 /src/core/dbus-unit.c
parentcore/manager: export manager_dbus_is_running (diff)
downloadsystemd-53964fd26b4a01191609ffc064aa8ccccd28e377.tar.xz
systemd-53964fd26b4a01191609ffc064aa8ccccd28e377.zip
core: refuse dbus activation if dbus is not running
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
Diffstat (limited to 'src/core/dbus-unit.c')
-rw-r--r--src/core/dbus-unit.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index dd36cae860..5b89c76586 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -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;