journal-remote: use source's boot-id
authorChris Morin <cmtm@google.com>
Thu, 14 Mar 2019 18:24:52 +0000 (11:24 -0700)
committerLennart Poettering <lennart@poettering.net>
Tue, 2 Apr 2019 08:32:21 +0000 (10:32 +0200)
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
src/journal-remote/journal-remote-write.c
src/journal-remote/journal-remote-write.h
src/journal/journal-file.c

index 535d06a..ebcae2f 100644 (file)
@@ -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;
index 188ff35..ab5e03a 100644 (file)
@@ -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)
index e445859..d42256e 100644 (file)
@@ -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);
 
index 6a2e80e..91d1c29 100644 (file)
@@ -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);