journal: Fix journal dumping for json, cat and export output
authorArmin Widegreen <armin.widegreen@stoneridge.com>
Thu, 11 Jan 2018 11:42:56 +0000 (12:42 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 22 Jan 2018 17:08:52 +0000 (18:08 +0100)
Incorporating the fix from d00f1d57 into other output formats of journalctl.

If journal files are corrupted, e.g. not cleanly closed, some journal
entries can not be read by output options other than 'short' (default).
If such entries has been identified, they will now just be skipped.

src/shared/logs-show.c

index a861be7..8a1b266 100644 (file)
@@ -661,6 +661,10 @@ static int output_export(
 
                 fputc('\n', f);
         }
+        if (r == -EBADMSG) {
+                log_debug_errno(r, "Skipping message we can't read: %m");
+                return 0;
+        }
 
         if (r < 0)
                 return r;
@@ -824,6 +828,11 @@ static int output_json(
                 }
         }
 
+        if (r == -EBADMSG) {
+                log_debug_errno(r, "Skipping message we can't read: %m");
+                return 0;
+        }
+
         if (r < 0)
                 return r;
 
@@ -964,6 +973,10 @@ static int output_cat(
         sd_journal_set_data_threshold(j, 0);
 
         r = sd_journal_get_data(j, "MESSAGE", &data, &l);
+        if (r == -EBADMSG) {
+                log_debug_errno(r, "Skipping message we can't read: %m");
+                return 0;
+        }
         if (r < 0) {
                 /* An entry without MESSAGE=? */
                 if (r == -ENOENT)