]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: do not restart a service with Restart=always when ExecCondition fails
authorLuca Boccassi <luca.boccassi@microsoft.com>
Wed, 26 Jan 2022 19:00:25 +0000 (19:00 +0000)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Wed, 26 Jan 2022 19:02:11 +0000 (19:02 +0000)
When a Condition*= fails, and a service has Restart=always,
the service is not restarted.
Follow the same behaviour for ExecCondition= to avoid inconsistencies.

Fixes #22257

src/core/service.c
test/units/testsuite-51-repro-3.service [new file with mode: 0644]
test/units/testsuite-51.sh

index 88307fa1a5dea776ee59c1efff1fc54da1c468b5..905558af57c1522c25928f84a3d301f254cf36e8 100644 (file)
@@ -1798,7 +1798,7 @@ static bool service_shall_restart(Service *s, const char **reason) {
                 return false;
 
         case SERVICE_RESTART_ALWAYS:
-                return true;
+                return s->result != SERVICE_SKIP_CONDITION;
 
         case SERVICE_RESTART_ON_SUCCESS:
                 return s->result == SERVICE_SUCCESS;
diff --git a/test/units/testsuite-51-repro-3.service b/test/units/testsuite-51-repro-3.service
new file mode 100644 (file)
index 0000000..c68f93d
--- /dev/null
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+[Unit]
+Description=Issue 22257 Repro with Restart=always
+
+[Service]
+Type=simple
+Restart=always
+ExecCondition=/bin/false
+ExecStart=sleep 100
+RestartSec=1
index fbe9693f3a5ec660ca69dda0c949750999de3062..e603d953a4fd3e618767620bf3d5890f9fc6ef16 100755 (executable)
@@ -5,9 +5,11 @@ set -o pipefail
 
 systemctl start testsuite-51-repro-1
 systemctl start testsuite-51-repro-2
+systemctl start testsuite-51-repro-3
 sleep 5 # wait a bit in case there are restarts so we can count them below
 
 [[ "$(systemctl show testsuite-51-repro-1 -P NRestarts)" == "0" ]]
 [[ "$(systemctl show testsuite-51-repro-2 -P NRestarts)" == "0" ]]
+[[ "$(systemctl show testsuite-51-repro-3 -P NRestarts)" == "0" ]]
 
 touch /testok