dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
Harald Hoyer fe20ad
From 9d5dbdd18f4c106856f031ae94d4f05aa3259de7 Mon Sep 17 00:00:00 2001
Harald Hoyer fe20ad
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer fe20ad
Date: Thu, 1 Aug 2013 12:14:02 +0200
Harald Hoyer fe20ad
Subject: [PATCH] journal: handle multiline syslog messages
Harald Hoyer fe20ad
MIME-Version: 1.0
Harald Hoyer fe20ad
Content-Type: text/plain; charset=UTF-8
Harald Hoyer fe20ad
Content-Transfer-Encoding: 8bit
Harald Hoyer fe20ad
Harald Hoyer fe20ad
Since the journal can handle multiple lines just well natively,
Harald Hoyer fe20ad
and rsyslog can be configured to handle them as well, there is no need
Harald Hoyer fe20ad
to truncate messages from syslog() after the first newline.
Harald Hoyer fe20ad
Harald Hoyer fe20ad
Reproducer:
Harald Hoyer fe20ad
Harald Hoyer fe20ad
1. Add following four lines to /etc/rsyslog.conf
Harald Hoyer fe20ad
Harald Hoyer fe20ad
   ----------
Harald Hoyer fe20ad
   $EscapeControlCharactersOnReceive off
Harald Hoyer fe20ad
   $ActionFileDefaultTemplate RSYSLOG_SysklogdFileFormat
Harald Hoyer fe20ad
   $SpaceLFOnReceive on
Harald Hoyer fe20ad
   $DropTrailingLFOnReception off
Harald Hoyer fe20ad
   ----------
Harald Hoyer fe20ad
Harald Hoyer fe20ad
3. Restart rsyslog
Harald Hoyer fe20ad
  # service rsyslog restart
Harald Hoyer fe20ad
Harald Hoyer fe20ad
4. Compile and run the following program
Harald Hoyer fe20ad
Harald Hoyer fe20ad
   ----------
Harald Hoyer fe20ad
   #include <stdio.h>
Harald Hoyer fe20ad
   #include <syslog.h>
Harald Hoyer fe20ad
Harald Hoyer fe20ad
   int main()
Harald Hoyer fe20ad
   {
Harald Hoyer fe20ad
    syslog(LOG_INFO, "aaa%caaa", '\n');
Harald Hoyer fe20ad
    return 0;
Harald Hoyer fe20ad
   }
Harald Hoyer fe20ad
   ----------
Harald Hoyer fe20ad
Harald Hoyer fe20ad
Actual results:
Harald Hoyer fe20ad
Below message appears in /var/log/messages.
Harald Hoyer fe20ad
Harald Hoyer fe20ad
   ----------
Harald Hoyer fe20ad
   Sep  7 19:19:39 localhost test2: aaa
Harald Hoyer fe20ad
   ----------
Harald Hoyer fe20ad
Harald Hoyer fe20ad
Expected results:
Harald Hoyer fe20ad
Below message, which worked prior to systemd-journald
Harald Hoyer fe20ad
appears in /var/log/messages.
Harald Hoyer fe20ad
Harald Hoyer fe20ad
   ----------
Harald Hoyer fe20ad
   Sep  7 19:19:39 localhost test2: aaa aaa
Harald Hoyer fe20ad
Harald Hoyer fe20ad
https://bugzilla.redhat.com/show_bug.cgi?id=855313
Harald Hoyer fe20ad
---
Harald Hoyer fe20ad
 src/journal/journald-server.c | 7 +------
Harald Hoyer fe20ad
 1 file changed, 1 insertion(+), 6 deletions(-)
Harald Hoyer fe20ad
Harald Hoyer fe20ad
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
Harald Hoyer fe20ad
index 60c32b1..c5c195a 100644
Harald Hoyer fe20ad
--- a/src/journal/journald-server.c
Harald Hoyer fe20ad
+++ b/src/journal/journald-server.c
Harald Hoyer fe20ad
@@ -1240,12 +1240,7 @@ int process_event(Server *s, struct epoll_event *ev) {
Harald Hoyer fe20ad
                                 char *e;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
                                 if (n > 0 && n_fds == 0) {
Harald Hoyer fe20ad
-                                        e = memchr(s->buffer, '\n', n);
Harald Hoyer fe20ad
-                                        if (e)
Harald Hoyer fe20ad
-                                                *e = 0;
Harald Hoyer fe20ad
-                                        else
Harald Hoyer fe20ad
-                                                s->buffer[n] = 0;
Harald Hoyer fe20ad
-
Harald Hoyer fe20ad
+                                        s->buffer[n] = 0;
Harald Hoyer fe20ad
                                         server_process_syslog_message(s, strstrip(s->buffer), ucred, tv, label, label_len);
Harald Hoyer fe20ad
                                 } else if (n_fds > 0)
Harald Hoyer fe20ad
                                         log_warning("Got file descriptors via syslog socket. Ignoring.");