diff --git a/test/test-functions b/test/test-functions index de553afb505..35a10868b69 100644 --- a/test/test-functions +++ b/test/test-functions @@ -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 diff --git a/test/units/testsuite-01.service b/test/units/testsuite-01.service index 1c81efc1b12..a55cc526a54 100644 --- a/test/units/testsuite-01.service +++ b/test/units/testsuite-01.service @@ -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 index 00000000000..469c5fe2784 --- /dev/null +++ b/test/units/testsuite-01.sh @@ -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