[SCM] Samba Shared Repository - branch master updated

Christof Schmitt cs at samba.org
Mon Mar 23 17:00:02 MDT 2015


The branch, master has been updated
       via  72f1a2a WHATSNEW: Add logging backends
       via  f9e92fc debug: Add GPFS tracing backend
       via  b818e09 gpfswrap: Add wrappers for tracing API
       via  8dcf8cf gpfswrap: Move gpfswrap to lib/util
       via  1257977 debug: Add lttng backend
       via  4aaf270 debug: Add systemd backend
       via  409b543 param: Mark syslog and syslog_only as deprecated
       via  f1f3804f debug: Remove now unused syslog variables from debug_settings
       via  d8ba76e debug: Simplify Debug1
       via  c89a33a debug: Use backends instead of explicitly logging to syslog or file
       via  25bd64f debug: Remove codepath to open file in Debug1
       via  8a46da3 debug: Set backends from logging parameter in smb.conf
       via  5a3eddc param: Add new 'logging' parameter
       via  2681c31 debug: Add syslog backend
       via  978fee8 debug: Add file backend
       via  289a7b4 debug: Add infrastructure for supporting multiple backends
       via  364e876 debug: Move mapping from level to syslog priority to helper function
       via  1270813 debug: Move logging to callback to separate function
       via  17bd9b7 debug: Always store short version of prog_name in debug state
       via  8eba2cf debug: Remove some unneeded function declarations
       via  ba86450 debug: Remove FORMAT_BUFR_MAX, use FORMAT_BUFR_SIZE - 1 instead
       via  0509790 build: Move systemd checks to lib/util
      from  dee2b95 lib: Move get_iconv_handle() call down

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 72f1a2a0af7810a0e6011524007a509d4dc065a5
Author: Christof Schmitt <cs at samba.org>
Date:   Thu Mar 19 13:15:24 2015 -0700

    WHATSNEW: Add logging backends
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    Autobuild-User(master): Christof Schmitt <cs at samba.org>
    Autobuild-Date(master): Mon Mar 23 23:59:37 CET 2015 on sn-devel-104

commit f9e92fc2b0dc4e5c613cf795952e3484f50388ac
Author: Christof Schmitt <cs at samba.org>
Date:   Thu Feb 19 16:32:44 2015 -0700

    debug: Add GPFS tracing backend
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit b818e09c022589b073595f72b573cf93d3d197a4
Author: Christof Schmitt <cs at samba.org>
Date:   Tue Feb 24 16:18:59 2015 -0700

    gpfswrap: Add wrappers for tracing API
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 8dcf8cfe66e5d94f62f07b1710210236c01a8f97
Author: Christof Schmitt <cs at samba.org>
Date:   Thu Feb 19 16:02:11 2015 -0700

    gpfswrap: Move gpfswrap to lib/util
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 1257977125b545ebd0d991e17ffa6afc50c2d907
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 16:17:08 2015 -0700

    debug: Add lttng backend
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 4aaf270ea8b7376aedc8711f70ff85ef78ec8f26
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Mar 20 14:36:58 2015 -0700

    debug: Add systemd backend
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 409b5433d24e69a03d8638d4c65c8098539f078d
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 15:13:37 2015 -0700

    param: Mark syslog and syslog_only as deprecated
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit f1f3804f6c9d835d30a4a1c6ddb3b1a47b26a7ae
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 15:07:36 2015 -0700

    debug: Remove now unused syslog variables from debug_settings
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit d8ba76e9975463864691918096331e640929c54e
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 15:00:04 2015 -0700

    debug: Simplify Debug1
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit c89a33a07a2041e05e3cdcf6cbc0a87ee5e71319
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 14:56:38 2015 -0700

    debug: Use backends instead of explicitly logging to syslog or file
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 25bd64ffb2f214fa1230dbc8f9230fc91dd2b786
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 14:51:00 2015 -0700

    debug: Remove codepath to open file in Debug1
    
    This is not used, the log file is already open from the call to
    reopen_logs_internal.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 8a46da32805e477144e0404531edeae4df554d7d
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 14:46:32 2015 -0700

    debug: Set backends from logging parameter in smb.conf
    
    Fallback to the settings of 'syslog' and 'syslog only' if logging has not
    been set.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 5a3eddc7b94aac34fa3e482a3b3da5711a8a9ff6
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 14:21:32 2015 -0700

    param: Add new 'logging' parameter
    
    This parameter allows to configure multiple backends at the same time.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 2681c31170360f1fa52bb2d5ac92f36c92b5f616
