1
0
mirror of https://github.com/systemd/systemd.git synced 2025-05-30 05:05:57 +03:00

test: check if we skip the full setup on daemon-reexec (again)

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.
This commit is contained in:
Frantisek Sumsal 2023-04-07 13:58:49 +02:00 committed by Yu Watanabe
parent b6b446cb62
commit 9acb7ee425

View File

@ -3,33 +3,29 @@
set -eux set -eux
set -o pipefail set -o pipefail
STTY_ORIGINAL="$(stty --file=/dev/console --save)" # Check if we properly differentiate between a full systemd setup and a "light"
# version of it that's done during daemon-reexec
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 # See: https://github.com/systemd/systemd/issues/27106
# if systemd-detect-virt -q --container; then
# Change a couple of console settings, do a reexec, and then check if our # We initialize /run/systemd/container only during a full setup
# changes persisted, since we reset the terminal stuff only on "full" reexec test -e /run/systemd/container
# cp -afv /run/systemd/container /tmp/container
# Relevant function: reset_terminal_fd() from terminal-util.cs rm -fv /run/systemd/container
stty --file=/dev/console brkint igncr inlcr istrip iuclc -icrnl -imaxbel -iutf8 \ systemctl daemon-reexec
kill ^K quit ^I test ! -e /run/systemd/container
STTY_NEW="$(stty --file=/dev/console --save)" cp -afv /tmp/container /run/systemd/container
systemctl daemon-reexec else
diff <(echo "$STTY_NEW") <(stty --file=/dev/console --save) # 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 only during a full setup
# We also disable coredumps when doing a "full" reexec, so check for that too
sysctl -w kernel.core_pattern=dont-overwrite-me sysctl -w kernel.core_pattern=dont-overwrite-me
systemctl daemon-reexec systemctl daemon-reexec
diff <(echo dont-overwrite-me) <(sysctl --values kernel.core_pattern) diff <(echo dont-overwrite-me) <(sysctl --values kernel.core_pattern)