From 924426a703a6923eedd63d23e6656655805598aa Mon Sep 17 00:00:00 2001 From: Chris Morin Date: Thu, 14 Mar 2019 11:24:52 -0700 Subject: [PATCH] journal-remote: use source's boot-id systemd-journal-remote always wrote the boot-id of the device it was running on to the header of its journal files. When the source had a different boot-id (because it was generated on a different boot, or a different device), the boot-ids in the file were inconsistent. The _BOOT_ID field was that of the source, but the journal file header and each entry object header were that of the device systemd-journal-remote ran on. This breaks journalctl --list-boots on any of these files. Set the boot-id in the header to be that of the source. This also fixes the entry object headers. --- src/journal-remote/journal-remote-parse.c | 6 +++++- src/journal-remote/journal-remote-write.c | 5 +++-- src/journal-remote/journal-remote-write.h | 1 + src/journal/journal-file.c | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c index 535d06a..ebcae2f 100644 --- a/src/journal-remote/journal-remote-parse.c +++ b/src/journal-remote/journal-remote-parse.c @@ -68,7 +68,11 @@ int process_source(RemoteSource *source, bool compress, bool seal) { assert(source->importer.iovw.iovec); - r = writer_write(source->writer, &source->importer.iovw, &source->importer.ts, compress, seal); + r = writer_write(source->writer, + &source->importer.iovw, + &source->importer.ts, + &source->importer.boot_id, + compress, seal); if (r == -EBADMSG) { log_error_errno(r, "Entry is invalid, ignoring."); r = 0; diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c index 188ff35..ab5e03a 100644 --- a/src/journal-remote/journal-remote-write.c +++ b/src/journal-remote/journal-remote-write.c @@ -59,6 +59,7 @@ DEFINE_TRIVIAL_REF_UNREF_FUNC(Writer, writer, writer_free); int writer_write(Writer *w, struct iovec_wrapper *iovw, dual_timestamp *ts, + sd_id128_t *boot_id, bool compress, bool seal) { int r; @@ -75,7 +76,7 @@ int writer_write(Writer *w, return r; } - r = journal_file_append_entry(w->journal, ts, NULL, + r = journal_file_append_entry(w->journal, ts, boot_id, iovw->iovec, iovw->count, &w->seqnum, NULL, NULL); if (r >= 0) { @@ -93,7 +94,7 @@ int writer_write(Writer *w, log_debug("%s: Successfully rotated journal", w->journal->path); log_debug("Retrying write."); - r = journal_file_append_entry(w->journal, ts, NULL, + r = journal_file_append_entry(w->journal, ts, boot_id, iovw->iovec, iovw->count, &w->seqnum, NULL, NULL); if (r < 0) diff --git a/src/journal-remote/journal-remote-write.h b/src/journal-remote/journal-remote-write.h index e445859..d42256e 100644 --- a/src/journal-remote/journal-remote-write.h +++ b/src/journal-remote/journal-remote-write.h @@ -28,6 +28,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Writer*, writer_unref); int writer_write(Writer *s, struct iovec_wrapper *iovw, dual_timestamp *ts, + sd_id128_t *boot_id, bool compress, bool seal); diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 6a2e80e..91d1c29 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -1796,7 +1796,9 @@ static int journal_file_append_entry_internal( o->entry.realtime = htole64(ts->realtime); o->entry.monotonic = htole64(ts->monotonic); o->entry.xor_hash = htole64(xor_hash); - o->entry.boot_id = boot_id ? *boot_id : f->header->boot_id; + if (boot_id) + f->header->boot_id = *boot_id; + o->entry.boot_id = f->header->boot_id; #if HAVE_GCRYPT r = journal_file_hmac_put_object(f, OBJECT_ENTRY, o, np); -- 2.7.4