Author: Christof Schmitt <cs at samba.org>
Date:   Mon Mar 23 13:30:31 2015 +1100

    debug: Add syslog backend
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 978fee84d0f353bef159ef8f7a084961e258d44c
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 14:00:02 2015 -0700

    debug: Add file backend
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 289a7b41bccbf05b596a86380229c089f15c5f64
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 13:49:13 2015 -0700

    debug: Add infrastructure for supporting multiple backends
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 364e8768d6ead6ff897d2ba85af5ac14aaa562a0
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 13:29:48 2015 -0700

    debug: Move mapping from level to syslog priority to helper function
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 12708136915d58f03e4638529aaf3ad1121e5bf4
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Jan 9 13:17:49 2015 -0700

    debug: Move logging to callback to separate function
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 17bd9b7349f041e9f48815e9a3e6129a83da1f8a
Author: Christof Schmitt <cs at samba.org>
Date:   Tue Feb 24 14:09:18 2015 -0700

    debug: Always store short version of prog_name in debug state
    
    Storing the prog_name in the debug state is not necessary at this point,
    but it will be used later.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 8eba2cfa51747b0802465c020a5911ce57477fa5
Author: Christof Schmitt <cs at samba.org>
Date:   Wed Dec 17 09:59:52 2014 -0700

    debug: Remove some unneeded function declarations
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit ba86450b27a8fda10670c3cc4b213d38d907d751
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Mar 20 14:19:09 2015 -0700

    debug: Remove FORMAT_BUFR_MAX, use FORMAT_BUFR_SIZE - 1 instead
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 0509790ec3696e09f6d5e6db969e46e8fd975efb
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Mar 20 12:13:14 2015 -0700

    build: Move systemd checks to lib/util
    
    Only lib/util uses the systemd library, so it makes sense to have the
    checks there. This also removes the need for the ctdb build script to
    specify an empty tag for the systemd library.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

-----------------------------------------------------------------------

Summary of changes:
 WHATSNEW.txt                               |   6 +
 ctdb/wscript                               |   2 -
 docs-xml/smbdotconf/logging/logging.xml    |  40 +++
 docs-xml/smbdotconf/logging/syslog.xml     |   4 +
 docs-xml/smbdotconf/logging/syslogonly.xml |   5 +
 lib/param/loadparm.c                       |   6 +-
 lib/param/param_table.c                    |  13 +-
 lib/util/debug.c                           | 479 ++++++++++++++++++++++-------
 lib/util/debug.h                           |   9 +-
 lib/util/debug_s3.c                        |   5 +-
 {source3/modules => lib/util}/gpfswrap.c   |  46 +++
 {source3/modules => lib/util}/gpfswrap.h   |   4 +
 lib/util/wscript                           |  16 +
 lib/util/wscript_build                     |  13 +-
 lib/util/wscript_configure                 |  46 +++
 source3/modules/vfs_gpfs.c                 |   2 +-
 source3/modules/wscript_build              |   4 +-
 source3/wscript                            |   4 -
 wscript                                    |  22 --
 19 files changed, 576 insertions(+), 150 deletions(-)
 create mode 100644 docs-xml/smbdotconf/logging/logging.xml
 rename {source3/modules => lib/util}/gpfswrap.c (86%)
 rename {source3/modules => lib/util}/gpfswrap.h (93%)


