@@ -74,6 +74,68 @@ rm -fv /run/systemd/coredump.conf.d/99-external.conf
74
74
# Wait a bit for the coredumps to get processed
75
75
timeout 30 bash -c " while [[ \$ (coredumpctl list -q --no-legend $CORE_TEST_BIN | wc -l) -lt 4 ]]; do sleep 1; done"
76
76
77
+ # RHEL9: following part is taken out of 097e28736aed9280dfac0f8e8096deca71bac813 but slightly tweaked, since
78
+ # in RHEL9 we don't have the support for coredump forwarding
79
+ CONTAINER=" testsuite-74-container"
80
+ TESTUSER_UID=" $( id -u testuser) "
81
+ TESTUSER_GID=" $( id -g testuser) "
82
+
83
+ mkdir -p " /var/lib/machines/$CONTAINER "
84
+ mkdir -p " /run/systemd/system/systemd-nspawn@$CONTAINER .service.d"
85
+ # Bind-mounting /etc into the container kinda defeats the purpose of --volatile=,
86
+ # but we need the ASan-related overrides scattered across /etc
87
+ cat > " /run/systemd/system/systemd-nspawn@$CONTAINER .service.d/override.conf" << EOF
88
+ [Service]
89
+ ExecStart=
90
+ ExecStart=systemd-nspawn --quiet --link-journal=try-guest --keep-unit --machine=%i --boot \
91
+ --volatile=yes --directory=/ --bind-ro=/etc --inaccessible=/etc/machine-id
92
+ EOF
93
+ systemctl daemon-reload
94
+
95
+ machinectl start " $CONTAINER "
96
+ timeout 60 bash -xec " until systemd-run -M '$CONTAINER ' -q --wait --pipe true; do sleep .5; done"
97
+ machinectl copy-to " $CONTAINER " " $MAKE_DUMP_SCRIPT "
98
+
99
+ run_namespaced_coredump_tests () {
100
+ local TS
101
+
102
+ # Make a couple of coredumps in a full-fleged container
103
+ TS=" $( date +" %s.%N" ) "
104
+ [[ " $( coredumpctl list --since=" @$TS " -q --no-legend /usr/bin/sleep | wc -l) " -eq 0 ]]
105
+ [[ " $( coredumpctl list --since=" @$TS " -q --no-legend /usr/bin/sleep _UID=" $TESTUSER_UID " | wc -l) " -eq 0 ]]
106
+ systemd-run -M " testuser@$CONTAINER " --user -q --wait --pipe " $MAKE_DUMP_SCRIPT " " /usr/bin/sleep" " SIGABRT"
107
+ systemd-run -M " $CONTAINER " -q --wait --pipe " $MAKE_DUMP_SCRIPT " " /usr/bin/sleep" " SIGTRAP"
108
+ # Wait a bit for the coredumps to get processed
109
+ timeout 30 bash -c " while [[ \$ (coredumpctl list --since=@$TS -q --no-legend /usr/bin/sleep | wc -l) -ne 2 ]]; do sleep 1; done"
110
+ coredumpctl list
111
+ [[ " $( coredumpctl list --since=" @$TS " -q --no-legend /usr/bin/sleep _UID=" $TESTUSER_UID " _GID=" $TESTUSER_GID " | wc -l) " -eq 1 ]]
112
+
113
+ # Simplified version of the above - not a full container, just a mount & pid namespace
114
+ TS=" $( date +" %s.%N" ) "
115
+ unshare --mount --pid --fork --mount-proc /bin/bash -xec " $MAKE_DUMP_SCRIPT /usr/bin/sleep SIGABRT"
116
+ timeout 30 bash -c " while [[ \$ (coredumpctl list --since=@$TS -q --no-legend /usr/bin/sleep | wc -l) -ne 1 ]]; do sleep 1; done"
117
+ TS=" $( date +" %s.%N" ) "
118
+ unshare --setuid=" $TESTUSER_UID " --setgid=" $TESTUSER_GID " --mount --pid --fork --mount-proc /bin/bash -xec " $MAKE_DUMP_SCRIPT /usr/bin/sleep SIGABRT"
119
+ timeout 30 bash -c " while [[ \$ (coredumpctl list --since=@$TS -q --no-legend /usr/bin/sleep _UID=$TESTUSER_UID _GID=$TESTUSER_GID | wc -l) -ne 1 ]]; do sleep 1; done"
120
+ }
121
+
122
+ # First, run the tests with default systemd-coredumpd settings
123
+ run_namespaced_coredump_tests
124
+
125
+ # And now with SYSTEMD_COREDUMP_ALLOW_NAMESPACE_CHANGE=1 (RHEL-only)
126
+ cat > /tmp/coredump-handler.sh << EOF
127
+ #!/bin/bash
128
+ export SYSTEMD_COREDUMP_ALLOW_NAMESPACE_CHANGE=1
129
+ exec /usr/lib/systemd/systemd-coredump "\$ @"
130
+ EOF
131
+ chmod +x /tmp/coredump-handler.sh
132
+ sysctl -w kernel.core_pattern=" |/tmp/coredump-handler.sh %P %u %g %s %t %c %h"
133
+ run_namespaced_coredump_tests
134
+
135
+ # Restore the original coredump handler
136
+ sysctl -p /usr/lib/sysctl.d/50-coredump.conf
137
+ sysctl kernel.core_pattern
138
+
77
139
coredumpctl
78
140
SYSTEMD_LOG_LEVEL=debug coredumpctl
79
141
coredumpctl --help
@@ -89,7 +151,7 @@ coredumpctl --json=pretty | jq
89
151
coredumpctl --json=off
90
152
coredumpctl --root=/
91
153
coredumpctl --directory=/var/log/journal
92
- coredumpctl --file=" /var/log/journal/$( < /etc/machine-id) /system .journal"
154
+ coredumpctl --file=" /var/log/journal/$( < /etc/machine-id) " / * .journal
93
155
coredumpctl --since=@0
94
156
coredumpctl --since=yesterday --until=tomorrow
95
157
# We should have a couple of externally stored coredumps
0 commit comments