File syslog-ng-3.3.5-sd-sock-name.patch of Package syslog-ng

From da1d7a240090021188db1bb818159ca1999d54e0 Mon Sep 17 00:00:00 2001
From: Marius Tomaschewski <mt@suse.com>
Date: Thu, 23 Feb 2012 17:08:55 +0100
Subject: [PATCH] Detect if to use /run/systemd/journal/syslog under systemd

Detect if we have to use the new /run/systemd/journal/syslog
socket under newer systemd versions, instead of the default
_PATH_LOG (/dev/log) socket.

Signed-off-by: Marius Tomaschewski <mt@suse.com>
---
 modules/afsocket/afunix.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/modules/afsocket/afunix.c b/modules/afsocket/afunix.c
index 8145f1a..5fe600a 100644
--- a/modules/afsocket/afunix.c
+++ b/modules/afsocket/afunix.c
@@ -34,12 +34,25 @@
 
 #include <string.h>
 #include <sys/types.h>
+#include <sys/syslog.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdlib.h>
 
+#if ENABLE_SYSTEMD
+/*
+ * default log socket name is usually defined
+ * as _PATH_LOG in the sys/socket.h (/dev/log
+ * on linux or /var/run/log on bsd), but under
+ * systemd, we have to use a different one...
+ */
+#ifndef SYSTEMD_PATH_LOG
+#define SYSTEMD_PATH_LOG "/run/systemd/journal/syslog"
+#endif
+#endif
+
 void
 afunix_sd_set_uid(LogDriver *s, gchar *owner)
 {
@@ -228,6 +241,22 @@ afunix_sd_new(gchar *filename, guint32 flags)
   else if (self->super.flags & AFSOCKET_STREAM)
     afsocket_sd_set_transport(&self->super.super.super, "unix-stream");
 
+#if defined(_PATH_LOG) && ENABLE_SYSTEMD
+  /*
+   * systemd >= 38 wants we use /run/systemd/journal/syslog,
+   * instead of /dev/log, so use it when the socket exists...
+   */
+  if(sd_booted() && strcmp(filename, _PATH_LOG) == 0) {
+    struct stat st;
+    if(stat(SYSTEMD_PATH_LOG, &st) != -1 && S_ISSOCK(st.st_mode)) {
+      msg_debug("Systemd socket name override",
+                evt_tag_str("log-socket-old", filename),
+                evt_tag_str("log-socket-new", SYSTEMD_PATH_LOG),
+		NULL);
+      filename = SYSTEMD_PATH_LOG;
+    }
+  }
+#endif
   self->filename = g_strdup(filename);
   self->owner = -1;
   self->group = -1;
-- 
1.7.7

openSUSE Build Service is sponsored by