]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: don't consider SERVICE_SKIP_CONDITION for abnormal or failure restarts
authorAnita Zhang <the.anitazha@gmail.com>
Wed, 10 Jun 2020 08:18:00 +0000 (01:18 -0700)
committerLennart Poettering <lennart@poettering.net>
Wed, 10 Jun 2020 15:12:55 +0000 (17:12 +0200)
Fixes: #16115
src/core/service.c
test/TEST-51-ISSUE-16115/Makefile [new symlink]
test/TEST-51-ISSUE-16115/test.sh [new file with mode: 0755]
test/units/testsuite-51-repro-1.service [new file with mode: 0644]
test/units/testsuite-51-repro-2.service [new file with mode: 0644]
test/units/testsuite-51.service [new file with mode: 0644]
test/units/testsuite-51.sh [new file with mode: 0755]

index 8b3fd2e5a44273c3a9d1344c3fdf0544c789c41a..3daf21296ae9990a3c303489e1429ce1561311f1 100644 (file)
@@ -1703,10 +1703,10 @@ static bool service_shall_restart(Service *s, const char **reason) {
                 return s->result == SERVICE_SUCCESS;
 
         case SERVICE_RESTART_ON_FAILURE:
-                return s->result != SERVICE_SUCCESS;
+                return !IN_SET(s->result, SERVICE_SUCCESS, SERVICE_SKIP_CONDITION);
 
         case SERVICE_RESTART_ON_ABNORMAL:
-                return !IN_SET(s->result, SERVICE_SUCCESS, SERVICE_FAILURE_EXIT_CODE);
+                return !IN_SET(s->result, SERVICE_SUCCESS, SERVICE_FAILURE_EXIT_CODE, SERVICE_SKIP_CONDITION);
 
         case SERVICE_RESTART_ON_WATCHDOG:
                 return s->result == SERVICE_FAILURE_WATCHDOG;
diff --git a/test/TEST-51-ISSUE-16115/Makefile b/test/TEST-51-ISSUE-16115/Makefile
new file mode 120000 (symlink)
index 0000000..e9f93b1
--- /dev/null
@@ -0,0 +1 @@
+../TEST-01-BASIC/Makefile
\ No newline at end of file
diff --git a/test/TEST-51-ISSUE-16115/test.sh b/test/TEST-51-ISSUE-16115/test.sh
new file mode 100755 (executable)
index 0000000..eca235c
--- /dev/null
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+set -e
+TEST_DESCRIPTION="Test ExecCondition= does not restart on abnormal or failure"
+. $TEST_BASE_DIR/test-functions
+
+do_test "$@" 51
diff --git a/test/units/testsuite-51-repro-1.service b/test/units/testsuite-51-repro-1.service
new file mode 100644 (file)
index 0000000..96ecabe
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Description=Issue 16115 Repro with on-abnormal
+
+[Service]
+Type=simple
+Restart=on-abnormal
+ExecCondition=/bin/false
+ExecStart=sleep 100
+RestartSec=1
diff --git a/test/units/testsuite-51-repro-2.service b/test/units/testsuite-51-repro-2.service
new file mode 100644 (file)
index 0000000..6015ad8
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Description=Issue 16115 Repro with on-failure
+
+[Service]
+Type=simple
+Restart=on-failure
+ExecCondition=/bin/false
+ExecStart=sleep 100
+RestartSec=1
diff --git a/test/units/testsuite-51.service b/test/units/testsuite-51.service
new file mode 100644 (file)
index 0000000..903dc9a
--- /dev/null
@@ -0,0 +1,7 @@
+[Unit]
+Description=TEST-51-ISSUE-16115
+
+[Service]
+ExecStartPre=rm -f /failed /testok
+ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
+Type=oneshot
diff --git a/test/units/testsuite-51.sh b/test/units/testsuite-51.sh
new file mode 100755 (executable)
index 0000000..246412a
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+set -ex
+set -o pipefail
+
+systemctl start testsuite-51-repro-1
+systemctl start testsuite-51-repro-2
+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" ]]
+
+touch /testok