core: Fail to start/stop/reload unit if frozen

Previously, unit_{start,stop,reload} would call the low-level cgroup
unfreeze function whenever a unit was started, stopped, or reloaded. It
did so with no error checking. This call would ultimately recurse up the
cgroup tree, and unfreeze all the parent cgroups of the unit, unless an
error occurred (in which case I have no idea what would happen...)

After the freeze/thaw rework in a previous commit, this can no longer
work. If we recursively thaw the parent cgroups of the unit, there may
be sibling units marked as PARENT_FROZEN which will no longer actually
have frozen parents. Fixing this is a lot more complicated than simply
disallowing start/stop/reload on a frozen unit

Fixes https://github.com/systemd/systemd/issues/15849
This commit is contained in:
Adrian Vovk
2024-01-30 11:18:16 -05:00
parent 16b6af6ade
commit 4cb2e6af8d
5 changed files with 33 additions and 30 deletions
+6 -25
View File
@@ -149,31 +149,6 @@ testcase_dbus_api() {
echo
}
testcase_jobs() {
local pid_before=
local pid_after=
echo "Test that it is possible to apply jobs on frozen units:"
systemctl start "${unit}"
dbus_freeze "${unit}"
check_freezer_state "${unit}" "frozen"
echo -n " - restart: "
pid_before=$(systemctl show -p MainPID "${unit}" --value)
systemctl restart "${unit}"
pid_after=$(systemctl show -p MainPID "${unit}" --value)
[ "$pid_before" != "$pid_after" ] && echo "[ OK ]"
dbus_freeze "${unit}"
check_freezer_state "${unit}" "frozen"
echo -n " - stop: "
timeout 5s systemctl stop "${unit}"
echo "[ OK ]"
echo
}
testcase_systemctl() {
echo "Test that systemctl freeze/thaw verbs:"
@@ -321,6 +296,11 @@ testcase_recursive() {
check_cgroup_state "$slice/$unit" 1
echo "[ OK ]"
echo -n " - can't stop a frozen unit: "
(! systemctl -q stop "$unit" )
echo "[ OK ]"
systemctl thaw "$unit"
systemctl stop "$unit"
systemctl stop "$slice"
@@ -368,6 +348,7 @@ testcase_preserve_state() {
check_freezer_state "$unit" "frozen"
echo "[ OK ]"
systemctl thaw "$unit"
systemctl stop "$unit"
systemctl stop "$slice"