1
0
mirror of https://github.com/systemd/systemd.git synced 2025-05-27 21:05:55 +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 -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
# Check if we properly differentiate between a full systemd setup and a "light"
# version of it that's done during 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 -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)