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

A simple test case for issue #27106.

Resolves: #27139
This commit is contained in:
Frantisek Sumsal 2023-04-06 19:14:12 +02:00 committed by Yu Watanabe
parent d7805ff711
commit 61961e693d
3 changed files with 48 additions and 3 deletions

View 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

View 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

42
test/units/testsuite-01.sh Executable file
View file

@ -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