From 3121e14658e98b8fe665f3d6c53fc0dcd12fb461 Mon Sep 17 00:00:00 2001 From: dongshengyuan <545258830@qq.com> Date: Tue, 14 Jul 2026 19:34:21 +0800 Subject: [PATCH] journalctl: use root machine ID for namespaces journalctl --root=... --list-namespaces scans the target root's journal tree, but used the host machine ID when matching namespace directories. Reproducer: root="$(mktemp -d)" mid=11111111111111111111111111111111 mkdir -p "$root/etc" "$root/var/log/journal/$mid.testns" printf '%s\n' "$mid" >"$root/etc/machine-id" journalctl --root="$root" --list-namespaces --quiet Before: no output Follow-up for: 68f66a171398e27280a95e58ae7464219cccaaec. --- src/journal/journalctl-misc.c | 3 ++- test/units/TEST-44-LOG-NAMESPACE.sh | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/journal/journalctl-misc.c b/src/journal/journalctl-misc.c index 000c1c6a2b..f05b1b518d 100644 --- a/src/journal/journalctl-misc.c +++ b/src/journal/journalctl-misc.c @@ -9,6 +9,7 @@ #include "format-table.h" #include "format-util.h" #include "hashmap.h" +#include "id128-util.h" #include "journal-authenticate.h" #include "journal-internal.h" #include "journal-verify.h" @@ -288,7 +289,7 @@ int action_list_namespaces(void) { assert(arg_action == ACTION_LIST_NAMESPACES); - r = sd_id128_get_machine(&machine); + r = id128_get_machine(arg_root, &machine); if (r < 0) return log_error_errno(r, "Failed to get machine ID: %m"); diff --git a/test/units/TEST-44-LOG-NAMESPACE.sh b/test/units/TEST-44-LOG-NAMESPACE.sh index 0b214c9378..9f314fe67d 100755 --- a/test/units/TEST-44-LOG-NAMESPACE.sh +++ b/test/units/TEST-44-LOG-NAMESPACE.sh @@ -20,6 +20,11 @@ journalctl --list-namespaces | grep foobaz journalctl --list-namespaces -o json | jq . [[ "$(journalctl --root=/tmp --list-namespaces --quiet)" == "" ]] +root="$(mktemp -d /tmp/journal-ns-root.XXXXXX)" +mkdir -p "$root/etc" "$root/var/log/journal/11111111111111111111111111111111.testns" +printf '11111111111111111111111111111111\n' >"$root/etc/machine-id" +[[ "$(journalctl --root="$root" --list-namespaces --quiet)" == "testns" ]] + grep "^hello world$" /tmp/hello-world (! grep "^hello world$" /tmp/no-hello-world)