[PATCH] Two patches for the debug system

Ralph Böhme rb at sernet.de
Wed Jul 1 05:19:09 MDT 2015


Hi,

attached are two small patches for the debug subsystem:

* the first gets rid of DBGC_MAX_FIXED by using designated array
  initializers and ARRAY_SIZE in order to traverse the debug classes

* the second adds a debug class for tevent

Please review&push if ok. Thanks!

Cheerio!
-Ralph

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de,mailto:kontakt@sernet.de
-------------- next part --------------
From 23e25289c2be54eb998e9f6c3b4cf7a3965e3f65 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Wed, 13 May 2015 16:03:38 +0200
Subject: [PATCH 1/2] debug: get rid of DBGC_MAX_FIXED

Simplify class table by using designated array initializers and
ARRAY_SIZE macro.

Signed-off-by: Ralph Boehme <slow at samba.org>
Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
---
 lib/util/debug.c | 61 ++++++++++++++++++++++++++++----------------------------
 lib/util/debug.h |  3 ---
 2 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index dce3292..6b8fc0c 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -416,11 +416,37 @@ static void debug_backends_log(const char *msg, int msg_level)
 */
 bool    override_logfile;
 
+static const char *default_classname_table[] = {
+	[DBGC_ALL] =		"all",
+	[DBGC_TDB] =		"tdb",
+	[DBGC_PRINTDRIVERS] =	"printdrivers",
+	[DBGC_LANMAN] =		"lanman",
+	[DBGC_SMB] =		"smb",
+	[DBGC_RPC_PARSE] =	"rpc_parse",
+	[DBGC_RPC_SRV] =	"rpc_srv",
+	[DBGC_RPC_CLI] =	"rpc_cli",
+	[DBGC_PASSDB] =		"passdb",
+	[DBGC_SAM] =		"sam",
+	[DBGC_AUTH] =		"auth",
+	[DBGC_WINBIND] =	"winbind",
+	[DBGC_VFS] =		"vfs",
+	[DBGC_IDMAP] =		"idmap",
+	[DBGC_QUOTA] =		"quota",
+	[DBGC_ACLS] =		"acls",
+	[DBGC_LOCKING] =	"locking",
+	[DBGC_MSDFS] =		"msdfs",
+	[DBGC_DMAPI] =		"dmapi",
+	[DBGC_REGISTRY] =	"registry",
+	[DBGC_SCAVENGER] =	"scavenger",
+	[DBGC_DNS] =		"dns",
+	[DBGC_LDB] =		"ldb",
+};
+
 /*
  * This is to allow reading of DEBUGLEVEL_CLASS before the debug
  * system has been initialized.
  */
-static const int debug_class_list_initial[DBGC_MAX_FIXED + 1];
+static const int debug_class_list_initial[ARRAY_SIZE(default_classname_table)];
 
 static int debug_num_classes = 0;
 int     *DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
@@ -460,32 +486,6 @@ static bool    log_overflow   = false;
  * white space. There must be one name for each DBGC_<class name>, and they
  * must be in the table in the order of DBGC_<class name>..
  */
-static const char *default_classname_table[] = {
-	"all",               /* DBGC_ALL; index refs traditional DEBUGLEVEL */
-	"tdb",               /* DBGC_TDB	  */
-	"printdrivers",      /* DBGC_PRINTDRIVERS */
-	"lanman",            /* DBGC_LANMAN       */
-	"smb",               /* DBGC_SMB          */
-	"rpc_parse",         /* DBGC_RPC_PARSE    */
-	"rpc_srv",           /* DBGC_RPC_SRV      */
-	"rpc_cli",           /* DBGC_RPC_CLI      */
-	"passdb",            /* DBGC_PASSDB       */
-	"sam",               /* DBGC_SAM          */
-	"auth",              /* DBGC_AUTH         */
-	"winbind",           /* DBGC_WINBIND      */
-	"vfs",		     /* DBGC_VFS	  */
-	"idmap",	     /* DBGC_IDMAP	  */
-	"quota",	     /* DBGC_QUOTA	  */
-	"acls",		     /* DBGC_ACLS	  */
-	"locking",	     /* DBGC_LOCKING	  */
-	"msdfs",	     /* DBGC_MSDFS	  */
-	"dmapi",	     /* DBGC_DMAPI	  */
-	"registry",          /* DBGC_REGISTRY     */
-	"scavenger",         /* DBGC_SCAVENGER    */
-	"dns",               /* DBGC_DNS          */
-	"ldb",               /* DBGC_LDB          */
-	NULL
-};
 
 static char **classname_table = NULL;
 
@@ -744,8 +744,7 @@ Init debugging (one time stuff)
 
 static void debug_init(void)
 {
-	int i;
-	const char **p;
+	size_t i;
 
 	if (state.initialized)
 		return;
@@ -754,8 +753,8 @@ static void debug_init(void)
 
 	debug_setup_talloc_log();
 
-	for(p = default_classname_table; *p; p++) {
-		debug_add_class(*p);
+	for (i = 0; i < ARRAY_SIZE(default_classname_table); i++) {
+		debug_add_class(default_classname_table[i]);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
diff --git a/lib/util/debug.h b/lib/util/debug.h
index 8d8f43d..9baf762 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -89,9 +89,6 @@ bool dbghdr( int level, const char *location, const char *func);
 #define DBGC_DNS		21
 #define DBGC_LDB		22
 
-/* Always ensure this is updated when new fixed classes area added, to ensure the array in debug.c is the right size */
-#define DBGC_MAX_FIXED		22
-
 /* So you can define DBGC_CLASS before including debug.h */
 #ifndef DBGC_CLASS
 #define DBGC_CLASS            0     /* override as shown above */
-- 
2.1.0


From a2c9cb3ed4a6bc95e98ef1376156e695ef1178d8 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sun, 28 Jun 2015 20:44:37 +0200
Subject: [PATCH 2/2] tevent: add and use debug class for tevent

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 lib/util/debug.c        | 1 +
 lib/util/debug.h        | 1 +
 lib/util/tevent_debug.c | 3 +++
 3 files changed, 5 insertions(+)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 6b8fc0c..726c682 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -440,6 +440,7 @@ static const char *default_classname_table[] = {
 	[DBGC_SCAVENGER] =	"scavenger",
 	[DBGC_DNS] =		"dns",
 	[DBGC_LDB] =		"ldb",
+	[DBGC_TEVENT] =		"tevent",
 };
 
 /*
diff --git a/lib/util/debug.h b/lib/util/debug.h
index 9baf762..c312bbf 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -88,6 +88,7 @@ bool dbghdr( int level, const char *location, const char *func);
 #define DBGC_SCAVENGER		20
 #define DBGC_DNS		21
 #define DBGC_LDB		22
+#define DBGC_TEVENT		23
 
 /* So you can define DBGC_CLASS before including debug.h */
 #ifndef DBGC_CLASS
diff --git a/lib/util/tevent_debug.c b/lib/util/tevent_debug.c
index bfbaed6..48f6529 100644
--- a/lib/util/tevent_debug.c
+++ b/lib/util/tevent_debug.c
@@ -19,6 +19,9 @@
 #include "includes.h"
 #include <tevent.h>
 
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_TEVENT
+
 static void samba_tevent_debug(void *context,
 			       enum tevent_debug_level level,
 			       const char *fmt,
-- 
2.1.0



More information about the samba-technical mailing list