systemd/test/units/TEST-74-AUX-UTILS.coredump.sh

228 lines
9.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux
set -o pipefail
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
# Make sure the binary name fits into 15 characters
CORE_TEST_BIN="/tmp/test-dump"
CORE_TEST_UNPRIV_BIN="/tmp/test-usr-dump"
MAKE_DUMP_SCRIPT="/tmp/make-dump"
# Unset $PAGER so we don't have to use --no-pager everywhere
export PAGER=
at_exit() {
rm -fv -- "$CORE_TEST_BIN" "$CORE_TEST_UNPRIV_BIN" "$MAKE_DUMP_SCRIPT"
}
trap at_exit EXIT
if systemd-detect-virt -cq; then
echo "Running in a container, skipping the systemd-coredump test..."
exit 0
fi
test: rotate journal before storing coredumps Hopefully fixes the failure like https://jenkins-systemd.apps.ocp.cloud.ci.centos.org/job/upstream-vagrant-archlinux-sanitizers/2558/ --- [ 66.708894] testsuite-74.sh[728]: + coredumpctl --json=off [ 66.709344] testsuite-74.sh[826]: TIME PID UID GID SIG COREFILE EXE SIZE [ 66.709773] testsuite-74.sh[826]: Tue 2023-05-23 22:10:17 UTC 739 0 0 SIGTRAP journal /tmp/test-dump - [ 66.711134] testsuite-74.sh[826]: Tue 2023-05-23 22:10:18 UTC 747 0 0 SIGABRT journal /tmp/test-dump - [ 66.711789] testsuite-74.sh[826]: Tue 2023-05-23 22:10:19 UTC 763 0 0 SIGTRAP present /tmp/test-dump 53.5K [ 66.712460] testsuite-74.sh[826]: Tue 2023-05-23 22:10:20 UTC 776 0 0 SIGABRT present /tmp/test-dump 53.3K [ 66.713505] testsuite-74.sh[728]: + coredumpctl --root=/ [ 66.714144] testsuite-74.sh[828]: TIME PID UID GID SIG COREFILE EXE SIZE [ 66.714535] testsuite-74.sh[828]: Tue 2023-05-23 22:10:17 UTC 739 0 0 SIGTRAP journal /tmp/test-dump - [ 66.715208] testsuite-74.sh[828]: Tue 2023-05-23 22:10:18 UTC 747 0 0 SIGABRT journal /tmp/test-dump - [ 66.715907] testsuite-74.sh[828]: Tue 2023-05-23 22:10:19 UTC 763 0 0 SIGTRAP present /tmp/test-dump 53.5K [ 66.716565] testsuite-74.sh[828]: Tue 2023-05-23 22:10:20 UTC 776 0 0 SIGABRT present /tmp/test-dump 53.3K [ 66.717494] testsuite-74.sh[728]: + coredumpctl --directory=/var/log/journal [ 66.718188] testsuite-74.sh[830]: TIME PID UID GID SIG COREFILE EXE SIZE [ 66.882072] testsuite-74.sh[830]: Tue 2023-05-23 22:10:17 UTC 739 0 0 SIGTRAP journal /tmp/test-dump - [ 66.882642] testsuite-74.sh[830]: Tue 2023-05-23 22:10:18 UTC 747 0 0 SIGABRT journal /tmp/test-dump - [ 66.883450] testsuite-74.sh[830]: Tue 2023-05-23 22:10:19 UTC 763 0 0 SIGTRAP present /tmp/test-dump 53.5K [ 66.883944] testsuite-74.sh[830]: Tue 2023-05-23 22:10:20 UTC 776 0 0 SIGABRT present /tmp/test-dump 53.3K [ 66.885448] testsuite-74.sh[728]: + coredumpctl --file=/var/log/journal/2e1ed84be19a4e22adfc99ad849be1f6/system.journal [ 66.885989] testsuite-74.sh[728]: + at_exit [ 66.894162] coredumpctl[833]: No coredumps found. ---
2023-05-24 01:31:41 +00:00
# To make all coredump entries stored in system.journal.
journalctl --rotate
# Check that we're the ones to receive coredumps
sysctl kernel.core_pattern | grep systemd-coredump
# Prepare "fake" binaries for coredumps, so we can properly exercise
# the matching stuff too
cp -vf /bin/sleep "${CORE_TEST_BIN:?}"
cp -vf /bin/sleep "${CORE_TEST_UNPRIV_BIN:?}"
# Simple script that spawns given "fake" binary and then kills it with
# given signal
cat >"${MAKE_DUMP_SCRIPT:?}" <<\EOF
#!/bin/bash -ex
bin="${1:?}"
sig="${2:?}"
ulimit -c unlimited
"$bin" infinity &
pid=$!
test: sync with the fake binary before killing it On faster machines we might be too fast and kill the fake binary during fork() which then makes kernel report a "wrong" binary in the coredump, e.g.: [ 31.408078] testsuite-74.sh[548]: + /tmp/make-dump /tmp/test-dump SIGTRAP [ 31.409720] testsuite-74.sh[560]: + bin=/tmp/test-dump [ 31.409720] testsuite-74.sh[560]: + sig=SIGTRAP [ 31.409720] testsuite-74.sh[560]: + ulimit -c unlimited [ 31.409720] testsuite-74.sh[560]: + pid=561 [ 31.409720] testsuite-74.sh[560]: + sleep 1 [ 31.409720] testsuite-74.sh[560]: + kill -s SIGTRAP 561 [ 31.409720] testsuite-74.sh[560]: + wait 561 [ 31.491757] systemd[1]: Created slice system-systemd\x2dcoredump.slice. [ 31.524488] systemd[1]: Started systemd-coredump@0-563-0.service. [ 31.616372] systemd-coredump[564]: [🡕] Process 561 (make-dump) of user 0 dumped core. Stack trace of thread 561: #0 0x00007ff86bb49af7 _Fork (libc.so.6 + 0xd4af7) #1 0x00007ff86bb4965f __libc_fork (libc.so.6 + 0xd465f) #2 0x000055e88011b0ad make_child (bash + 0x550ad) #3 0x000055e8800fd05f n/a (bash + 0x3705f) #4 0x000055e880100116 execute_command_internal (bash + 0x3a116) #5 0x000055e8801011f2 execute_command_internal (bash + 0x3b1f2) #6 0x000055e8801025b6 execute_command (bash + 0x3c5b6) #7 0x000055e8800f134b reader_loop (bash + 0x2b34b) #8 0x000055e8800e757d main (bash + 0x2157d) #9 0x00007ff86ba98850 n/a (libc.so.6 + 0x23850) #10 0x00007ff86ba9890a __libc_start_main (libc.so.6 + 0x2390a) #11 0x000055e8800e83b5 _start (bash + 0x223b5) ELF object binary architecture: AMD x86-64 [ 31.666617] testsuite-74.sh[560]: /tmp/make-dump: line 12: 561 Trace/breakpoint trap (core dumped) "$bin" infinity ... $ coredumpctl list --file system.journal TIME PID UID GID SIG COREFILE EXE SIZE Fri 2023-06-02 10:42:10 CEST 561 0 0 SIGTRAP journal /usr/bin/bash - Fri 2023-06-02 10:42:11 CEST 570 0 0 SIGABRT journal /tmp/test-dump - Fri 2023-06-02 10:42:12 CEST 582 0 0 SIGTRAP missing /tmp/test-dump - Fri 2023-06-02 10:42:13 CEST 593 0 0 SIGABRT missing /tmp/test-dump -
2023-06-02 11:24:32 +00:00
# Sync with the "fake" binary, so we kill it once it's fully forked off,
# otherwise we might kill it during fork and kernel would then report
# "wrong" binary name (i.e. $MAKE_DUMP_SCRIPT instead of $CORE_TEST_BIN).
# In this case, wait until the "fake" binary (sleep in this case) enters
# the "interruptible sleep" state, at which point it should be ready
# to be sacrificed.
for _ in {0..9}; do
read -ra self_stat <"/proc/$pid/stat"
[[ "${self_stat[2]}" == S ]] && break
sleep .5
done
kill -s "$sig" "$pid"
# This should always fail
! wait "$pid"
EOF
chmod +x "$MAKE_DUMP_SCRIPT"
# Privileged stuff
[[ "$(id -u)" -eq 0 ]]
# Trigger a couple of coredumps
"$MAKE_DUMP_SCRIPT" "$CORE_TEST_BIN" "SIGTRAP"
"$MAKE_DUMP_SCRIPT" "$CORE_TEST_BIN" "SIGABRT"
# In the tests we store the coredumps in journals, so let's generate a couple
# with Storage=external as well
mkdir -p /run/systemd/coredump.conf.d/
printf '[Coredump]\nStorage=external' >/run/systemd/coredump.conf.d/99-external.conf
"$MAKE_DUMP_SCRIPT" "$CORE_TEST_BIN" "SIGTRAP"
"$MAKE_DUMP_SCRIPT" "$CORE_TEST_BIN" "SIGABRT"
rm -fv /run/systemd/coredump.conf.d/99-external.conf
# Wait a bit for the coredumps to get processed
timeout 30 bash -c "while [[ \$(coredumpctl list -q --no-legend $CORE_TEST_BIN | wc -l) -lt 4 ]]; do sleep 1; done"
test: bump the container boot timeout when running w/o acceleration With plain QEMU on a saturated AWS region we might just barely miss the timeout window, causing unexpected test fails: [ 688.681324] systemd-nspawn[1332]: [ OK ] Finished systemd-user-sessions.service. [ 689.451267] systemd-nspawn[1332]: [ OK ] Started console-getty.service. [ 689.572874] systemd-nspawn[1332]: [ OK ] Reached target getty.target. [ 693.634609] testsuite-74.sh[1223]: + at_exit [ 693.634609] testsuite-74.sh[1223]: + rm -fv -- /tmp/test-dump /tmp/test-usr-dump /tmp/make-dump [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-usr-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/make-dump' [ 693.951114] testsuite-74.sh[670]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed' [ 693.951114] testsuite-74.sh[670]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed [ 693.951114] testsuite-74.sh[670]: + return 1 [ 694.659094] systemd[1]: testsuite-74.service: Main process exited, code=exited, status=1/FAILURE [ 694.719563] systemd[1]: testsuite-74.service: Failed with result 'exit-code'. [ 694.882069] systemd[1]: Failed to start testsuite-74.service. [ 695.574445] systemd[1]: Reached target testsuite.target. [ 696.174844] systemd[1]: Starting end.service... [ 699.509408] systemd-nspawn[1332]: [ 699.509408] systemd-nspawn[1332]: CentOS Stream 9 [ 699.509408] systemd-nspawn[1332]: Kernel 5.14.0-432.el9.x86_64 on an x86_64 (pts/0) [ 699.509408] systemd-nspawn[1332]: Also, move the rest of container the setup for the user xattrs test into the condition, since doing it without the actual test is pretty pointless.
2024-03-28 14:15:06 +00:00
if cgroupfs_supports_user_xattrs; then
# Make sure we can forward crashes back to containers
CONTAINER="TEST-74-AUX-UTILS-container"
test: bump the container boot timeout when running w/o acceleration With plain QEMU on a saturated AWS region we might just barely miss the timeout window, causing unexpected test fails: [ 688.681324] systemd-nspawn[1332]: [ OK ] Finished systemd-user-sessions.service. [ 689.451267] systemd-nspawn[1332]: [ OK ] Started console-getty.service. [ 689.572874] systemd-nspawn[1332]: [ OK ] Reached target getty.target. [ 693.634609] testsuite-74.sh[1223]: + at_exit [ 693.634609] testsuite-74.sh[1223]: + rm -fv -- /tmp/test-dump /tmp/test-usr-dump /tmp/make-dump [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-usr-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/make-dump' [ 693.951114] testsuite-74.sh[670]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed' [ 693.951114] testsuite-74.sh[670]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed [ 693.951114] testsuite-74.sh[670]: + return 1 [ 694.659094] systemd[1]: testsuite-74.service: Main process exited, code=exited, status=1/FAILURE [ 694.719563] systemd[1]: testsuite-74.service: Failed with result 'exit-code'. [ 694.882069] systemd[1]: Failed to start testsuite-74.service. [ 695.574445] systemd[1]: Reached target testsuite.target. [ 696.174844] systemd[1]: Starting end.service... [ 699.509408] systemd-nspawn[1332]: [ 699.509408] systemd-nspawn[1332]: CentOS Stream 9 [ 699.509408] systemd-nspawn[1332]: Kernel 5.14.0-432.el9.x86_64 on an x86_64 (pts/0) [ 699.509408] systemd-nspawn[1332]: Also, move the rest of container the setup for the user xattrs test into the condition, since doing it without the actual test is pretty pointless.
2024-03-28 14:15:06 +00:00
mkdir -p "/var/lib/machines/$CONTAINER"
mkdir -p "/run/systemd/system/systemd-nspawn@$CONTAINER.service.d"
# Bind-mounting /etc into the container kinda defeats the purpose of --volatile=,
# but we need the ASan-related overrides scattered across /etc
cat > "/run/systemd/system/systemd-nspawn@$CONTAINER.service.d/override.conf" <<EOF
[Service]
ExecStart=
ExecStart=systemd-nspawn --quiet --link-journal=try-guest --keep-unit --machine=%i --boot \
--volatile=yes --directory=/ --bind-ro=/etc --inaccessible=/etc/machine-id
EOF
test: bump the container boot timeout when running w/o acceleration With plain QEMU on a saturated AWS region we might just barely miss the timeout window, causing unexpected test fails: [ 688.681324] systemd-nspawn[1332]: [ OK ] Finished systemd-user-sessions.service. [ 689.451267] systemd-nspawn[1332]: [ OK ] Started console-getty.service. [ 689.572874] systemd-nspawn[1332]: [ OK ] Reached target getty.target. [ 693.634609] testsuite-74.sh[1223]: + at_exit [ 693.634609] testsuite-74.sh[1223]: + rm -fv -- /tmp/test-dump /tmp/test-usr-dump /tmp/make-dump [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-usr-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/make-dump' [ 693.951114] testsuite-74.sh[670]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed' [ 693.951114] testsuite-74.sh[670]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed [ 693.951114] testsuite-74.sh[670]: + return 1 [ 694.659094] systemd[1]: testsuite-74.service: Main process exited, code=exited, status=1/FAILURE [ 694.719563] systemd[1]: testsuite-74.service: Failed with result 'exit-code'. [ 694.882069] systemd[1]: Failed to start testsuite-74.service. [ 695.574445] systemd[1]: Reached target testsuite.target. [ 696.174844] systemd[1]: Starting end.service... [ 699.509408] systemd-nspawn[1332]: [ 699.509408] systemd-nspawn[1332]: CentOS Stream 9 [ 699.509408] systemd-nspawn[1332]: Kernel 5.14.0-432.el9.x86_64 on an x86_64 (pts/0) [ 699.509408] systemd-nspawn[1332]: Also, move the rest of container the setup for the user xattrs test into the condition, since doing it without the actual test is pretty pointless.
2024-03-28 14:15:06 +00:00
systemctl daemon-reload
[[ "$(systemd-detect-virt)" == "qemu" ]] && TIMEOUT=120 || TIMEOUT=60
machinectl start "$CONTAINER"
test: bump the container boot timeout when running w/o acceleration With plain QEMU on a saturated AWS region we might just barely miss the timeout window, causing unexpected test fails: [ 688.681324] systemd-nspawn[1332]: [ OK ] Finished systemd-user-sessions.service. [ 689.451267] systemd-nspawn[1332]: [ OK ] Started console-getty.service. [ 689.572874] systemd-nspawn[1332]: [ OK ] Reached target getty.target. [ 693.634609] testsuite-74.sh[1223]: + at_exit [ 693.634609] testsuite-74.sh[1223]: + rm -fv -- /tmp/test-dump /tmp/test-usr-dump /tmp/make-dump [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-usr-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/make-dump' [ 693.951114] testsuite-74.sh[670]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed' [ 693.951114] testsuite-74.sh[670]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed [ 693.951114] testsuite-74.sh[670]: + return 1 [ 694.659094] systemd[1]: testsuite-74.service: Main process exited, code=exited, status=1/FAILURE [ 694.719563] systemd[1]: testsuite-74.service: Failed with result 'exit-code'. [ 694.882069] systemd[1]: Failed to start testsuite-74.service. [ 695.574445] systemd[1]: Reached target testsuite.target. [ 696.174844] systemd[1]: Starting end.service... [ 699.509408] systemd-nspawn[1332]: [ 699.509408] systemd-nspawn[1332]: CentOS Stream 9 [ 699.509408] systemd-nspawn[1332]: Kernel 5.14.0-432.el9.x86_64 on an x86_64 (pts/0) [ 699.509408] systemd-nspawn[1332]: Also, move the rest of container the setup for the user xattrs test into the condition, since doing it without the actual test is pretty pointless.
2024-03-28 14:15:06 +00:00
timeout "$TIMEOUT" bash -xec "until systemd-run -M '$CONTAINER' -q --wait --pipe true; do sleep .5; done"
[[ "$(systemd-run -M "$CONTAINER" -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l)" -eq 0 ]]
machinectl copy-to "$CONTAINER" "$MAKE_DUMP_SCRIPT"
systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGABRT"
systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGTRAP"
# Wait a bit for the coredumps to get processed
timeout 30 bash -c "while [[ \$(systemd-run -M $CONTAINER -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l) -lt 2 ]]; do sleep 1; done"
test: bump the container boot timeout when running w/o acceleration With plain QEMU on a saturated AWS region we might just barely miss the timeout window, causing unexpected test fails: [ 688.681324] systemd-nspawn[1332]: [ OK ] Finished systemd-user-sessions.service. [ 689.451267] systemd-nspawn[1332]: [ OK ] Started console-getty.service. [ 689.572874] systemd-nspawn[1332]: [ OK ] Reached target getty.target. [ 693.634609] testsuite-74.sh[1223]: + at_exit [ 693.634609] testsuite-74.sh[1223]: + rm -fv -- /tmp/test-dump /tmp/test-usr-dump /tmp/make-dump [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-usr-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/make-dump' [ 693.951114] testsuite-74.sh[670]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed' [ 693.951114] testsuite-74.sh[670]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed [ 693.951114] testsuite-74.sh[670]: + return 1 [ 694.659094] systemd[1]: testsuite-74.service: Main process exited, code=exited, status=1/FAILURE [ 694.719563] systemd[1]: testsuite-74.service: Failed with result 'exit-code'. [ 694.882069] systemd[1]: Failed to start testsuite-74.service. [ 695.574445] systemd[1]: Reached target testsuite.target. [ 696.174844] systemd[1]: Starting end.service... [ 699.509408] systemd-nspawn[1332]: [ 699.509408] systemd-nspawn[1332]: CentOS Stream 9 [ 699.509408] systemd-nspawn[1332]: Kernel 5.14.0-432.el9.x86_64 on an x86_64 (pts/0) [ 699.509408] systemd-nspawn[1332]: Also, move the rest of container the setup for the user xattrs test into the condition, since doing it without the actual test is pretty pointless.
2024-03-28 14:15:06 +00:00
machinectl stop "$CONTAINER"
test: bump the container boot timeout when running w/o acceleration With plain QEMU on a saturated AWS region we might just barely miss the timeout window, causing unexpected test fails: [ 688.681324] systemd-nspawn[1332]: [ OK ] Finished systemd-user-sessions.service. [ 689.451267] systemd-nspawn[1332]: [ OK ] Started console-getty.service. [ 689.572874] systemd-nspawn[1332]: [ OK ] Reached target getty.target. [ 693.634609] testsuite-74.sh[1223]: + at_exit [ 693.634609] testsuite-74.sh[1223]: + rm -fv -- /tmp/test-dump /tmp/test-usr-dump /tmp/make-dump [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/test-usr-dump' [ 693.838395] testsuite-74.sh[1502]: removed '/tmp/make-dump' [ 693.951114] testsuite-74.sh[670]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed' [ 693.951114] testsuite-74.sh[670]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-74.coredump.sh failed [ 693.951114] testsuite-74.sh[670]: + return 1 [ 694.659094] systemd[1]: testsuite-74.service: Main process exited, code=exited, status=1/FAILURE [ 694.719563] systemd[1]: testsuite-74.service: Failed with result 'exit-code'. [ 694.882069] systemd[1]: Failed to start testsuite-74.service. [ 695.574445] systemd[1]: Reached target testsuite.target. [ 696.174844] systemd[1]: Starting end.service... [ 699.509408] systemd-nspawn[1332]: [ 699.509408] systemd-nspawn[1332]: CentOS Stream 9 [ 699.509408] systemd-nspawn[1332]: Kernel 5.14.0-432.el9.x86_64 on an x86_64 (pts/0) [ 699.509408] systemd-nspawn[1332]: Also, move the rest of container the setup for the user xattrs test into the condition, since doing it without the actual test is pretty pointless.
2024-03-28 14:15:06 +00:00
rm -rf "/var/lib/machines/$CONTAINER"
unset CONTAINER
fi
coredumpctl
SYSTEMD_LOG_LEVEL=debug coredumpctl
coredumpctl --help
coredumpctl --version
coredumpctl --no-pager --no-legend
coredumpctl --all
coredumpctl -1
coredumpctl -n 1
coredumpctl --reverse
coredumpctl -F COREDUMP_EXE
coredumpctl --json=short | jq
coredumpctl --json=pretty | jq
coredumpctl --json=off
coredumpctl --root=/
coredumpctl --directory=/var/log/journal
coredumpctl --file="/var/log/journal/$(</etc/machine-id)"/*.journal
coredumpctl --since=@0
coredumpctl --since=yesterday --until=tomorrow
# We should have a couple of externally stored coredumps
coredumpctl --field=COREDUMP_FILENAME | tee /tmp/coredumpctl.out
grep "/var/lib/systemd/coredump/core" /tmp/coredumpctl.out
rm -f /tmp/coredumpctl.out
coredumpctl info
coredumpctl info "$CORE_TEST_BIN"
coredumpctl info /foo /bar/ /baz "$CORE_TEST_BIN"
coredumpctl info "${CORE_TEST_BIN##*/}"
coredumpctl info foo bar baz "${CORE_TEST_BIN##*/}"
coredumpctl info COREDUMP_EXE="$CORE_TEST_BIN"
coredumpctl info COREDUMP_EXE=aaaaa COREDUMP_EXE= COREDUMP_EXE="$CORE_TEST_BIN"
coredumpctl debug --debugger=/bin/true "$CORE_TEST_BIN"
SYSTEMD_DEBUGGER=/bin/true coredumpctl debug "$CORE_TEST_BIN"
coredumpctl debug --debugger=/bin/true --debugger-arguments="-this --does --not 'do anything' -a -t --all" "${CORE_TEST_BIN##*/}"
coredumpctl dump "$CORE_TEST_BIN" >/tmp/core.redirected
test -s /tmp/core.redirected
coredumpctl dump -o /tmp/core.output "${CORE_TEST_BIN##*/}"
test -s /tmp/core.output
rm -f /tmp/core.{output,redirected}
# Unprivileged stuff
# Related issue: https://github.com/systemd/systemd/issues/26912
UNPRIV_CMD=(systemd-run --user --wait --pipe -M "testuser@.host" --)
# Trigger a couple of coredumps as an unprivileged user
"${UNPRIV_CMD[@]}" "$MAKE_DUMP_SCRIPT" "$CORE_TEST_UNPRIV_BIN" "SIGTRAP"
"${UNPRIV_CMD[@]}" "$MAKE_DUMP_SCRIPT" "$CORE_TEST_UNPRIV_BIN" "SIGABRT"
# In the tests we store the coredumps in journals, so let's generate a couple
# with Storage=external as well
mkdir -p /run/systemd/coredump.conf.d/
printf '[Coredump]\nStorage=external' >/run/systemd/coredump.conf.d/99-external.conf
"${UNPRIV_CMD[@]}" "$MAKE_DUMP_SCRIPT" "$CORE_TEST_UNPRIV_BIN" "SIGTRAP"
"${UNPRIV_CMD[@]}" "$MAKE_DUMP_SCRIPT" "$CORE_TEST_UNPRIV_BIN" "SIGABRT"
rm -fv /run/systemd/coredump.conf.d/99-external.conf
# Wait a bit for the coredumps to get processed
timeout 30 bash -c "while [[ \$(coredumpctl list -q --no-legend $CORE_TEST_UNPRIV_BIN | wc -l) -lt 4 ]]; do sleep 1; done"
# root should see coredumps from both binaries
coredumpctl info "$CORE_TEST_UNPRIV_BIN"
coredumpctl info "${CORE_TEST_UNPRIV_BIN##*/}"
# The test user should see only their own coredumps
"${UNPRIV_CMD[@]}" coredumpctl
"${UNPRIV_CMD[@]}" coredumpctl info "$CORE_TEST_UNPRIV_BIN"
"${UNPRIV_CMD[@]}" coredumpctl info "${CORE_TEST_UNPRIV_BIN##*/}"
(! "${UNPRIV_CMD[@]}" coredumpctl info --all "$CORE_TEST_BIN")
(! "${UNPRIV_CMD[@]}" coredumpctl info --all "${CORE_TEST_BIN##*/}")
# We should have a couple of externally stored coredumps
"${UNPRIV_CMD[@]}" coredumpctl --field=COREDUMP_FILENAME | tee /tmp/coredumpctl.out
grep "/var/lib/systemd/coredump/core" /tmp/coredumpctl.out
rm -f /tmp/coredumpctl.out
"${UNPRIV_CMD[@]}" coredumpctl debug --debugger=/bin/true "$CORE_TEST_UNPRIV_BIN"
"${UNPRIV_CMD[@]}" coredumpctl debug --debugger=/bin/true --debugger-arguments="-this --does --not 'do anything' -a -t --all" "${CORE_TEST_UNPRIV_BIN##*/}"
"${UNPRIV_CMD[@]}" coredumpctl dump "$CORE_TEST_UNPRIV_BIN" >/tmp/core.redirected
test -s /tmp/core.redirected
"${UNPRIV_CMD[@]}" coredumpctl dump -o /tmp/core.output "${CORE_TEST_UNPRIV_BIN##*/}"
test -s /tmp/core.output
rm -f /tmp/core.{output,redirected}
(! "${UNPRIV_CMD[@]}" coredumpctl dump "$CORE_TEST_BIN" >/dev/null)
# --backtrace mode
# Pass one of the existing journal coredump records to systemd-coredump and
# use our PID as the source to make matching the coredump later easier
# systemd-coredump args: PID UID GID SIGNUM TIMESTAMP CORE_SOFT_RLIMIT HOSTNAME
journalctl -b -n 1 --output=export --output-fields=MESSAGE,COREDUMP COREDUMP_EXE="/usr/bin/test-dump" |
/usr/lib/systemd/systemd-coredump --backtrace $$ 0 0 6 1679509994 12345 mymachine
# Wait a bit for the coredump to get processed
timeout 30 bash -c "while [[ \$(coredumpctl list -q --no-legend $$ | wc -l) -eq 0 ]]; do sleep 1; done"
coredumpctl info "$$"
coredumpctl info COREDUMP_HOSTNAME="mymachine"
# This used to cause a stack overflow
systemd-run -t --property CoredumpFilter=all ls /tmp
systemd-run -t --property CoredumpFilter=default ls /tmp
(! coredumpctl --hello-world)
(! coredumpctl -n 0)
(! coredumpctl -n -1)
(! coredumpctl --file=/dev/null)
(! coredumpctl --since=0)
(! coredumpctl --until='')
(! coredumpctl --since=today --until=yesterday)
(! coredumpctl --directory=/ --root=/)
(! coredumpctl --json=foo)
(! coredumpctl -F foo -F bar)
(! coredumpctl list 0)
(! coredumpctl list -- -1)
(! coredumpctl list '')
(! coredumpctl info /../.~=)
(! coredumpctl info '')
(! coredumpctl dump --output=/dev/full "$CORE_TEST_BIN")
(! coredumpctl dump --output=/dev/null --output=/dev/null "$CORE_TEST_BIN")
(! coredumpctl debug --debugger=/bin/false)
(! coredumpctl debug --debugger=/bin/true --debugger-arguments='"')