]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-remote: parse the _BOOT_ID field and use the value when writing entries
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 27 May 2018 09:35:07 +0000 (11:35 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 31 May 2018 12:32:39 +0000 (14:32 +0200)
The boot id is stored twice, and different code paths use either one or the
other. So we need to store it both in the header and as a field for full
compatibility.

src/basic/journal-importer.c
src/basic/journal-importer.h

index a751c5ec8aaa58e38d39bedfff5abffae175f0a1..6fd0f937e2cafc8855664ec78ea22ba6832db7d8 100644 (file)
@@ -246,26 +246,26 @@ static int get_data_newline(JournalImporter *imp) {
         return 1;
 }
 
-static int process_dunder(JournalImporter *imp, char *line) {
-        const char *timestamp;
+static int process_special_field(JournalImporter *imp, char *line) {
+        const char *value;
         char buf[CELLESCAPE_DEFAULT_LENGTH];
         int r;
 
         assert(line);
 
-        timestamp = startswith(line, "__CURSOR=");
-        if (timestamp)
+        value = startswith(line, "__CURSOR=");
+        if (value)
                 /* ignore __CURSOR */
                 return 1;
 
-        timestamp = startswith(line, "__REALTIME_TIMESTAMP=");
-        if (timestamp) {
+        value = startswith(line, "__REALTIME_TIMESTAMP=");
+        if (value) {
                 uint64_t x;
 
-                r = safe_atou64(timestamp, &x);
+                r = safe_atou64(value, &x);
                 if (r < 0)
                         return log_warning_errno(r, "Failed to parse __REALTIME_TIMESTAMP '%s': %m",
-                                                 cellescape(buf, sizeof buf, timestamp));
+                                                 cellescape(buf, sizeof buf, value));
                 else if (!VALID_REALTIME(x)) {
                         log_warning("__REALTIME_TIMESTAMP out of range, ignoring: %"PRIu64, x);
                         return -ERANGE;
@@ -275,14 +275,14 @@ static int process_dunder(JournalImporter *imp, char *line) {
                 return 1;
         }
 
-        timestamp = startswith(line, "__MONOTONIC_TIMESTAMP=");
-        if (timestamp) {
+        value = startswith(line, "__MONOTONIC_TIMESTAMP=");
+        if (value) {
                 uint64_t x;
 
-                r = safe_atou64(timestamp, &x);
+                r = safe_atou64(value, &x);
                 if (r < 0)
                         return log_warning_errno(r, "Failed to parse __MONOTONIC_TIMESTAMP '%s': %m",
-                                                 cellescape(buf, sizeof buf, timestamp));
+                                                 cellescape(buf, sizeof buf, value));
                 else if (!VALID_MONOTONIC(x)) {
                         log_warning("__MONOTONIC_TIMESTAMP out of range, ignoring: %"PRIu64, x);
                         return -ERANGE;
@@ -292,9 +292,21 @@ static int process_dunder(JournalImporter *imp, char *line) {
                 return 1;
         }
 
-        timestamp = startswith(line, "__");
-        if (timestamp) {
-                log_notice("Unknown dunder line __%s, ignoring.", cellescape(buf, sizeof buf, timestamp));
+        /* Just a single underline, but it needs special treatment too. */
+        value = startswith(line, "_BOOT_ID=");
+        if (value) {
+                r = sd_id128_from_string(value, &imp->boot_id);
+                if (r < 0)
+                        return log_warning_errno(r, "Failed to parse _BOOT_ID '%s': %m",
+                                                 cellescape(buf, sizeof buf, value));
+
+                /* store the field in the usual fashion too */
+                return 0;
+        }
+
+        value = startswith(line, "__");
+        if (value) {
+                log_notice("Unknown dunder line __%s, ignoring.", cellescape(buf, sizeof buf, value));
                 return 1;
         }
 
@@ -342,13 +354,13 @@ int journal_importer_process_data(JournalImporter *imp) {
 
                                 t = strndupa(line, sep - line);
                                 log_debug("Ignoring invalid field: \"%s\"",
-                                          cellescape(buf, t));
+                                          cellescape(buf, sizeof buf, t));
 
                                 return 0;
                         }
 
                         line[n] = '\0';
-                        r = process_dunder(imp, line);
+                        r = process_special_field(imp, line);
                         if (r != 0)
                                 return r < 0 ? r : 0;
 
index 7434a789d8c65ac6e1aa08f11375cca890a0de53..c3db3d92d009477fedef39bcb90f54307856895e 100644 (file)
@@ -11,6 +11,8 @@
 #include <stdbool.h>
 #include <sys/uio.h>
 
+#include "sd-id128.h"
+
 #include "time-util.h"
 
 /* Make sure not to make this smaller than the maximum coredump size.
@@ -45,6 +47,7 @@ typedef struct JournalImporter {
 
         int state;
         dual_timestamp ts;
+        sd_id128_t boot_id;
 } JournalImporter;
 
 void journal_importer_cleanup(JournalImporter *);