Changeset truncated at 500 lines:

diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index b389b5c..ac2e40d 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -16,6 +16,11 @@ UPGRADING
 NEW FEATURES
 ============
 
+The logging code now supports logging to multiple backends.  In
+addition to the previously available syslog and file backends, the
+backends for logging to the systemd-journal, lttng and gpfs have been
+added. Please consult the section for the 'logging' parameter in the
+smb.conf manpage for details.
 
 
 ######################################################################
@@ -27,6 +32,7 @@ smb.conf changes
 
    Parameter Name			Description	Default
    --------------			-----------	-------
+   logging				New		(empty)
 
 
 KNOWN ISSUES
diff --git a/ctdb/wscript b/ctdb/wscript
index 5957f16..f0b68cd 100755
--- a/ctdb/wscript
+++ b/ctdb/wscript
@@ -212,8 +212,6 @@ def configure(conf):
             conf.ADD_EXTRA_INCLUDES('#ctdb')
         conf.ADD_EXTRA_INCLUDES('#lib #lib/replace')
 
-        conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
-
         del(conf.env.defines['PYTHONDIR'])
         del(conf.env.defines['PYTHONARCHDIR'])
 
diff --git a/docs-xml/smbdotconf/logging/logging.xml b/docs-xml/smbdotconf/logging/logging.xml
new file mode 100644
index 0000000..41b6c08
--- /dev/null
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -0,0 +1,40 @@
+<samba:parameter name="logging"
+		 type="string"
+		 context="G"
+		 developer="1" advanced="1"
+		 xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
+<description>
+
+  <para>This parameter configures logging backends backends. Multiple
+    backends can be specified at the same time, with different log
+    levels for each backend. The parameter is a list of backends,
+    where each backend is specified as backend[:option][@loglevel].</para>
+
+  <para>The 'option' parameter can be used to pass backend-specific
+    options.</para>
+
+  <para>The log level for a backend is optional, if it is not set for
+    a backend, all messages are sent to this backend. The parameter
+    <smbconfoption name="log level"/> determines overall log levels,
+    while the log levels specified here define what is sent to the
+    individual backends.</para>
+
+  <para>When <smbconfoption name="logging"/> is set, it overrides the
+    <smbconfoption  name="syslog"/>  and  <smbconfoption  name="syslog
+    only"/> parameters.</para>
+
+  <para>Some backends are only available when Samba has been compiled
+  with the additional libraries. The overall list of logging backends:</para>
+
+  <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>
+    <listitem><para><parameter moreinfo="none">lttng</parameter></para></listitem>
+    <listitem><para><parameter moreinfo="none">gpfs</parameter></para></listitem>
+  </itemizedlist>
+
+</description>
+<value type="default"></value>
+<value type="example">syslog at 1 file</value>
+</samba:parameter>
diff --git a/docs-xml/smbdotconf/logging/syslog.xml b/docs-xml/smbdotconf/logging/syslog.xml
index e4722d8..f58a9a5 100644
--- a/docs-xml/smbdotconf/logging/syslog.xml
+++ b/docs-xml/smbdotconf/logging/syslog.xml
@@ -16,6 +16,10 @@
     level less than this value will be sent to syslog. There still will be some
     logging to log.[sn]mbd even if <emphasis>syslog only</emphasis> is enabled.
     </para>
+
+    <para>The <smbconfoption name="logging"/> parameter should be used
+      instead. When <smbconfoption name="logging"/> is set, it
+      overrides the <smbconfoption name="syslog"/> parameter.</para>
 </description>
 <value type="default">1</value>
 </samba:parameter>
diff --git a/docs-xml/smbdotconf/logging/syslogonly.xml b/docs-xml/smbdotconf/logging/syslogonly.xml
index 0fe7471..aec40c2 100644
--- a/docs-xml/smbdotconf/logging/syslogonly.xml
+++ b/docs-xml/smbdotconf/logging/syslogonly.xml
@@ -9,6 +9,11 @@
     syslog only, and not to the debug log files. There still will be some
 	logging to log.[sn]mbd even if <emphasis>syslog only</emphasis> is enabled.
     </para>
