[PATCH] New debug backend "ringbuf"

Ralph Böhme slow at samba.org
Mon Jan 9 21:45:01 UTC 2017


Hi!

On Mon, Jan 09, 2017 at 10:16:01PM +0100, Ralph Böhme wrote:
> On Tue, Jan 10, 2017 at 10:09:31AM +1300, Andrew Bartlett wrote:
> > Can you register it in source4/lib/messaging.c as well, so we can ask a
> > 'samba' process the same question?
> 
> sure, updated patchset on the way...

here we go.

Cheerio!
-slow
-------------- next part --------------
From 811fe48b7f1bd6a8982a21cc5848f5f56b7bbc05 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sun, 8 Jan 2017 13:57:51 +0100
Subject: [PATCH 1/8] pidl: allow mixing enum entries with and without values

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 pidl/lib/Parse/Pidl/Samba4/Header.pm | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/pidl/lib/Parse/Pidl/Samba4/Header.pm b/pidl/lib/Parse/Pidl/Samba4/Header.pm
index e9b7bee..f73c30c 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Header.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Header.pm
@@ -140,8 +140,7 @@ sub HeaderEnum($$;$)
 		pidl "\n";
 		pidl "#else\n";
 		my $count = 0;
-		my $with_val = 0;
-		my $without_val = 0;
+		my $fstr = "%d";
 		pidl " { __do_not_use_enum_$name=0x7FFFFFFF}\n";
 		foreach my $e (@{$enum->{ELEMENTS}}) {
 			my $t = "$e";
@@ -150,15 +149,16 @@ sub HeaderEnum($$;$)
 			if ($t =~ /(.*)=(.*)/) {
 				$name = $1;
 				$value = $2;
-				$with_val = 1;
-				fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!")
-					unless ($without_val == 0);
+				$count = oct($value) if $value =~ /^0/;
+				$count++;
+				if ($value =~ /^0x/) {
+					$fstr = "0x%x";
+				} else {
+					$fstr = "%d";
+				}
 			} else {
 				$name = $t;
-				$value = $count++;
-				$without_val = 1;
-				fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!")
-					unless ($with_val == 0);
+				$value = sprintf $fstr, $count++;
 			}
 			pidl "#define $name ( $value )\n";
 		}
-- 
2.7.4


From 691b9e8527c651f293bba67e4dd1b100d0bd1ab5 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sun, 8 Jan 2017 13:59:05 +0100
Subject: [PATCH 2/8] messaging.idl: convert to automatic enum enumeration

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 librpc/idl/messaging.idl | 148 +++++++++++++++++++++++------------------------
 1 file changed, 74 insertions(+), 74 deletions(-)

diff --git a/librpc/idl/messaging.idl b/librpc/idl/messaging.idl
index a54d13c..48f68c2 100644
--- a/librpc/idl/messaging.idl
+++ b/librpc/idl/messaging.idl
@@ -17,124 +17,124 @@ interface messaging
 
 		/* general messages */
 		MSG_DEBUG			= 0x0001,
-		MSG_PING			= 0x0002,
-		MSG_PONG			= 0x0003,
-		MSG_PROFILE			= 0x0004,
-		MSG_REQ_DEBUGLEVEL		= 0x0005,
-		MSG_DEBUGLEVEL			= 0x0006,
-		MSG_REQ_PROFILELEVEL		= 0x0007,
-		MSG_PROFILELEVEL		= 0x0008,
-		MSG_REQ_POOL_USAGE		= 0x0009,
-		MSG_POOL_USAGE			= 0x000A,
+		MSG_PING,
+		MSG_PONG,
+		MSG_PROFILE,
+		MSG_REQ_DEBUGLEVEL,
+		MSG_DEBUGLEVEL,
+		MSG_REQ_PROFILELEVEL,
+		MSG_PROFILELEVEL,
+		MSG_REQ_POOL_USAGE,
+		MSG_POOL_USAGE,
 
 		/* If dmalloc is included, set a steady-state mark */
-		MSG_REQ_DMALLOC_MARK		= 0x000B,
+		MSG_REQ_DMALLOC_MARK,
 
 		/* If dmalloc is included, dump to the dmalloc log a description of
 		 * what has changed since the last MARK */
