From c735f8e237315e47c8fcb0af4aeb6b3401f8e987 Mon Sep 17 00:00:00 2001 From: Yiqiao Pu Date: Sat, 5 Jul 2025 10:49:45 +0800 Subject: [PATCH] Update the journalctl function to ignore No entry message For currently version of journalctl, --user option only works when the persistent storage is enabled. So we need to check this option before we use it. Otherwise a set of tests will failed with can not find expected output from journalctl with rootless user. Signed-off-by: Yiqiao Pu --- test/system/helpers.systemd.bash | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/system/helpers.systemd.bash b/test/system/helpers.systemd.bash index 1ea1a8f22f..6ca33c1d11 100644 --- a/test/system/helpers.systemd.bash +++ b/test/system/helpers.systemd.bash @@ -14,12 +14,42 @@ fi mkdir -p $UNIT_DIR +journalctl_raw() { + # Run the journalctl command directly without any wrapper + timeout --foreground -v --kill=10 $PODMAN_TIMEOUT journalctl "$@" +} + +JOURNALCTL_SUPPORT_USER=false +run journalctl_raw --user -b -n 1 +if [[ $output != *"No entries"* ]]; then + JOURNALCTL_SUPPORT_USER=true +fi + systemctl() { timeout --foreground -v --kill=10 $PODMAN_TIMEOUT systemctl $_DASHUSER "$@" } journalctl() { - timeout --foreground -v --kill=10 $PODMAN_TIMEOUT journalctl $_DASHUSER "$@" + if is_rootless && ! $JOURNALCTL_SUPPORT_USER; then + # For systems that --user not working, need to update the options manually + # for our testing. Otherwise journalctl with --user will always report + # -- No entries -- + options=() + for arg in "$@"; do + opt=("$arg") + if [[ "$arg" =~ "--unit" ]]; then + opt=("${arg/--unit/--user-unit}") + elif [[ "$arg" == "-u" ]]; then + opt=("--user-unit") + elif [[ "$arg" =~ ^-u || "$arg" =~ ^-[a-zA-Z]+u ]]; then + opt=("${arg/u/}" "--user-unit") + fi + options+=("${opt[@]}") + done + journalctl_raw "${options[@]}" + else + journalctl_raw $_DASHUSER "$@" + fi } systemd-run() {