From abb99360d3317980fc8843f79b67c763cd4a9a2c Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 26 Jan 2022 19:00:25 +0000 Subject: [PATCH] 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 --- src/core/service.c | 2 +- test/units/testsuite-51-repro-3.service | 10 ++++++++++ test/units/testsuite-51.sh | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/units/testsuite-51-repro-3.service diff --git a/src/core/service.c b/src/core/service.c index 88307fa1a5..905558af57 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 0000000000..c68f93d11d --- /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 fbe9693f3a..e603d953a4 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 -- 2.25.1