-		MSG_REQ_DMALLOC_LOG_CHANGED	= 0x000C,
-		MSG_SHUTDOWN			= 0x000D,
+		MSG_REQ_DMALLOC_LOG_CHANGED,
+		MSG_SHUTDOWN,
 
-		/* ID_CACHE_FLUSH		= 0x000E, obsoleted */
-		ID_CACHE_DELETE			= 0x000F,
-		ID_CACHE_KILL			= 0x0010,
+		/* ID_CACHE_FLUSH obsoleted */
+		ID_CACHE_DELETE,
+		ID_CACHE_KILL,
 
 		/* Changes to smb.conf are really of general interest */
-		MSG_SMB_CONF_UPDATED		= 0x0021,
+		MSG_SMB_CONF_UPDATED,
 
-		MSG_PREFORK_CHILD_EVENT		= 0x0031,
-		MSG_PREFORK_PARENT_EVENT	= 0x0032,
+		MSG_PREFORK_CHILD_EVENT,
+		MSG_PREFORK_PARENT_EVENT,
 
 		/* nmbd messages */
 		MSG_FORCE_ELECTION		= 0x0101,
-		MSG_WINS_NEW_ENTRY		= 0x0102,
-		MSG_SEND_PACKET			= 0x0103,
+		MSG_WINS_NEW_ENTRY,
+		MSG_SEND_PACKET,
 
 		/* printing messages */
-		/* MSG_PRINTER_NOTIFY		= 0x2001,  Obsoleted */
-		MSG_PRINTER_NOTIFY2		= 0x0202,
-		MSG_PRINTER_DRVUPGRADE		= 0x0203,
-		MSG_PRINTERDATA_INIT_RESET	= 0x0204,
-		MSG_PRINTER_UPDATE		= 0x0205,
-		MSG_PRINTER_MOD			= 0x0206,
-		MSG_PRINTER_PCAP		= 0x0207,
+		/* MSG_PRINTER_NOTIFY obsoleted */
+		MSG_PRINTER_NOTIFY2		= 0x0201,
+		MSG_PRINTER_DRVUPGRADE,
+		MSG_PRINTERDATA_INIT_RESET,
+		MSG_PRINTER_UPDATE,
+		MSG_PRINTER_MOD,
+		MSG_PRINTER_PCAP,
 
 		/* smbd messages */
-		/* MSG_SMB_CONF_UPDATED		= 0x0301,  Obsoleted */
-		MSG_SMB_FORCE_TDIS		= 0x0302,
-		/* MSG_SMB_SAM_SYNC		= 0x0303,  Obsoleted */
-		/* MSG_SMB_SAM_REPL		= 0x0304,  Obsoleted */
-		MSG_SMB_UNLOCK			= 0x0305,
-		MSG_SMB_BREAK_REQUEST		= 0x0306,
-		/* MSG_SMB_BREAK_RESPONSE	= 0x0307,  Obsoleted */
-		/* MSG_SMB_ASYNC_LEVEL2_BREAK	= 0x0308,  Obsoleted */
-		/* MSG_SMB_OPEN_RETRY		= 0x0309,  Obsoleted */
-		MSG_SMB_KERNEL_BREAK		= 0x030A,
-		MSG_SMB_FILE_RENAME		= 0x030B,
-		MSG_SMB_INJECT_FAULT		= 0x030C,
-		MSG_SMB_BLOCKING_LOCK_CANCEL	= 0x030D,
-		MSG_SMB_NOTIFY			= 0x030E,
-		MSG_SMB_STAT_CACHE_DELETE	= 0x030F,
+		/* MSG_SMB_CONF_UPDATED obsoleted */
+		MSG_SMB_FORCE_TDIS		= 0x0301,
+		/* MSG_SMB_SAM_SYNC obsoleted */
+		/* MSG_SMB_SAM_REPL obsoleted */
+		MSG_SMB_UNLOCK,
+		MSG_SMB_BREAK_REQUEST,
+		/* MSG_SMB_BREAK_RESPONSE obsoleted */
+		/* MSG_SMB_ASYNC_LEVEL2_BREAK obsoleted */
+		/* MSG_SMB_OPEN_RETRY obsoleted */
+		MSG_SMB_KERNEL_BREAK,
+		MSG_SMB_FILE_RENAME,
+		MSG_SMB_INJECT_FAULT,
+		MSG_SMB_BLOCKING_LOCK_CANCEL,
+		MSG_SMB_NOTIFY,
+		MSG_SMB_STAT_CACHE_DELETE,
 
 		/* Samba4 compatibility */
