Skip to content

Commit

Permalink
journal: do not remove multiple spaces after identifier in syslog mes…
Browse files Browse the repository at this point in the history
…sage

Single space is used as separator.
C.f. discussions in systemd#156.

Fixes #9839 introduced by a6aadf4.
  • Loading branch information
yuwata authored and evverx committed Aug 10, 2018
1 parent a95696e commit 8595102
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/journal/journald-syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,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;
Expand Down
24 changes: 14 additions & 10 deletions src/journal/test-journal-syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "syslog-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;
Expand All @@ -17,6 +17,7 @@ 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));
}

static void test_syslog_parse_priority(const char *str, int priority, int ret) {
Expand All @@ -31,15 +32,18 @@ static void test_syslog_parse_priority(const char *str, int priority, int ret) {
}

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("pidu:", "pidu", NULL, "", 5);
test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6);
test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0);

test_syslog_parse_priority("<>", 0, 0);
test_syslog_parse_priority("<>aaa", 0, 0);
Expand Down

0 comments on commit 8595102

Please sign in to comment.