+
+
+    <para>The <smbconfoption name="logging"/> parameter should be used
+      instead. When <smbconfoption name="logging"/> is set, it
+      overrides the <smbconfoption name="syslog only"/> parameter.</para>
 </description>
 <value type="default">no</value>
 </samba:parameter>
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index c619ad2..e2b0ca2 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -2875,15 +2875,15 @@ static bool lpcfg_update(struct loadparm_context *lp_ctx)
 	ZERO_STRUCT(settings);
 	/* Add any more debug-related smb.conf parameters created in
 	 * future here */
-	settings.syslog = lp_ctx->globals->syslog;
-	settings.syslog_only = lp_ctx->globals->syslog_only;
 	settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
 	settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
 	settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
 	settings.debug_pid = lp_ctx->globals->debug_pid;
 	settings.debug_uid = lp_ctx->globals->debug_uid;
 	settings.debug_class = lp_ctx->globals->debug_class;
-	debug_set_settings(&settings);
+	debug_set_settings(&settings, lp_ctx->globals->logging,
+			   lp_ctx->globals->syslog,
+			   lp_ctx->globals->syslog_only);
 
 	/* FIXME: This is a bit of a hack, but we can't use a global, since 
 	 * not everything that uses lp also uses the socket library */
diff --git a/lib/param/param_table.c b/lib/param/param_table.c
index 447c99b..d78b4d1 100644
--- a/lib/param/param_table.c
+++ b/lib/param/param_table.c
@@ -1185,7 +1185,7 @@ struct parm_struct parm_table[] = {
 		.offset		= GLOBAL_VAR(syslog),
 		.special	= NULL,
 		.enum_list	= NULL,
-		.flags		= FLAG_ADVANCED,
+		.flags		= FLAG_ADVANCED | FLAG_DEPRECATED,
 	},
 	{
 		.label		= "syslog only",
@@ -1194,7 +1194,7 @@ struct parm_struct parm_table[] = {
 		.offset		= GLOBAL_VAR(syslog_only),
 		.special	= NULL,
 		.enum_list	= NULL,
-		.flags		= FLAG_ADVANCED,
+		.flags		= FLAG_ADVANCED | FLAG_DEPRECATED,
 	},
 	{
 		.label		= "log file",
@@ -1206,6 +1206,15 @@ struct parm_struct parm_table[] = {
 		.flags		= FLAG_ADVANCED,
 	},
 	{
+		.label		= "logging",
+		.type		= P_STRING,
+		.p_class	= P_GLOBAL,
+		.offset		= GLOBAL_VAR(logging),
+		.special	= NULL,
+		.enum_list	= NULL,
+		.flags		= FLAG_ADVANCED,
+	},
+	{
 		.label		= "max log size",
 		.type		= P_BYTES,
 		.p_class	= P_GLOBAL,
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 80a1c25..6b16cd7 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -37,14 +37,13 @@
 
 /* -------------------------------------------------------------------------- **
  * Defines...
- *
- *  FORMAT_BUFR_MAX - Index of the last byte of the format buffer;
- *                    format_bufr[FORMAT_BUFR_MAX] should always be reserved
- *                    for a terminating null byte.
  */
 
+/*
+ * format_bufr[FORMAT_BUFR_SIZE - 1] should always be reserved
+ * for a terminating null byte.
+ */
 #define FORMAT_BUFR_SIZE 1024
-#define FORMAT_BUFR_MAX (FORMAT_BUFR_SIZE - 1)
 
 /* -------------------------------------------------------------------------- **
  * This module implements Samba's debugging utility.
@@ -103,6 +102,305 @@ static struct {
 	.fd = 2 /* stderr by default */
 };
 
+#if defined(WITH_SYSLOG) || defined(HAVE_SYSTEMD_JOURNAL)
+static int debug_level_to_priority(int level)
+{
+	/*
+	 * map debug levels to syslog() priorities note that not all
+	 * DEBUG(0, ...) calls are necessarily errors
+	 */
+	static const int priority_map[4] = {
+		LOG_ERR,     /* 0 */
+		LOG_WARNING, /* 1 */
+		LOG_NOTICE,  /* 2 */
+		LOG_INFO,    /* 3 */
+	};
+	int priority;
+
+	if( level >= ARRAY_SIZE(priority_map) || level < 0)
+		priority = LOG_DEBUG;
+	else
+		priority = priority_map[level];
+
+	return priority;
+}
+#endif
+
+/* -------------------------------------------------------------------------- **
+ * Debug backends. When logging to DEBUG_FILE, send the log entries to
+ * all active backends.
+ */
+
+static void debug_file_log(int msg_level,
+			   const char *msg, const char *msg_no_nl)
+{
+	check_log_size();
+	write(state.fd, msg, strlen(msg));
+}
+
+#ifdef WITH_SYSLOG
+static void debug_syslog_reload(bool enabled, bool previously_enabled,
+				const char *prog_name)
+{
+	if (enabled && !previously_enabled) {
+#ifdef LOG_DAEMON
+		openlog(prog_name, LOG_PID, SYSLOG_FACILITY);
+#else
+		/* for old systems that have no facility codes. */
+		openlog(prog_name, LOG_PID );
+#endif
+		return;
+	}
+
+	if (!enabled && previously_enabled) {
+		closelog();
+	}
+}
+
+static void debug_syslog_log(int msg_level,
+			     const char *msg, const char *msg_no_nl)
+{
+	int priority;
+
+	priority = debug_level_to_priority(msg_level);
+
+	/*
+	 * Specify the facility to interoperate with other syslog
+	 * callers (vfs_full_audit for example).
+	 */
+	priority |= SYSLOG_FACILITY;
+
+	syslog(priority, "%s", msg);
+}
+#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
+
+#ifdef HAVE_LTTNG_TRACEF
+#include <lttng/tracef.h>
+static void debug_lttng_log(int msg_level,
+			    const char *msg, const char *msg_no_nl)
+{
+	tracef(msg_no_nl);
+}
+#endif /* WITH_LTTNG_TRACEF */
+
+#ifdef HAVE_GPFS
+#include "gpfswrap.h"
+static void debug_gpfs_reload(bool enabled, bool previously_enabled,
+			      const char *prog_name)
+{
+	gpfswrap_init();
+
+	if (enabled && !previously_enabled) {
+		gpfswrap_init_trace();
+		return;
+	}
+
+	if (!enabled && previously_enabled) {
+		gpfswrap_fini_trace();
+		return;
+	}
+
+	if (enabled) {
+		/*
+		 * Trigger GPFS library to adjust state if necessary.
+		 */
+		gpfswrap_query_trace();
+	}
+}
+
+static void debug_gpfs_log(int msg_level,
+			   const char *msg, const char *msg_no_nl)
+{
+	gpfswrap_add_trace(msg_level, msg_no_nl);
+}
+#endif /* HAVE_GPFS */
+
+static struct debug_backend {
+	const char *name;
+	int log_level;
+	int new_log_level;
+	void (*reload)(bool enabled, bool prev_enabled, const char *prog_name);
+	void (*log)(int msg_level, const char *msg, const char *msg_no_nl);
+} debug_backends[] = {
+	{
+		.name = "file",
+		.log = debug_file_log,
+	},
+#ifdef WITH_SYSLOG
+	{
+		.name = "syslog",
+		.reload = debug_syslog_reload,
+		.log = debug_syslog_log,
+	},
+#endif
+
+#ifdef HAVE_SYSTEMD_JOURNAL
+	{
+		.name = "systemd",
+		.log = debug_systemd_log,
+	},
+#endif
+
+#ifdef HAVE_LTTNG_TRACEF
+	{
+		.name = "lttng",
+		.log = debug_lttng_log,
+	},
+#endif
+
+#ifdef HAVE_GPFS
+	{
+		.name = "gpfs",
+		.reload = debug_gpfs_reload,
+		.log = debug_gpfs_log,
+	},
+#endif
+};
+
+static struct debug_backend *debug_find_backend(const char *name)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		if (strcmp(name, debug_backends[i].name) == 0) {
+			return &debug_backends[i];
+		}
+	}
+
+	return NULL;
+}
+
+/*
+ * parse "backend[:option][@loglevel]
+ */
+static void debug_backend_parse_token(char *tok)
+{
+	char *backend_name_option, *backend_name,*backend_level, *saveptr;
+	struct debug_backend *b;
+
+	/*
+	 * First parse into backend[:option] and loglevel
+	 */
+	backend_name_option = strtok_r(tok, "@\0", &saveptr);
+	if (backend_name_option == NULL) {
+		return;
+	}
+
+	backend_level = strtok_r(NULL, "\0", &saveptr);
+
+	/*
+	 * Now parse backend[:option]
+	 */
+	backend_name = strtok_r(backend_name_option, ":\0", &saveptr);
+	if (backend_name == NULL) {
+		return;
+	}
+
+	/*
+	 * No backend is using the option yet.
+	 */
+#if 0
+	backend_option = strtok_r(NULL, "\0", &saveptr);
+#endif
+
+	/*
+	 * Find and update backend
+	 */
+	b = debug_find_backend(backend_name);
+	if (b == NULL) {
+		return;
+	}
+
+	if (backend_level == NULL) {
+		b->new_log_level = MAX_DEBUG_LEVEL;
+	} else {
+		b->new_log_level = atoi(backend_level);
+	}
+}
+
+/*
+ * parse "backend1[:option1][@loglevel1] backend2[option2][@loglevel2] ... "
+ * and enable/disable backends accordingly
+ */
+static void debug_set_backends(const char *param)
+{
+	size_t str_len = strlen(param);
+	char str[str_len+1];
+	char *tok, *saveptr;
+	int i;
+
+	/*
+	 * initialize new_log_level to detect backends that have been
+	 * disabled
+	 */
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		debug_backends[i].new_log_level = -1;
+	}
+
+	memcpy(str, param, str_len + 1);
+
+	tok = strtok_r(str, LIST_SEP, &saveptr);
+	if (tok == NULL) {
+		return;
+	}
+
+	while (tok != NULL) {
+		debug_backend_parse_token(tok);
+		tok = strtok_r(NULL, LIST_SEP, &saveptr);
+	}
+
+	/*
+	 * Let backends react to config changes
+	 */
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		struct debug_backend *b = &debug_backends[i];
+
+		if (b->reload) {
+			bool enabled = b->new_log_level > -1;
+			bool previously_enabled = b->log_level > -1;
+
+			b->reload(enabled, previously_enabled, state.prog_name);
+		}
+		b->log_level = b->new_log_level;
+	}
+}
+
+static void debug_backends_log(const char *msg, int msg_level)
+{
+	char msg_no_nl[FORMAT_BUFR_SIZE];
+	int i, len;
+
+	/*
+	 * Some backends already add an extra newline, so also provide
+	 * a buffer without the newline character.
+	 */
+	len = MIN(strlen(msg), FORMAT_BUFR_SIZE - 1);
+	if (msg[len - 1] == '\n') {
+		len--;
+	}
+
+	memcpy(msg_no_nl, msg, len);
+	msg_no_nl[len] = '\0';
+
+	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
+		if (msg_level <= debug_backends[i].log_level) {
+			debug_backends[i].log(msg_level, msg, msg_no_nl);
+		}
+	}
+}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list