]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: use root machine ID for namespaces
authordongshengyuan <545258830@qq.com>
Tue, 14 Jul 2026 11:34:21 +0000 (19:34 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 15 Jul 2026 16:26:46 +0000 (01:26 +0900)
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
test/units/TEST-44-LOG-NAMESPACE.sh

index 000c1c6a2b02fc13692ab9107efd5b4d6bfe0b8d..f05b1b518d9567a5d5a58b7a8ed9687787c3b27c 100644 (file)
@@ -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");
 
index 0b214c9378568e6d5112c528e2d87fc478054349..9f314fe67dde2a03135335645c9c313535dc391e 100755 (executable)
@@ -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)