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.
#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"
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");
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)