anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0643-journal-forward-messages-from-dev-log-unmodified-to-.patch

aed857
From d82c40a2377b487ef83aa1fb907ec275a1b3e86e Mon Sep 17 00:00:00 2001
aed857
From: Michal Sekletar <msekleta@redhat.com>
aed857
Date: Wed, 30 May 2018 16:27:22 +0200
aed857
Subject: [PATCH] journal: forward messages from /dev/log unmodified to
aed857
 syslog.socket
aed857
aed857
(cherry picked from commit bb3ff70a86faff85fe482995c8ba5332b1a34f76)
aed857
aed857
Resolves: #1409659
aed857
---
aed857
 src/journal/journald-server.c |  2 +-
23b3cf
 src/journal/journald-syslog.c | 39 ++++++++++++++++++++++-------------
aed857
 src/journal/journald-syslog.h |  2 +-
aed857
 3 files changed, 27 insertions(+), 16 deletions(-)
aed857
aed857
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
aed857
index 7c69061f4..7e67e055e 100644
aed857
--- a/src/journal/journald-server.c
aed857
+++ b/src/journal/journald-server.c
aed857
@@ -1294,7 +1294,7 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
aed857
 
aed857
         if (fd == s->syslog_fd) {
aed857
                 if (n > 0 && n_fds == 0)
aed857
-                        server_process_syslog_message(s, strstrip(s->buffer), ucred, tv, label, label_len);
aed857
+                        server_process_syslog_message(s, s->buffer, n, ucred, tv, label, label_len);
aed857
                 else if (n_fds > 0)
aed857
                         log_warning("Got file descriptors via syslog socket. Ignoring.");
aed857
 
aed857
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
aed857
index b499a0d38..01d2bf69f 100644
aed857
--- a/src/journal/journald-syslog.c
aed857
+++ b/src/journal/journald-syslog.c
aed857
@@ -109,7 +109,7 @@ static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned
aed857
                 log_debug_errno(errno, "Failed to forward syslog message: %m");
aed857
 }
aed857
 
aed857
-static void forward_syslog_raw(Server *s, int priority, const char *buffer, const struct ucred *ucred, const struct timeval *tv) {
aed857
+static void forward_syslog_raw(Server *s, int priority, const char *buffer, size_t buffer_len, const struct ucred *ucred, const struct timeval *tv) {
aed857
         struct iovec iovec;
aed857
 
aed857
         assert(s);
aed857
@@ -118,7 +118,9 @@ static void forward_syslog_raw(Server *s, int priority, const char *buffer, cons
aed857
         if (LOG_PRI(priority) > s->max_level_syslog)
aed857
                 return;
aed857
 
aed857
-        IOVEC_SET_STRING(iovec, buffer);
aed857
+        iovec.iov_base = (char *) buffer;
aed857
+        iovec.iov_len = buffer_len;
aed857
+
aed857
         forward_syslog_iovec(s, &iovec, 1, ucred, tv);
aed857
 }
aed857
 
aed857
@@ -311,40 +313,49 @@ static void syslog_skip_date(char **buf) {
aed857
 void server_process_syslog_message(
aed857
         Server *s,
aed857
         const char *buf,
aed857
+        size_t buf_len,
aed857
         const struct ucred *ucred,
aed857
         const struct timeval *tv,
aed857
         const char *label,
aed857
         size_t label_len) {
aed857
 
aed857
         char syslog_priority[sizeof("PRIORITY=") + DECIMAL_STR_MAX(int)],
aed857
-             syslog_facility[sizeof("SYSLOG_FACILITY=") + DECIMAL_STR_MAX(int)];
aed857
+             syslog_facility[sizeof("SYSLOG_FACILITY=") + DECIMAL_STR_MAX(int)], *msg;
aed857
         const char *message = NULL, *syslog_identifier = NULL, *syslog_pid = NULL;
aed857
         struct iovec iovec[N_IOVEC_META_FIELDS + 6];
aed857
-        unsigned n = 0;
aed857
+        unsigned n = 0, i;
aed857
         int priority = LOG_USER | LOG_INFO;
aed857
         _cleanup_free_ char *identifier = NULL, *pid = NULL;
aed857
-        const char *orig;
aed857
 
aed857
         assert(s);
aed857
         assert(buf);
aed857
 
aed857
-        orig = buf;
aed857
-        syslog_parse_priority(&buf, &priority, true);
aed857
+        /* We are creating copy of the message because we want to forward original message verbatim to the legacy
aed857
+           syslog implementation */
aed857
+        for (i = buf_len; i > 0; i--)
aed857
+                if (!strchr(WHITESPACE, buf[i-1]))
aed857
+                        break;
aed857
+
aed857
+        msg = newa(char, i + 1);
aed857
+        *((char *) mempcpy(msg, buf, i)) = 0;
aed857
+        msg += strspn(msg, WHITESPACE);
aed857
+
aed857
+        syslog_parse_priority((const char **)&msg, &priority, true);
aed857
 
aed857
         if (s->forward_to_syslog)
aed857
-                forward_syslog_raw(s, priority, orig, ucred, tv);
aed857
+                forward_syslog_raw(s, priority, buf, buf_len, ucred, tv);
aed857
 
aed857
-        syslog_skip_date((char**) &buf;;
aed857
-        syslog_parse_identifier(&buf, &identifier, &pid;;
aed857
+        syslog_skip_date(&msg;;
aed857
+        syslog_parse_identifier((const char**)&msg, &identifier, &pid;;
aed857
 
aed857
         if (s->forward_to_kmsg)
aed857
-                server_forward_kmsg(s, priority, identifier, buf, ucred);
aed857
+                server_forward_kmsg(s, priority, identifier, msg, ucred);
aed857
 
aed857
         if (s->forward_to_console)
aed857
-                server_forward_console(s, priority, identifier, buf, ucred);
aed857
+                server_forward_console(s, priority, identifier, msg, ucred);
aed857
 
aed857
         if (s->forward_to_wall)
aed857
-                server_forward_wall(s, priority, identifier, buf, ucred);
aed857
+                server_forward_wall(s, priority, identifier, msg, ucred);
aed857
 
aed857
         IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=syslog");
aed857
 
aed857
@@ -368,7 +379,7 @@ void server_process_syslog_message(
aed857
                         IOVEC_SET_STRING(iovec[n++], syslog_pid);
aed857
         }
aed857
 
aed857
-        message = strjoina("MESSAGE=", buf);
aed857
+        message = strjoina("MESSAGE=", msg);
aed857
         if (message)
aed857
                 IOVEC_SET_STRING(iovec[n++], message);
aed857
 
aed857
diff --git a/src/journal/journald-syslog.h b/src/journal/journald-syslog.h
aed857
index 3774ebdf0..e593be99a 100644
aed857
--- a/src/journal/journald-syslog.h
aed857
+++ b/src/journal/journald-syslog.h
aed857
@@ -29,7 +29,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid);
aed857
 
aed857
 void server_forward_syslog(Server *s, int priority, const char *identifier, const char *message, const struct ucred *ucred, const struct timeval *tv);
aed857
 
aed857
-void server_process_syslog_message(Server *s, const char *buf, const struct ucred *ucred, const struct timeval *tv, const char *label, size_t label_len);
aed857
+void server_process_syslog_message(Server *s, const char *buf, size_t buf_len, const struct ucred *ucred, const struct timeval *tv, const char *label, size_t label_len);
aed857
 int server_open_syslog_socket(Server *s);
aed857
 
aed857
 void server_maybe_warn_forward_syslog_missed(Server *s);