TEST-04-JOURNAL: include util.sh before calling cgroupfs_supports_user_xattrs() (#37039)

Fixes a bug introduced by 46322f2742
(v256).
Fixes #36991.
This commit is contained in:
Luca Boccassi
2025-04-08 09:52:13 +01:00
committed by GitHub
3 changed files with 14 additions and 9 deletions

View File

@@ -3,9 +3,8 @@ Description=Log filtering unit
[Service]
Type=oneshot
ExecStart=sh -c 'echo "Logging from the service, and ~more~ foo bar"'
# If the service finishes extremely fast, journald cannot find the source of the
# stream. Hence, we need to call 'journalctl --sync' before service finishes.
ExecStart=journalctl --sync
ExecStart=sh -c 'echo "Logging from the service, and ~more~ foo bar"; journalctl --sync'
SyslogLevel=notice
LogLevelMax=info

View File

@@ -3,13 +3,17 @@
set -eux
set -o pipefail
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
if ! cgroupfs_supports_user_xattrs; then
echo "CGroup does not support user xattrs, skipping LogFilterPatterns= tests."
exit 0
fi
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
# Unfortunately, journalctl -I/--invocation= is unstable when debug logging is enabled on service manager.
SAVED_LOG_LEVEL=$(systemctl log-level)
systemctl log-level info
NEEDS_RELOAD=
@@ -25,17 +29,14 @@ add_logs_filtering_override() {
run_service_and_fetch_logs() {
local unit="${1:?}"
local start
if [[ -n "$NEEDS_RELOAD" ]]; then
systemctl daemon-reload
NEEDS_RELOAD=
fi
journalctl --sync
start="$(date '+%Y-%m-%d %T.%6N')"
systemctl start "$unit"
journalctl -q -u "$unit" -S "$start" -p notice
journalctl -q -u "$unit" -I -p notice
}
at_exit() {
@@ -91,3 +92,5 @@ add_logs_filtering_override "delegated-cgroup-filtering.service" "00-allow-all"
add_logs_filtering_override "delegated-cgroup-filtering.service" "01-discard-hello" "~hello"
[[ -z $(run_service_and_fetch_logs "delegated-cgroup-filtering.service") ]]
systemctl log-level "$SAVED_LOG_LEVEL"

View File

@@ -6,4 +6,7 @@ mkdir /sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child
echo "parent_process: hello, world!"
echo "parent_process: hello, people!"
sleep 2
# If the service finishes extremely fast, journald cannot find the source of the
# stream. Hence, we need to call 'journalctl --sync' before service finishes.
journalctl --sync