-		MSG_PVFS_NOTIFY			= 0x0310,
+		MSG_PVFS_NOTIFY,
 
 		/* cluster reconfigure events */
-		MSG_SMB_BRL_VALIDATE		= 0x0311,
+		MSG_SMB_BRL_VALIDATE,
 
 		/*Close a specific file given a share entry. */
-		MSG_SMB_CLOSE_FILE		= 0x0313,
+		MSG_SMB_CLOSE_FILE,
 
 		/* Trigger a notify cleanup run */
-		MSG_SMB_NOTIFY_CLEANUP		= 0x0314,
-		MSG_SMB_SCAVENGER		= 0x0315,
+		MSG_SMB_NOTIFY_CLEANUP,
+		MSG_SMB_SCAVENGER,
 
 		/* shutdown connection for given client */
-		MSG_SMB_KILL_CLIENT_IP		= 0x0316,
+		MSG_SMB_KILL_CLIENT_IP,
 
 		/* Tell number of child processes */
-		MSG_SMB_TELL_NUM_CHILDREN       = 0x0317,
-		MSG_SMB_NUM_CHILDREN            = 0x0318,
+		MSG_SMB_TELL_NUM_CHILDREN,
+		MSG_SMB_NUM_CHILDREN,
 
 		/* Cancel a notify, directory got deleted */
-		MSG_SMB_NOTIFY_CANCEL_DELETED   = 0x0319,
+		MSG_SMB_NOTIFY_CANCEL_DELETED,
 
 		/* notifyd messages */
-		MSG_SMB_NOTIFY_REC_CHANGE	= 0x031A,
-		MSG_SMB_NOTIFY_TRIGGER		= 0x031B,
-		MSG_SMB_NOTIFY_GET_DB		= 0x031C,
-		MSG_SMB_NOTIFY_DB		= 0x031D,
-		MSG_SMB_NOTIFY_REC_CHANGES	= 0x031E,
-		MSG_SMB_NOTIFY_STARTED          = 0x031F,
+		MSG_SMB_NOTIFY_REC_CHANGE,
+		MSG_SMB_NOTIFY_TRIGGER,
+		MSG_SMB_NOTIFY_GET_DB,
+		MSG_SMB_NOTIFY_DB,
+		MSG_SMB_NOTIFY_REC_CHANGES,
+		MSG_SMB_NOTIFY_STARTED,
 
 		/* winbind messages */
 		MSG_WINBIND_FINISHED		= 0x0401,
-		MSG_WINBIND_FORGET_STATE	= 0x0402,
-		MSG_WINBIND_ONLINE		= 0x0403,
-		MSG_WINBIND_OFFLINE		= 0x0404,
-		MSG_WINBIND_ONLINESTATUS	= 0x0405,
-		MSG_WINBIND_TRY_TO_GO_ONLINE	= 0x0406,
-		MSG_WINBIND_FAILED_TO_GO_ONLINE = 0x0407,
-		MSG_WINBIND_VALIDATE_CACHE	= 0x0408,
-		MSG_WINBIND_DUMP_DOMAIN_LIST	= 0x0409,
-		MSG_WINBIND_IP_DROPPED		= 0x040A,
-		MSG_WINBIND_DOMAIN_ONLINE	= 0x040B,
-		MSG_WINBIND_DOMAIN_OFFLINE	= 0x040C,
-		MSG_WINBIND_NEW_TRUSTED_DOMAIN	= 0x040D,
+		MSG_WINBIND_FORGET_STATE,
+		MSG_WINBIND_ONLINE,
+		MSG_WINBIND_OFFLINE,
+		MSG_WINBIND_ONLINESTATUS,
+		MSG_WINBIND_TRY_TO_GO_ONLINE,
+		MSG_WINBIND_FAILED_TO_GO_ONLINE,
+		MSG_WINBIND_VALIDATE_CACHE,
+		MSG_WINBIND_DUMP_DOMAIN_LIST,
+		MSG_WINBIND_IP_DROPPED,
+		MSG_WINBIND_DOMAIN_ONLINE,
+		MSG_WINBIND_DOMAIN_OFFLINE,
+		MSG_WINBIND_NEW_TRUSTED_DOMAIN,
 
 		/* event messages */
 		MSG_DUMP_EVENT_LIST		= 0x0500,
 
 		/* smbXsrv messages */
 		MSG_SMBXSRV_SESSION_CLOSE	= 0x0600,
