#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later set -eux set -o pipefail if systemd-detect-virt -cq; then echo "This test requires a VM, skipping the test" | tee --append /skipped exit 0 fi if [[ ! -x /usr/lib/systemd/systemd-bsod ]]; then echo "systemd-bsod is not installed, skipping the test" | tee --append /skipped exit 0 fi # shellcheck disable=SC2317 at_exit() { local EC=$? if [[ $EC -ne 0 ]] && [[ -e /tmp/console.dump ]]; then cat /tmp/console.dump fi if mountpoint -q /var/log/journal; then # In order to preserve the journal from the just run test we need to do a little dance, as # --relinquish-var is not a "true" opposite of --flush, meaning that it won't move the existing # journal(s) from /var/log/ to /run/log/. To do that, let's rotate the journal first, so all # important bits are in the archived journal(s)... journalctl --rotate # ...then instruct sd-journald to write further entries to the runtime journal... journalctl --relinquish-var # ...make sure there are no outstanding writes to the persistent journal that might block us from # unmounting the tmpfs... journalctl --sync # ...move the archived journals to the runtime storage... mv -v "/var/log/journal/$(/run/systemd/system/systemd-bsod.service.d/99-override.conf systemctl daemon-reload systemctl start systemd-bsod systemd-cat -p emerg echo "Service emergency message" vcs_dump_and_check "Service emergency message" systemctl status systemd-bsod systemctl stop systemd-bsod # Wipe the journal journalctl --vacuum-size=1 --rotate (! journalctl -q -b -p emerg --grep .) # Same as above, but make sure the service responds to signals even when there are # no "emerg" messages, see systemd/systemd#30084 (! systemctl is-active systemd-bsod) systemctl start systemd-bsod timeout 5s bash -xec 'until systemctl is-active systemd-bsod; do sleep .5; done' timeout 5s systemctl stop systemd-bsod timeout 5s bash -xec 'while systemctl is-active systemd-bsod; do sleep .5; done'