summaryrefslogtreecommitdiff
path: root/src/journal/journal-send.c
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2016-07-19 21:11:41 +0300
committerGitHub <noreply@github.com>2016-07-19 21:11:41 +0300
commit4526e15d064c77a61cf79c595c3384effd66d31b (patch)
treecae77d07c8dfd6680e519300004a96f81bbf285e /src/journal/journal-send.c
parentbb557f90f842fb9646a83fd3c21ba359bb8c0f28 (diff)
parent0d23bc57da6a3aeb1e7f92cfd7da2cd831b7c11c (diff)
Merge pull request #3636 from poettering/logs-show-utf8
improve handling of trailing newline in journal logging
Diffstat (limited to 'src/journal/journal-send.c')
-rw-r--r--src/journal/journal-send.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index 5e8a3e3200..440fba67ca 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -107,6 +107,13 @@ _public_ int sd_journal_printv(int priority, const char *format, va_list ap) {
memcpy(buffer, "MESSAGE=", 8);
vsnprintf(buffer+8, sizeof(buffer) - 8, format, ap);
+ /* Strip trailing whitespace, keep prefix whitespace. */
+ (void) strstrip(buffer);
+
+ /* Suppress empty lines */
+ if (isempty(buffer+8))
+ return 0;
+
zero(iov);
IOVEC_SET_STRING(iov[0], buffer);
IOVEC_SET_STRING(iov[1], p);
@@ -158,6 +165,8 @@ _printf_(1, 0) static int fill_iovec_sprintf(const char *format, va_list ap, int
VA_FORMAT_ADVANCE(format, ap);
+ (void) strstrip(buffer); /* strip trailing whitespace, keep prefixing whitespace */
+
IOVEC_SET_STRING(iov[i++], buffer);
format = va_arg(ap, char *);
@@ -471,6 +480,13 @@ _public_ int sd_journal_printv_with_location(int priority, const char *file, con
memcpy(buffer, "MESSAGE=", 8);
vsnprintf(buffer+8, sizeof(buffer) - 8, format, ap);
+ /* Strip trailing whitespace, keep prefixing whitespace */
+ (void) strstrip(buffer);
+
+ /* Suppress empty lines */
+ if (isempty(buffer+8))
+ return 0;
+
/* func is initialized from __func__ which is not a macro, but
* a static const char[], hence cannot easily be prefixed with
* CODE_FUNC=, hence let's do it manually here. */