[systemd-devel] [PATCH] journald: check if socket is in connected state before forwarding to syslog

Piotr Wilczek p.wilczek at samsung.com
Fri Jul 11 00:52:22 PDT 2014


Currently syslog socket is not correctly verified if is in connected state.
This results in sending messages to a socket that is not connected which is
not allowed.

In this patch the socket is correctly checked. If the socket is not connected
forwarding to syslog is disabled.

This patch causes about 15% decrease in CPU usage on Trats2 when ForwardToSyslog=yes
but the syslog socket is not connected.

Signed-off-by: Piotr Wilczek <p.wilczek at samsung.com>
---
 src/journal/journald-server.c | 2 +-
 src/journal/journald-syslog.c | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 58410a2..186b1a8 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1558,7 +1558,7 @@ int server_init(Server *s) {
 
         r = server_open_syslog_socket(s);
         if (r < 0)
-                return r;
+                s->forward_to_syslog = false;
 
         r = server_open_native_socket(s);
         if (r < 0)
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
index b826e23..f86c17b 100644
--- a/src/journal/journald-syslog.c
+++ b/src/journal/journald-syslog.c
@@ -478,6 +478,10 @@ int server_open_syslog_socket(Server *s) {
                 return r;
         }
 
+        r = getsockopt(s->syslog_fd, SOL_SOCKET, SO_ERROR, NULL, NULL);
+        if (r < 0)
+                return r;
+
         return 0;
 }
 
-- 
1.9.1



More information about the systemd-devel mailing list