]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: remove trailing spaces when outputing to journal
authorSami Kerola <kerolasa@iki.fi>
Mon, 18 Jul 2016 20:49:27 +0000 (21:49 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 19 Jul 2016 09:02:48 +0000 (11:02 +0200)
Issues:
1. Whitespace-ish \r is not stripped, while it should be.
2. In journal \r is considered unprintable.

Lennart: "it is the duty of the client side to drop the trailing whitespace,
which "logger" doesn't do".

Reported-by: Ivan Babrou <ibobrik@gmail.com>
Explained-by: Lennart Poettering <lennart@poettering.net>
Reference: https://github.com/systemd/systemd/issues/3416
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/logger.c
tests/expected/logger/journald

index 9f2940cb289196076ddf103133b6ba6438c5d118..70fac68bb33d46081932d37128e7e0c1a45cbd0a 100644 (file)
@@ -341,14 +341,11 @@ static int journald_entry(struct logger_ctl *ctl, FILE *fp)
        for (lines = 0; /* nothing */ ; lines++) {
                buf = NULL;
                sz = getline(&buf, &dummy, fp);
-               if (sz == -1) {
+               if (sz == -1 ||
+                  (sz = rtrim_whitespace((unsigned char *) buf)) == 0) {
                        free(buf);
                        break;
                }
-               if (0 < sz && buf[sz - 1] == '\n') {
-                       sz--;
-                       buf[sz] = '\0';
-               }
                if (lines == vectors) {
                        vectors *= 2;
                        if (IOV_MAX < vectors)
index 75bd0f3e70f0284bdce1b5adc11c34c820f6ab2e..354628d16873a3c59ce6214ac7c2cffaa5f526f6 100644 (file)
@@ -1,4 +1,3 @@
 MESSAGE_ID=b8f74e14bc714bfc8040a5106dc9376a
 MESSAGE=a b c 1 2 3
-
 ret: 0