From: Luca Boccassi Date: Wed, 26 Jan 2022 19:00:25 +0000 (+0000) Subject: core: do not restart a service with Restart=always when ExecCondition fails X-Git-Tag: v251-rc1~447^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=abb99360d3317980fc8843f79b67c763cd4a9a2c;p=thirdparty%2Fsystemd.git core: do not restart a service with Restart=always when ExecCondition fails 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 --- diff --git a/src/core/service.c b/src/core/service.c index 88307fa1a5d..905558af57c 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -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 index 00000000000..c68f93d11d7 --- /dev/null +++ b/test/units/testsuite-51-repro-3.service @@ -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 diff --git a/test/units/testsuite-51.sh b/test/units/testsuite-51.sh index fbe9693f3a5..e603d953a4f 100755 --- a/test/units/testsuite-51.sh +++ b/test/units/testsuite-51.sh @@ -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