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: 68f66a1713.
This commit is contained in:
dongshengyuan
2026-07-16 01:26:46 +09:00
committed by Yu Watanabe
parent 08bebda611
commit 3121e14658
2 changed files with 7 additions and 1 deletions
+5
View File
@@ -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)