From: Sami Kerola Date: Mon, 18 Jul 2016 20:49:27 +0000 (+0100) Subject: logger: remove trailing spaces when outputing to journal X-Git-Tag: v2.29-rc1~148 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1f5f21ee664c232df1454a322f2570301ee1add;p=thirdparty%2Futil-linux.git logger: remove trailing spaces when outputing to journal 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 Explained-by: Lennart Poettering Reference: https://github.com/systemd/systemd/issues/3416 Signed-off-by: Sami Kerola --- diff --git a/misc-utils/logger.c b/misc-utils/logger.c index 9f2940cb28..70fac68bb3 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -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) diff --git a/tests/expected/logger/journald b/tests/expected/logger/journald index 75bd0f3e70..354628d168 100644 --- a/tests/expected/logger/journald +++ b/tests/expected/logger/journald @@ -1,4 +1,3 @@ MESSAGE_ID=b8f74e14bc714bfc8040a5106dc9376a MESSAGE=a b c 1 2 3 - ret: 0