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:
committed by
Yu Watanabe
parent
08bebda611
commit
3121e14658
@@ -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");
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user