core: increment start limit counter only when we can start the unit

Otherwise, e.g. requesting to start a unit that is under stopping may
enter the failed state.

This makes
- rename .can_start() -> .test_startable(), and make it allow to return
  boolean and refuse to start units when it returns false,
- refuse earlier to start units that are in the deactivating state, so
  several redundant conditions in .start() can be dropped,
- move checks for unit states mapped to UNIT_ACTIVATING from .start() to
  .test_startable().

Fixes #39247.
This commit is contained in:
Yu Watanabe
2025-10-23 15:51:28 +02:00
committed by Mike Yuan
parent c05758663b
commit 8eefd0f4de
10 changed files with 94 additions and 85 deletions
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux
set -o pipefail
# For issue #39247.
at_exit() {
set +e
rm -rf /run/systemd/system/systemd-resolved.service.d/
systemctl daemon-reload
systemctl restart systemd-resolved.service
}
trap at_exit EXIT
mkdir -p /run/systemd/system/systemd-resolved.service.d/
cat >/run/systemd/system/systemd-resolved.service.d/99-start-limit.conf <<EOF
[Unit]
StartLimitBurst=5
StartLimitInterval=30
[Service]
ExecStopPost=sleep 10
EOF
systemctl daemon-reload
systemctl restart systemd-resolved.service
systemctl reset-failed systemd-resolved.service
systemctl status --no-pager systemd-resolved.service
systemctl show systemd-resolved.service | grep StartLimit
for i in {1..5}; do
echo "Start #$i"
systemctl stop --no-block systemd-resolved.service
if ! resolvectl; then
journalctl -o short-monotonic --no-hostname --no-pager -u systemd-resolved.service -n 15
exit 1
fi
done