journal: automatically pick up boot ID in journal_file_append_entry()

Let's pick up the boot ID early if unspecified, in
journal_file_append_entry(). This is symmetric to the fact that we
already pick up the monotonic timestamp in journal_file_append_entry()
if unspecified, and given that the monotonic clock is not too useful
without its boot ID it makes a lot of sense to pick them up at the same
time.

There are two relevant callers of journal_file_append_entry() right now:
journald (which leaves the boot ID unspecified) and journal-remote
(there are also some tests, but those don't matter too much). The former
calls it to store new entries in the journal file, the latter for
converting/processing/merging existing ones (where it passes along the
original boot ID). This new code hence only is relevant on the former,
and using the boot ID of the current system is the right choice for live
generated entries.

Note that this effectively changes little, since the lower-level
function journal_file_append_entry_internal() will copy boot ID stored
in the file header into all records if unspecified, and typically that's
the one of the local system. But strictly speaking this is not the right
thing to do, since we actually might end up appending to journal files
from previous boots. (The lower level function is indirectly used by
various tests, where the copying-from-header logic kinda makes sense
since they are detached from any live messages streaming in from the
host after all).
This commit is contained in:
Lennart Poettering 2023-01-19 22:45:17 +01:00
parent 6ae3bd82d0
commit bd524f497f

View file

@ -2256,6 +2256,7 @@ int journal_file_append_entry(
EntryItem *items;
uint64_t xor_hash = 0;
struct dual_timestamp _ts;
sd_id128_t _boot_id;
int r;
assert(f);
@ -2277,6 +2278,14 @@ int journal_file_append_entry(
ts = &_ts;
}
if (!boot_id) {
r = sd_id128_get_boot(&_boot_id);
if (r < 0)
return r;
boot_id = &_boot_id;
}
#if HAVE_GCRYPT
r = journal_file_maybe_append_tag(f, ts->realtime);
if (r < 0)