anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone
923a60
From 0adbe0fe7f1cb8703904c85fa095db8070503c04 Mon Sep 17 00:00:00 2001
923a60
From: Yu Watanabe <watanabe.yu+github@gmail.com>
923a60
Date: Fri, 10 Aug 2018 11:07:54 +0900
923a60
Subject: [PATCH] journal: do not remove multiple spaces after identifier in
923a60
 syslog message
923a60
923a60
Single space is used as separator.
923a60
C.f. discussions in #156.
923a60
923a60
Fixes #9839 introduced by a6aadf4ae0bae185dc4c414d492a4a781c80ffe5.
923a60
923a60
(cherry-picked from commit 8595102d3ddde6d25c282f965573a6de34ab4421)
923a60
Related: #1657794
923a60
---
923a60
 src/journal/journald-syslog.c     |  4 +++-
923a60
 src/journal/test-journal-syslog.c | 24 ++++++++++++++----------
923a60
 2 files changed, 17 insertions(+), 11 deletions(-)
923a60
923a60
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
923a60
index 3ea5d79c3a..1a9db59a0f 100644
923a60
--- a/src/journal/journald-syslog.c
923a60
+++ b/src/journal/journald-syslog.c
923a60
@@ -234,7 +234,9 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
923a60
         if (t)
923a60
                 *identifier = t;
923a60
 
923a60
-        e += strspn(p + e, WHITESPACE);
923a60
+        /* Single space is used as separator */
923a60
+        if (p[e] != '\0' && strchr(WHITESPACE, p[e]))
923a60
+                e++;
923a60
 
923a60
         *buf = p + e;
923a60
         return e;
923a60
diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c
923a60
index f56a813774..d4bd8607d3 100644
923a60
--- a/src/journal/test-journal-syslog.c
923a60
+++ b/src/journal/test-journal-syslog.c
923a60
@@ -23,7 +23,7 @@
923a60
 #include "macro.h"
923a60
 
923a60
 static void test_syslog_parse_identifier(const char *str,
923a60
-                                         const char *ident, const char*pid, int ret) {
923a60
+                                         const char *ident, const char *pid, const char *rest, int ret) {
923a60
         const char *buf = str;
923a60
         _cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
923a60
         int ret2;
923a60
@@ -33,18 +33,22 @@ static void test_syslog_parse_identifier(const char *str,
923a60
         assert_se(ret == ret2);
923a60
         assert_se(ident == ident2 || streq_ptr(ident, ident2));
923a60
         assert_se(pid == pid2 || streq_ptr(pid, pid2));
923a60
+        assert_se(streq(buf, rest));
923a60
 }
923a60
 
923a60
 int main(void) {
923a60
-        test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", 11);
923a60
-        test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, 6);
923a60
-        test_syslog_parse_identifier("pidu:  xxx", "pidu", NULL, 7);
923a60
-        test_syslog_parse_identifier("pidu xxx", NULL, NULL, 0);
923a60
-        test_syslog_parse_identifier(":", "", NULL, 1);
923a60
-        test_syslog_parse_identifier(":  ", "", NULL, 3);
923a60
-        test_syslog_parse_identifier("pidu:", "pidu", NULL, 5);
923a60
-        test_syslog_parse_identifier("pidu: ", "pidu", NULL, 6);
923a60
-        test_syslog_parse_identifier("pidu : ", NULL, NULL, 0);
923a60
+        test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11);
923a60
+        test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, "xxx", 6);
923a60
+        test_syslog_parse_identifier("pidu:  xxx", "pidu", NULL, " xxx", 6);
923a60
+        test_syslog_parse_identifier("pidu xxx", NULL, NULL, "pidu xxx", 0);
923a60
+        test_syslog_parse_identifier("   pidu xxx", NULL, NULL, "   pidu xxx", 0);
923a60
+        test_syslog_parse_identifier("", NULL, NULL, "", 0);
923a60
+        test_syslog_parse_identifier("  ", NULL, NULL, "  ", 0);
923a60
+        test_syslog_parse_identifier(":", "", NULL, "", 1);
923a60
+        test_syslog_parse_identifier(":  ", "", NULL, " ", 2);
923a60
+        test_syslog_parse_identifier("pidu:", "pidu", NULL, "", 5);
923a60
+        test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6);
923a60
+        test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0);
923a60
 
923a60
         return 0;
923a60
 }