-		MSG_SMBXSRV_CONNECTION_PASS	= 0x0601,
+		MSG_SMBXSRV_CONNECTION_PASS,
 
 		/* source4 and NTVFS smb server messages */
 		MSG_BRL_RETRY                   = 0x0700,
-		MSG_PVFS_RETRY_OPEN             = 0x0701,
-		MSG_IRPC                        = 0x0702,
-		MSG_NTVFS_OPLOCK_BREAK          = 0x0703,
-		MSG_DREPL_ALLOCATE_RID          = 0x0704,
+		MSG_PVFS_RETRY_OPEN,
+		MSG_IRPC,
+		MSG_NTVFS_OPLOCK_BREAK,
+		MSG_DREPL_ALLOCATE_RID,
 
 		/* dbwrap messages 4001-4999 (0x0FA0 - 0x1387) */
 		/* MSG_DBWRAP_TDB2_CHANGES		= 4001, */
-- 
2.7.4


From 6c2c80449a1b073c74ec95152575f692b02047f7 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sat, 7 Jan 2017 19:34:46 +0100
Subject: [PATCH 3/8] debug: parse, store and pass backend option

Will be used in the next commit by new "ringbuf" backend.

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 lib/util/debug.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 37582db..5ce3325 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -149,7 +149,7 @@ static void debug_file_log(int msg_level,
 
 #ifdef WITH_SYSLOG
 static void debug_syslog_reload(bool enabled, bool previously_enabled,
-				const char *prog_name)
+				const char *prog_name, char *option)
 {
 	if (enabled && !previously_enabled) {
 #ifdef LOG_DAEMON
@@ -207,7 +207,7 @@ static void debug_lttng_log(int msg_level,
 #ifdef HAVE_GPFS
 #include "gpfswrap.h"
 static void debug_gpfs_reload(bool enabled, bool previously_enabled,
-			      const char *prog_name)
+			      const char *prog_name, char *option)
 {
 	gpfswrap_init();
 
@@ -240,8 +240,10 @@ 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 (*reload)(bool enabled, bool prev_enabled,
+		       const char *prog_name, char *option);
 	void (*log)(int msg_level, const char *msg, const char *msg_no_nl);
+	char *option;
 } debug_backends[] = {
 	{
 		.name = "file",
@@ -297,6 +299,7 @@ static struct debug_backend *debug_find_backend(const char *name)
 static void debug_backend_parse_token(char *tok)
 {
 	char *backend_name_option, *backend_name,*backend_level, *saveptr;
+	char *backend_option;
 	struct debug_backend *b;
 
 	/*
@@ -317,12 +320,7 @@ static void debug_backend_parse_token(char *tok)
 		return;
 	}
 
-	/*
-	 * No backend is using the option yet.
-	 */
-#if 0
 	backend_option = strtok_r(NULL, "\0", &saveptr);
-#endif
 
 	/*
 	 * Find and update backend
@@ -337,6 +335,13 @@ static void debug_backend_parse_token(char *tok)
 	} else {
 		b->new_log_level = atoi(backend_level);
 	}
+
+	if (backend_option != NULL) {
+		b->option = strdup(backend_option);
+		if (b->option == NULL) {
+			return;
+		}
+	}
 }
 
 /*
@@ -380,7 +385,8 @@ static void debug_set_backends(const char *param)
 			bool enabled = b->new_log_level > -1;
 			bool previously_enabled = b->log_level > -1;
 
-			b->reload(enabled, previously_enabled, state.prog_name);
+			b->reload(enabled, previously_enabled, state.prog_name,
+				  b->option);
 		}
 		b->log_level = b->new_log_level;
 	}
-- 
2.7.4


From f3c4d850b42a560552bd15133e8db01160b2ae1f Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sat, 7 Jan 2017 14:36:24 +0100
Subject: [PATCH 4/8] debug: add "ringbuf" backend logging to a ringbuffer

This is useful for debugging bugs that involve timing effects and are
not reproducible when logging at higher debug levels with the file
backend.

The log can be dumped to a file with gdb:

(gdb) dump binary memory samba.log debug_ringbuf debug_ringbuf+SIZE

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 docs-xml/smbdotconf/logging/logging.xml |  5 +++
 lib/util/debug.c                        | 73 +++++++++++++++++++++++++++++++++
 lib/util/debug.h                        |  3 ++
 3 files changed, 81 insertions(+)

diff --git a/docs-xml/smbdotconf/logging/logging.xml b/docs-xml/smbdotconf/logging/logging.xml
index 8524884..b152d0c 100644
--- a/docs-xml/smbdotconf/logging/logging.xml
+++ b/docs-xml/smbdotconf/logging/logging.xml
@@ -31,8 +31,13 @@
     <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>
+    <listitem><para><parameter moreinfo="none">ringbuf</parameter></para></listitem>
   </itemizedlist>
 
+  <para>The <parameter moreinfo="none">ringbuf</parameter> backend supports an
+  optional size argument to change the buffer size used, the default is 1 MB:
+  <parameter moreinfo="none">ringbuf:size=NBYTES</parameter></para>
+
 </description>
 <value type="default"></value>
 <value type="example">syslog at 1 file</value>
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 5ce3325..ee8b193 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -236,6 +236,74 @@ static void debug_gpfs_log(int msg_level,
 }
 #endif /* HAVE_GPFS */
 
+#define DEBUG_RINGBUF_SIZE (1024 * 1024)
+#define DEBUG_RINGBUF_SIZE_OPT "size="
+
+static char *debug_ringbuf;
+static size_t debug_ringbuf_size;
+static size_t debug_ringbuf_ofs;
+
+char *debug_get_ringbuf(void)
+{
+	return debug_ringbuf;
+}
+
+size_t debug_get_ringbuf_size(void)
+{
+	return debug_ringbuf_size;
+}
+
+static void debug_ringbuf_reload(bool enabled, bool previously_enabled,
+				 const char *prog_name, char *option)
+{
+	bool cmp;
+	size_t optlen = strlen(DEBUG_RINGBUF_SIZE_OPT);
+
+	debug_ringbuf_size = DEBUG_RINGBUF_SIZE;
+	debug_ringbuf_ofs = 0;
+
+	if (debug_ringbuf != NULL) {
+		free(debug_ringbuf);
+		debug_ringbuf = NULL;
+	}
+
+	if (!enabled) {
+		return;
+	}
+
+	if (option != NULL) {
+		cmp = strncmp(option, DEBUG_RINGBUF_SIZE_OPT, optlen);
+		if (cmp == 0) {
+			debug_ringbuf_size = (size_t)strtoull(
+				option + optlen, NULL, 10);
+		}
+	}
+
+	/* Ensure the buffer is always a 0 terminated string */
+	debug_ringbuf = calloc(debug_ringbuf_size + 1, sizeof(char));
+	if (debug_ringbuf == NULL) {
+		return;
+	}
+}
+
+static void debug_ringbuf_log(int msg_level,
+			      const char *msg,
+			      const char *msg_no_nl)
+{
+	size_t msglen = strlen(msg);
+
+	if (debug_ringbuf == NULL) {
+		return;
+	}
+
+	if (msglen + debug_ringbuf_ofs >= debug_ringbuf_size) {
+		debug_ringbuf_ofs = 0;
+	}
+
+	memcpy(debug_ringbuf + debug_ringbuf_ofs, msg, msglen);
+	debug_ringbuf_ofs += msglen;
+}
+
 static struct debug_backend {
 	const char *name;
 	int log_level;
@@ -278,6 +346,11 @@ static struct debug_backend {
 		.log = debug_gpfs_log,
 	},
 #endif
+	{
+		.name = "ringbuf",
+		.log = debug_ringbuf_log,
+		.reload = debug_ringbuf_reload,
+	},
 };
 
 static struct debug_backend *debug_find_backend(const char *name)
diff --git a/lib/util/debug.h b/lib/util/debug.h
index b50bf50..43c6aa0 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -287,4 +287,7 @@ typedef void (*debug_callback_fn)(void *private_ptr, int level, const char *msg)
  */
 void debug_set_callback(void *private_ptr, debug_callback_fn fn);
 
+char *debug_get_ringbuf(void);
+size_t debug_get_ringbuf_size(void);
+
 #endif /* _SAMBA_DEBUG_H */
-- 
2.7.4


From 697d5bc9d6c26581621c169522975acfad46e334 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Mon, 9 Jan 2017 22:35:17 +0100
Subject: [PATCH 5/8] messaging.idl: add ringbuf message types

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 librpc/idl/messaging.idl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/librpc/idl/messaging.idl b/librpc/idl/messaging.idl
index 48f68c2..c47d41d 100644
--- a/librpc/idl/messaging.idl
+++ b/librpc/idl/messaging.idl
@@ -26,6 +26,8 @@ interface messaging
 		MSG_PROFILELEVEL,
 		MSG_REQ_POOL_USAGE,
 		MSG_POOL_USAGE,
+		MSG_REQ_RINGBUF_LOG,
+		MSG_RINGBUF_LOG,
 
 		/* If dmalloc is included, set a steady-state mark */
 		MSG_REQ_DMALLOC_MARK,
-- 
2.7.4


From e53cdfbf82e284eff2447d08d566f3410db26f35 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sun, 8 Jan 2017 14:08:27 +0100
Subject: [PATCH 6/8] s3/debug: listen for MSG_REQ_RINGBUF_LOG

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 lib/util/debug_s3.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/util/debug_s3.c b/lib/util/debug_s3.c
index 98e7b00..1367d16 100644
--- a/lib/util/debug_s3.c
+++ b/lib/util/debug_s3.c
@@ -21,6 +21,7 @@
 #include "includes.h"
 #include "librpc/gen_ndr/messaging.h"
 #include "messages.h"
+#include "lib/util/memory.h"
 
 /* This is the Samba3-specific implementation of reopen_logs(), which
  * calls out to the s3 loadparm code, and means that we don't depend
@@ -98,9 +99,29 @@ static void debuglevel_message(struct messaging_context *msg_ctx,
 
 	TALLOC_FREE(message);
 }
+
+static void debug_ringbuf_log(struct messaging_context *msg_ctx,
+			      void *private_data,
+			      uint32_t msg_type,
+			      struct server_id src,
+			      DATA_BLOB *data)
+{
+	char *log = debug_get_ringbuf();
+	size_t logsize = debug_get_ringbuf_size() + 1;
+
+	if (log == NULL) {
+		log = discard_const_p(char, "*disabled*\n");
+		logsize = strlen("*disabled*\n") + 1;
+	}
+
+	messaging_send_buf(msg_ctx, src, MSG_RINGBUF_LOG, (uint8_t *)log, logsize);
+}
+
 void debug_register_msgs(struct messaging_context *msg_ctx)
 {
 	messaging_register(msg_ctx, NULL, MSG_DEBUG, debug_message);
 	messaging_register(msg_ctx, NULL, MSG_REQ_DEBUGLEVEL,
 			   debuglevel_message);
+	messaging_register(msg_ctx, NULL, MSG_REQ_RINGBUF_LOG,
+			   debug_ringbuf_log);
 }
-- 
2.7.4


From 677d39509caee43594310b4f72f35f4225a5fee3 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Mon, 9 Jan 2017 22:33:55 +0100
Subject: [PATCH 7/8] s4/messaging: register for MSG_REQ_RINGBUF_LOG

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 source4/lib/messaging/messaging.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index 6fca9b8..5b99890 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -114,6 +114,27 @@ static void pool_message(struct imessaging_context *msg, void *private_data,
 	talloc_free(report);
 }
 
+static void ringbuf_log_msg(struct imessaging_context *msg,
+			    void *private_data,
+			    uint32_t msg_type,
+			    struct server_id src,
+			    DATA_BLOB *data)
+{
+	char *log = debug_get_ringbuf();
+	size_t logsize = debug_get_ringbuf_size() + 1;
+	DATA_BLOB blob;
+
+	if (log == NULL) {
+		log = discard_const_p(char, "*disabled*\n");
+		logsize = strlen("*disabled*\n") + 1;
+	}
+
+	blob.data = (uint8_t *)log;
+	blob.length = logsize;
+
+	imessaging_send(msg, src, MSG_RINGBUF_LOG, &blob);
+}
+
 /*
   return uptime of messaging server via irpc
 */
@@ -408,6 +429,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
 	imessaging_register(msg, NULL, MSG_PING, ping_message);
 	imessaging_register(msg, NULL, MSG_REQ_POOL_USAGE, pool_message);
 	imessaging_register(msg, NULL, MSG_IRPC, irpc_handler);
+	imessaging_register(msg, NULL, MSG_REQ_RINGBUF_LOG, ringbuf_log_msg);
 	IRPC_REGISTER(msg, irpc, IRPC_UPTIME, irpc_uptime, msg);
 
 	DLIST_ADD(msg_ctxs, msg);
-- 
2.7.4


From c575ae7dd6d443a45fd0bbd8af803975ff569708 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sun, 8 Jan 2017 16:47:30 +0100
Subject: [PATCH 8/8] smbcontrol: add ringbuf-log

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 docs-xml/manpages/smbcontrol.1.xml |  7 +++++++
 source3/utils/smbcontrol.c         | 43 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/docs-xml/manpages/smbcontrol.1.xml b/docs-xml/manpages/smbcontrol.1.xml
index ebbb8dc..e9a3acf 100644
--- a/docs-xml/manpages/smbcontrol.1.xml
+++ b/docs-xml/manpages/smbcontrol.1.xml
@@ -257,6 +257,13 @@
 	</varlistentry>
 
 	<varlistentry>
+	<term>ringbuf-log</term>
+	<listitem><para>Fetch and print the ringbuf log. Requires
+	<parameter>logging = ringbuf</parameter>. Available for smbd, winbindd
+	and nmbd.</para></listitem>
+	</varlistentry>
+
+	<varlistentry>
 	<term>drvupgrade</term>
 	<listitem><para>Force clients of printers using specified driver 
 	to update their local version of the driver. Can only be 
diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c
index ad602b3..595fffa 100644
--- a/source3/utils/smbcontrol.c
+++ b/source3/utils/smbcontrol.c
@@ -886,6 +886,48 @@ static bool do_poolusage(struct tevent_context *ev_ctx,
 	return num_replies;
 }
 
+/* Fetch and print the ringbuf log */
+
+static void print_ringbuf_log_cb(struct messaging_context *msg,
+				 void *private_data,
+				 uint32_t msg_type,
+				 struct server_id pid,
+				 DATA_BLOB *data)
+{
+	printf("%s", (const char *)data->data);
+	num_replies++;
+}
+
+static bool do_ringbuflog(struct tevent_context *ev_ctx,
+			  struct messaging_context *msg_ctx,
+			  const struct server_id pid,
+			  const int argc, const char **argv)
+{
+	if (argc != 1) {
+		fprintf(stderr, "Usage: smbcontrol <dest> ringbuf-log\n");
+		return False;
+	}
+
+	messaging_register(msg_ctx, NULL, MSG_RINGBUF_LOG, print_ringbuf_log_cb);
+
+	/* Send a message and register our interest in a reply */
+
+	if (!send_message(msg_ctx, pid, MSG_REQ_RINGBUF_LOG, NULL, 0))
+		return False;
+
+	wait_replies(ev_ctx, msg_ctx, procid_to_pid(&pid) == 0);
+
+	/* No replies were received within the timeout period */
+
+	if (num_replies == 0) {
+		printf("No replies received\n");
+	}
+
+	messaging_deregister(msg_ctx, MSG_RINGBUF_LOG, NULL);
+
+	return num_replies;
+}
+
 /* Perform a dmalloc mark */
 
 static bool do_dmalloc_mark(struct tevent_context *ev_ctx,
@@ -1385,6 +1427,7 @@ static const struct {
 	{ "lockretry", do_lockretry, "Force a blocking lock retry" },
 	{ "brl-revalidate", do_brl_revalidate, "Revalidate all brl entries" },
 	{ "pool-usage", do_poolusage, "Display talloc memory usage" },
+	{ "ringbuf-log", do_ringbuflog, "Display ringbuf log" },
 	{ "dmalloc-mark", do_dmalloc_mark, "" },
 	{ "dmalloc-log-changed", do_dmalloc_changed, "" },
 	{ "shutdown", do_shutdown, "Shut down daemon" },
-- 
2.7.4



More information about the samba-technical mailing list