chiark / gitweb /
logs-show: fix corrupt output with empty messages
authorUoti Urpala <uoti.urpala@pp1.inet.fi>
Thu, 20 Feb 2014 01:00:09 +0000 (03:00 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Feb 2014 05:43:24 +0000 (00:43 -0500)
If a message had zero length, journalctl would print no newline, and
two output lines would be concatenated. Fix. The problem was
introduced in commit 31f7bf199452 ("logs-show: print multiline
messages"). Affected short and verbose output modes.

Before fix:

Feb 09 21:16:17 glyph dhclient[1323]: Feb 09 21:16:17 glyph NetworkManager[788]: <info> (enp4s2): DHCPv4 state changed nbi -> preinit

after:

Feb 09 21:16:17 glyph dhclient[1323]:
Feb 09 21:16:17 glyph NetworkManager[788]: <info> (enp4s2): DHCPv4 state changed nbi -> preinit

src/shared/logs-show.c

index 61c3652bd5ae32943d020f3f4e98f241071de9f9..12d4a1caecae75fd8090e98adc3e001efe9e5d59 100644 (file)
@@ -124,6 +124,11 @@ static bool print_multiline(FILE *f, unsigned prefix, unsigned n_columns, Output
                 }
         }
 
+        /* A special case: make sure that we print a newline when
+           the message is empty. */
+        if (message_len == 0)
+                fputs("\n", f);
+
         for (pos = message;
              pos < message + message_len;
              pos = end + 1, line++) {