]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: check if we skip the full setup on daemon-reexec (again)
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 7 Apr 2023 11:58:49 +0000 (13:58 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 8 Apr 2023 04:55:29 +0000 (13:55 +0900)
My original assumption in 61961e693d was wrong, since we do reset
/dev/console during reexec (see make_console_stdio()), so the test was
quite racy. Let's replace it with something, hopefully, more reliable.

Follow-up to 61961e693d.

test/units/testsuite-01.sh

index 469c5fe27846c32ca1a9bbc06c00bfe583af498a..ebb8a78128a4c5b6fbfe9a4a917aeba06d5141b8 100755 (executable)
@@ -3,33 +3,29 @@
 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
+# Check if we properly differentiate between a full systemd setup and a "light"
+# version of it that's done during daemon-reexec
 #
-# 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)
+# See: https://github.com/systemd/systemd/issues/27106
+if systemd-detect-virt -q --container; then
+    # We initialize /run/systemd/container only during a full setup
+    test -e /run/systemd/container
+    cp -afv /run/systemd/container /tmp/container
+    rm -fv /run/systemd/container
+    systemctl daemon-reexec
+    test ! -e /run/systemd/container
+    cp -afv /tmp/container /run/systemd/container
+else
+    # We bring the loopback netdev up only during a full setup, so it should
+    # not get brought back up during reexec if we disable it beforehand
+    [[ "$(ip -o link show lo)" =~ LOOPBACK,UP ]]
+    ip link set lo down
+    [[ "$(ip -o link show lo)" =~ state\ DOWN ]]
+    systemctl daemon-reexec
+    [[ "$(ip -o link show lo)" =~ state\ DOWN ]]
+    ip link set lo up
 
-if ! systemd-detect-virt -qc; then
-    # We also disable coredumps when doing a "full" reexec, so check for that too
+    # We also disable coredumps only during a full setup
     sysctl -w kernel.core_pattern=dont-overwrite-me
     systemctl daemon-reexec
     diff <(echo dont-overwrite-me) <(sysctl --values kernel.core_pattern)