summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2020-06-10 01:18:00 -0700
committerThe Plumber <50238977+systemd-rhel-bot@users.noreply.github.com>2020-06-16 12:45:42 +0200
commit41346615264e01c6ff6118e09cf3ac4b4c71e89d (patch)
tree121dd1be20cb7d6a74cbcb8af44be0d3e8d020e0
parent0065f2bf838dd0c24ec7be41439b4c0ba650029c (diff)
downloadsystemd-41346615264e01c6ff6118e09cf3ac4b4c71e89d.tar.gz
core: don't consider SERVICE_SKIP_CONDITION for abnormal or failure restarts
Fixes: #16115 (cherry picked from commit bb9244781c6fc7608f7cac910269f8987b8adc01) Related: #1737283
-rw-r--r--src/core/service.c4
l---------test/TEST-51-ISSUE-16115/Makefile1
-rw-r--r--test/TEST-51-ISSUE-16115/repro-1.service9
-rw-r--r--test/TEST-51-ISSUE-16115/repro-2.service9
-rwxr-xr-xtest/TEST-51-ISSUE-16115/test.sh46
-rwxr-xr-xtest/TEST-51-ISSUE-16115/testsuite.sh19
-rw-r--r--test/test-functions2
7 files changed, 87 insertions, 3 deletions
diff --git a/src/core/service.c b/src/core/service.c
index 92be4280f6..1d98ee37fd 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1637,10 +1637,10 @@ static bool service_shall_restart(Service *s) {
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
index 0000000000..e9f93b1104
--- /dev/null
+++ b/test/TEST-51-ISSUE-16115/Makefile
@@ -0,0 +1 @@
+../TEST-01-BASIC/Makefile \ No newline at end of file
diff --git a/test/TEST-51-ISSUE-16115/repro-1.service b/test/TEST-51-ISSUE-16115/repro-1.service
new file mode 100644
index 0000000000..96ecabe234
--- /dev/null
+++ b/test/TEST-51-ISSUE-16115/repro-1.service
@@ -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/TEST-51-ISSUE-16115/repro-2.service b/test/TEST-51-ISSUE-16115/repro-2.service
new file mode 100644
index 0000000000..6015ad8080
--- /dev/null
+++ b/test/TEST-51-ISSUE-16115/repro-2.service
@@ -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/TEST-51-ISSUE-16115/test.sh b/test/TEST-51-ISSUE-16115/test.sh
new file mode 100755
index 0000000000..09ac96ffce
--- /dev/null
+++ b/test/TEST-51-ISSUE-16115/test.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+set -e
+TEST_DESCRIPTION="Test ExecCondition= does not restart on abnormal or failure"
+. $TEST_BASE_DIR/test-functions
+
+test_setup() {
+ create_empty_image
+ mkdir -p $TESTDIR/root
+ mount ${LOOPDEV}p1 $TESTDIR/root
+
+ (
+ LOG_LEVEL=5
+ eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
+
+ setup_basic_environment
+
+ # mask some services that we do not want to run in these tests
+ ln -fs /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
+ ln -fs /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
+ ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.service
+ ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
+ ln -fs /dev/null $initdir/etc/systemd/system/systemd-resolved.service
+ ln -fs /dev/null $initdir/etc/systemd/system/systemd-machined.service
+
+ # setup the testsuite service
+ cat >$initdir/etc/systemd/system/testsuite.service <<EOF
+[Unit]
+Description=Testsuite service
+
+[Service]
+ExecStart=/testsuite.sh
+Type=oneshot
+EOF
+
+ cp testsuite.sh $initdir/
+ cp repro-?.service $initdir/etc/systemd/system/
+
+ setup_testsuite
+ )
+ setup_nspawn_root
+
+ ddebug "umount $TESTDIR/root"
+ umount $TESTDIR/root
+}
+
+do_test "$@"
diff --git a/test/TEST-51-ISSUE-16115/testsuite.sh b/test/TEST-51-ISSUE-16115/testsuite.sh
new file mode 100755
index 0000000000..695896ab7b
--- /dev/null
+++ b/test/TEST-51-ISSUE-16115/testsuite.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+set -ex
+set -o pipefail
+
+systemd-analyze log-level debug
+systemd-analyze log-target console
+
+systemctl start repro-1
+systemctl start repro-2
+sleep 5 # wait a bit in case there are restarts so we can count them below
+
+[[ "$(systemctl show repro-1 --value -p NRestarts)" == "0" ]]
+[[ "$(systemctl show repro-2 --value -p NRestarts)" == "0" ]]
+
+systemd-analyze log-level info
+
+echo OK > /testok
+
+exit 0
diff --git a/test/test-functions b/test/test-functions
index 7c4230b078..4d7832b1fb 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -23,7 +23,7 @@ fi
PATH_TO_INIT=$ROOTLIBDIR/systemd
-BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs"
+BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs env"
DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find"
STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"