diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-08-10 11:07:54 +0900 |
---|---|---|
committer | INSUN PYO <insun.pyo@samsung.com> | 2019-02-18 15:39:24 +0900 |
commit | 141d2dce32bc8339336fe226de97fee2a0538de6 (patch) | |
tree | 6af6387777cf06b09f8c2a62d6aa45309da3e4ab /src | |
parent | dd195c4b12dd263b4f53c53b89b6ff19073248a3 (diff) | |
download | systemd-141d2dce32bc8339336fe226de97fee2a0538de6.tar.gz systemd-141d2dce32bc8339336fe226de97fee2a0538de6.tar.bz2 systemd-141d2dce32bc8339336fe226de97fee2a0538de6.zip |
journal: do not remove multiple spaces after identifier in syslog message
Single space is used as separator.
C.f. discussions in #156.
Fixes #9839 introduced by a6aadf4ae0bae185dc4c414d492a4a781c80ffe5.
Change-Id: I2cabac6e0d99634aeb148b4d7698a67d84b546dd
Diffstat (limited to 'src')
-rw-r--r-- | src/journal/journald-syslog.c | 4 | ||||
-rw-r--r-- | src/journal/test-journal-syslog.c | 26 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index fb63412060..59b68dfdf2 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -238,7 +238,9 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid) if (t) *identifier = t; - e += strspn(p + e, WHITESPACE); + /* Single space is used as separator */ + if (p[e] != '\0' && strchr(WHITESPACE, p[e])) + e++; *buf = p + e; return e; diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c index 60cbe5621b..0828b887d8 100644 --- a/src/journal/test-journal-syslog.c +++ b/src/journal/test-journal-syslog.c @@ -23,7 +23,7 @@ #include "string-util.h" static void test_syslog_parse_identifier(const char *str, - const char *ident, const char *pid, int ret) { + const char *ident, const char *pid, const char *rest, int ret) { const char *buf = str; _cleanup_free_ char *ident2 = NULL, *pid2 = NULL; int ret2; @@ -33,18 +33,24 @@ static void test_syslog_parse_identifier(const char *str, assert_se(ret == ret2); assert_se(ident == ident2 || streq_ptr(ident, ident2)); assert_se(pid == pid2 || streq_ptr(pid, pid2)); + assert_se(streq(buf, rest)); } int main(void) { - test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", 11); - test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, 6); - test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, 7); - test_syslog_parse_identifier("pidu xxx", NULL, NULL, 0); - test_syslog_parse_identifier(":", "", NULL, 1); - test_syslog_parse_identifier(": ", "", NULL, 3); - test_syslog_parse_identifier("pidu:", "pidu", NULL, 5); - test_syslog_parse_identifier("pidu: ", "pidu", NULL, 6); - test_syslog_parse_identifier("pidu : ", NULL, NULL, 0); + test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11); + test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, "xxx", 6); + test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, " xxx", 6); + test_syslog_parse_identifier("pidu xxx", NULL, NULL, "pidu xxx", 0); + test_syslog_parse_identifier(" pidu xxx", NULL, NULL, " pidu xxx", 0); + test_syslog_parse_identifier("", NULL, NULL, "", 0); + test_syslog_parse_identifier(" ", NULL, NULL, " ", 0); + test_syslog_parse_identifier(":", "", NULL, "", 1); + test_syslog_parse_identifier(": ", "", NULL, " ", 2); + test_syslog_parse_identifier(" :", "", NULL, "", 2); + test_syslog_parse_identifier(" pidu:", "pidu", NULL, "", 8); + test_syslog_parse_identifier("pidu:", "pidu", NULL, "", 5); + test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6); + test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0); return 0; } |