]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: check if we skip the full setup on daemon-reexec
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 6 Apr 2023 17:14:12 +0000 (19:14 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 Apr 2023 22:53:14 +0000 (07:53 +0900)
A simple test case for issue #27106.

Resolves: #27139

test/test-functions
test/units/testsuite-01.service
test/units/testsuite-01.sh [new file with mode: 0755]

index de553afb5058a66d6280a1716eb6b7ebf7cba79e..35a10868b69e179d1b7b3d333d887d6e0f6797ce 100644 (file)
@@ -220,6 +220,7 @@ BASICTOOLS=(
     sh
     sleep
     stat
+    stty
     su
     sulogin
     sysctl
@@ -262,7 +263,6 @@ DEBUGTOOLS=(
     route
     sort
     strace
-    stty
     tty
     vi
     /usr/libexec/vi
index 1c81efc1b126a0ce9d2f83d56a92bd9b1fcf66d4..a55cc526a54edf69eebea85c95ffc7f9fafb5ea0 100644 (file)
@@ -1,10 +1,13 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 [Unit]
 Description=TEST-01-BASIC
-After=multi-user.target
+# Order the test unit after systemd-update-utmp-runlevel.service, since
+# the service doesn't play well with daemon-reexec
+# See: https://github.com/systemd/systemd/issues/27167
+After=multi-user.target systemd-update-utmp-runlevel.service
 Wants=systemd-resolved.service systemd-networkd.service
 
 [Service]
 ExecStartPre=rm -f /failed /testok
-ExecStart=sh -e -x -c 'systemctl --state=failed --no-legend --no-pager >/failed ; systemctl daemon-reload ; echo OK >/testok'
+ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
 Type=oneshot
diff --git a/test/units/testsuite-01.sh b/test/units/testsuite-01.sh
new file mode 100755 (executable)
index 0000000..469c5fe
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+STTY_ORIGINAL="$(stty --file=/dev/console --save)"
+
+at_exit() {
+    set +e
+    stty --file=/dev/console "${STTY_ORIGINAL:?}"
+}
+
+trap at_exit EXIT
+
+# Do one reexec beforehand to get /dev/console into some predictable state
+systemctl daemon-reexec
+
+# Check if we do skip the early setup when doing daemon-reexec
+# See: https://github.com/systemd/systemd/issues/27106
+#
+# Change a couple of console settings, do a reexec, and then check if our
+# changes persisted, since we reset the terminal stuff only on "full" reexec
+#
+# Relevant function: reset_terminal_fd() from terminal-util.cs
+stty --file=/dev/console brkint igncr inlcr istrip iuclc -icrnl -imaxbel -iutf8 \
+     kill ^K quit ^I
+STTY_NEW="$(stty --file=/dev/console --save)"
+systemctl daemon-reexec
+diff <(echo "$STTY_NEW") <(stty --file=/dev/console --save)
+
+if ! systemd-detect-virt -qc; then
+    # We also disable coredumps when doing a "full" reexec, so check for that too
+    sysctl -w kernel.core_pattern=dont-overwrite-me
+    systemctl daemon-reexec
+    diff <(echo dont-overwrite-me) <(sysctl --values kernel.core_pattern)
+fi
+
+# Collect failed units & do one daemon-reload to a basic sanity check
+systemctl --state=failed --no-legend --no-pager | tee /failed
+systemctl daemon-reload
+
+echo OK >/testok