core: do not start watchdog for frozen service on daemon-reload/-reexec (#38553)

Fixes #38551.
This commit is contained in:
Yu Watanabe
2025-08-14 01:18:50 +09:00
committed by GitHub
3 changed files with 37 additions and 40 deletions
-3
View File
@@ -2088,9 +2088,6 @@ static int unit_update_cgroup(
if (!UNIT_HAS_CGROUP_CONTEXT(u))
return 0;
if (u->freezer_state != FREEZER_RUNNING)
return log_unit_error_errno(u, SYNTHETIC_ERRNO(EBUSY), "Cannot realize cgroup for frozen unit.");
r = unit_get_cgroup_path_with_fallback(u, &cgroup);
if (r < 0)
return log_unit_error_errno(u, r, "Failed to get cgroup path: %m");
+2 -1
View File
@@ -1418,7 +1418,8 @@ static int service_coldplug(Unit *u) {
SERVICE_DEAD_RESOURCES_PINNED))
(void) unit_setup_exec_runtime(u);
if (IN_SET(s->deserialized_state, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD, SERVICE_RELOAD_SIGNAL, SERVICE_RELOAD_NOTIFY, SERVICE_REFRESH_EXTENSIONS, SERVICE_MOUNTING))
if (IN_SET(s->deserialized_state, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD, SERVICE_RELOAD_SIGNAL, SERVICE_RELOAD_NOTIFY, SERVICE_REFRESH_EXTENSIONS, SERVICE_MOUNTING) &&
freezer_state_finish(u->freezer_state) == FREEZER_RUNNING)
service_start_watchdog(s);
if (UNIT_ISSET(s->accept_socket)) {
+35 -36
View File
@@ -69,42 +69,18 @@ dbus_thaw_unit() {
"$1"
}
dbus_can_freeze() {
local name object_path suffix
suffix="${1##*.}"
name="${1%".$suffix"}"
object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
busctl get-property \
org.freedesktop.systemd1 \
"${object_path}" \
org.freedesktop.systemd1.Unit \
CanFreeze
}
check_freezer_state() {
local name object_path suffix
local name state expected
suffix="${1##*.}"
name="${1%".$suffix"}"
object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
name="${1:?}"
expected="${2:?}"
for _ in {0..10}; do
state=$(busctl get-property \
org.freedesktop.systemd1 \
"${object_path}" \
org.freedesktop.systemd1.Unit \
FreezerState | cut -d " " -f2 | tr -d '"')
# Ignore the intermediate freezing & thawing states in case we check the unit state too quickly.
timeout 10 bash -c "while [[ \"\$(systemctl show \"$name\" --property FreezerState --value)\" =~ (freezing|thawing) ]]; do sleep .5; done"
# Ignore the intermediate freezing & thawing states in case we check
# the unit state too quickly
[[ "$state" =~ ^(freezing|thawing) ]] || break
sleep .5
done
[ "$state" = "$2" ] || {
echo "error: unexpected freezer state, expected: $2, actual: $state" >&2
state="$(systemctl show "$name" --property FreezerState --value)"
[[ "$state" = "$expected" ]] || {
echo "error: unexpected freezer state, expected: $expected, actual: $state" >&2
exit 1
}
}
@@ -146,9 +122,8 @@ testcase_dbus_api() {
check_cgroup_state "$unit" 0
echo "[ OK ]"
echo -n " - CanFreeze(): "
output=$(dbus_can_freeze "${unit}")
[ "$output" = "b true" ]
echo -n " - CanFreeze: "
[[ "$(systemctl show "${unit}" --property=CanFreeze --value)" == 'yes' ]]
echo "[ OK ]"
echo
@@ -367,12 +342,36 @@ testcase_watchdog() {
/bin/bash -c 'systemd-notify --ready; while true; do systemd-notify WATCHDOG=1; sleep 1; done'
systemctl freeze "$unit"
check_freezer_state "$unit" "frozen"
sleep 6
check_freezer_state "$unit" "frozen"
systemctl thaw "$unit"
check_freezer_state "$unit" "running"
sleep 6
check_freezer_state "$unit" "running"
systemctl is-active "$unit"
systemctl freeze "$unit"
check_freezer_state "$unit" "frozen"
systemctl daemon-reload
sleep 6
check_freezer_state "$unit" "frozen"
systemctl thaw "$unit"
check_freezer_state "$unit" "running"
sleep 6
check_freezer_state "$unit" "running"
systemctl is-active "$unit"
systemctl freeze "$unit"
check_freezer_state "$unit" "frozen"
systemctl daemon-reexec
sleep 6
check_freezer_state "$unit" "frozen"
systemctl thaw "$unit"
check_freezer_state "$unit" "running"
sleep 6
check_freezer_state "$unit" "running"
systemctl is-active "$unit"