debug: Add systemd backend
authorChristof Schmitt <cs@samba.org>
Fri, 20 Mar 2015 21:36:58 +0000 (14:36 -0700)
committerChristof Schmitt <cs@samba.org>
Mon, 23 Mar 2015 20:22:11 +0000 (21:22 +0100)
Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
docs-xml/smbdotconf/logging/logging.xml
lib/util/debug.c
lib/util/wscript_build
lib/util/wscript_configure

index f888c4623e8e4d2c6e6fb9b475215708f6b0811b..039a9656e88af8c09acdbdb8c0204f367d5993ec 100644 (file)
@@ -29,6 +29,7 @@
   <itemizedlist>
     <listitem><para><parameter moreinfo="none">syslog</parameter></para></listitem>
     <listitem><para><parameter moreinfo="none">file</parameter></para></listitem>
+    <listitem><para><parameter moreinfo="none">systemd</parameter></para></listitem>
   </itemizedlist>
 
 </description>
index 7602a5156874e17859cc86182fc054af1cb6e607..81acbb1b33d99c8dec7f2abc774d43c9e829db06 100644 (file)
@@ -102,7 +102,7 @@ static struct {
        .fd = 2 /* stderr by default */
 };
 
-#ifdef WITH_SYSLOG
+#if defined(WITH_SYSLOG) || defined(HAVE_SYSTEMD_JOURNAL)
 static int debug_level_to_priority(int level)
 {
        /*
@@ -174,6 +174,18 @@ static void debug_syslog_log(int msg_level,
 }
 #endif /* WITH_SYSLOG */
 
+#ifdef HAVE_SYSTEMD_JOURNAL
+#include <systemd/sd-journal.h>
+static void debug_systemd_log(int msg_level,
+                             const char *msg, const char *msg_no_nl)
+{
+       sd_journal_send("MESSAGE=%s", msg_no_nl,
+                       "PRIORITY=%d", debug_level_to_priority(msg_level),
+                       "LEVEL=%d", msg_level,
+                       NULL);
+}
+#endif
+
 static struct debug_backend {
        const char *name;
        int log_level;
@@ -192,6 +204,13 @@ static struct debug_backend {
                .log = debug_syslog_log,
        },
 #endif
+
+#ifdef HAVE_SYSTEMD_JOURNAL
+       {
+               .name = "systemd",
+               .log = debug_systemd_log,
+       },
+#endif
 };
 
 static struct debug_backend *debug_find_backend(const char *name)
index b2e406ec8e8411b5bc004dc4d1655d58e2f0b24a..5f89c83a20bfbb355617b50299ab68e0bdbf2edc 100755 (executable)
@@ -31,6 +31,7 @@ bld.SAMBA_SUBSYSTEM('close-low-fd',
 bld.SAMBA_LIBRARY('samba-debug',
                   source='debug.c',
                   deps='replace time-basic close-low-fd talloc socket-blocking',
+                  public_deps='systemd-journal',
                   local_include=False,
                   private_library=True)
 
index 8cf77b432ae38dc2ecd94c4a0e0b9cf04d05d10b..0153fb8f67f5de17c8fccb71b549c246eedf6dbe 100644 (file)
@@ -113,3 +113,17 @@ if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_DAEMON_H') and
 else:
     conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
     conf.undefine('HAVE_SYSTEMD')
+
+if Options.options.enable_systemd != False:
+    conf.check_cfg(package='libsystemd-journal', args='--cflags --libs',
+                   msg='Checking for libsystemd-journal',
+                   uselib_store="SYSTEMD-JOURNAL")
+    conf.CHECK_HEADERS('systemd/sd-journal.h', lib='systemd-journal')
+    conf.CHECK_LIB('systemd-journal', shlib=True)
+
+if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_JOURNAL_H') and
+    conf.CONFIG_SET('HAVE_LIBSYSTEMD_JOURNAL')):
+    conf.DEFINE('HAVE_SYSTEMD_JOURNAL', '1')
+else:
+    conf.SET_TARGET_TYPE('systemd-journal', 'EMPTY')
+    conf.undefine('HAVE_SYSTEMD_JOURNAL')