debug: Use debuglevel_(get|set) function
authorAndreas Schneider <asn@samba.org>
Wed, 7 Nov 2018 13:14:05 +0000 (14:14 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 8 Nov 2018 10:03:11 +0000 (11:03 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Nov  8 11:03:11 CET 2018 on sn-devel-144

16 files changed:
ctdb/common/conf_tool.c
ctdb/common/logging.c
ctdb/common/path_tool.c
ctdb/event/event_tool.c
ctdb/server/ctdb_control.c
ctdb/server/ctdb_recoverd.c
ctdb/tests/src/ctdb_takeover_tests.c
ctdb/tests/src/dummy_client.c
ctdb/tests/src/test_options.c
ctdb/tools/ctdb.c
ctdb/tools/ctdb_killtcp.c
lib/util/debug.c
lib/util/debug.h
python/pyglue.c
source3/nmbd/asyncdns.c
source4/param/pyparam.c

index e6020c504e62e0a835fc76902338f9a3f7ba7843..8e0753eb787f62b4a084da3d996d1e9171b87d62 100644 (file)
@@ -276,6 +276,7 @@ int main(int argc, const char **argv)
        TALLOC_CTX *mem_ctx;
        struct conf_tool_context *ctx;
        int ret, result;
+       int level;
        bool ok;
 
        mem_ctx = talloc_new(NULL);
@@ -297,10 +298,11 @@ int main(int argc, const char **argv)
        }
 
        setup_logging("ctdb-config", DEBUG_STDERR);
-       ok = debug_level_parse(conf_data.debug, &DEBUGLEVEL);
+       ok = debug_level_parse(conf_data.debug, &level);
        if (!ok) {
-               DEBUGLEVEL = DEBUG_ERR;
+               level = DEBUG_ERR;
        }
+       debuglevel_set(level);
 
        ret = conf_tool_run(ctx, &result);
        if (ret != 0) {
index dc8c4f7505896007bfee30833fb6c53d6ca65604..aaa93216ef552c97b30c86b96de1152ffc9b62d6 100644 (file)
@@ -674,6 +674,7 @@ int logging_init(TALLOC_CTX *mem_ctx, const char *logging,
 {
        struct log_backend *backend = NULL;
        char *option = NULL;
+       int level;
        int ret;
 
        setup_logging(app_name, DEBUG_STDERR);
@@ -681,9 +682,10 @@ int logging_init(TALLOC_CTX *mem_ctx, const char *logging,
        if (debug_level == NULL) {
                debug_level = getenv("CTDB_DEBUGLEVEL");
        }
-       if (! debug_level_parse(debug_level, &DEBUGLEVEL)) {
+       if (! debug_level_parse(debug_level, &level)) {
                return EINVAL;
        }
+       debuglevel_set(level);
 
        if (logging == NULL) {
                logging = getenv("CTDB_LOGGING");
index 1c60b023c427700f342b1b517ba6ce6e96537a2a..a19afa9b0c34711589bb1576e9de15edef9e6cfd 100644 (file)
@@ -365,7 +365,7 @@ int main(int argc, const char **argv)
        }
 
        setup_logging("ctdb-path", DEBUG_STDERR);
-       DEBUGLEVEL = DEBUG_ERR;
+       debuglevel_set(DEBUG_ERR);
 
        ret = path_tool_run(ctx, &result);
        if (ret != 0) {
index f18deb8d5b1b1d7ba83ccf3cf9770148110ad0f4..8350f202ceae43f163d7cdf7942cf8506c2d54dc 100644 (file)
@@ -717,6 +717,7 @@ int main(int argc, const char **argv)
        TALLOC_CTX *mem_ctx;
        struct event_tool_context *ctx;
        int ret, result = 0;
+       int level;
        bool ok;
 
        mem_ctx = talloc_new(NULL);
@@ -738,10 +739,11 @@ int main(int argc, const char **argv)
        }
 
        setup_logging("ctdb-event", DEBUG_STDERR);
-       ok = debug_level_parse(event_data.debug, &DEBUGLEVEL);
+       ok = debug_level_parse(event_data.debug, &level);
        if (!ok) {
-               DEBUGLEVEL = DEBUG_ERR;
+               level = DEBUG_ERR;
        }
+       debuglevel_set(level);
 
        ret = event_tool_run(ctx, &result);
        if (ret != 0) {
index c260b92452970e39a8b1598891817f6a788bd67d..6c91e211660302435feafc4a0d8619ef4a571575 100644 (file)
@@ -100,6 +100,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        uint32_t opcode = c->opcode;
        uint64_t srvid = c->srvid;
        uint32_t client_id = c->client_id;
+       static int level = DEBUG_ERR;
 
        switch (opcode) {
        case CTDB_CONTROL_PROCESS_EXISTS: {
@@ -108,14 +109,20 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        }
 
        case CTDB_CONTROL_SET_DEBUG: {
+               union {
+                       uint8_t *ptr;
+                       int32_t *level;
+               } debug;
                CHECK_CONTROL_DATA_SIZE(sizeof(int32_t));
-               DEBUGLEVEL = *(int32_t *)indata.dptr;
+               debug.ptr = indata.dptr;
+               debuglevel_set(*debug.level);
                return 0;
        }
 
        case CTDB_CONTROL_GET_DEBUG: {
                CHECK_CONTROL_DATA_SIZE(0);
-               outdata->dptr = (uint8_t *)&(DEBUGLEVEL);
+               level = debuglevel_get();
+               outdata->dptr = (uint8_t *)&(level);
                outdata->dsize = sizeof(DEBUGLEVEL);
                return 0;
        }
index 673c99c3d341b10b808fb84b45fd007367f01a59..f000538bae2af4c2037b06b4910e2694410503ee 100644 (file)
@@ -2637,7 +2637,7 @@ static void main_loop(struct ctdb_context *ctdb, struct ctdb_recoverd *rec,
                DEBUG(DEBUG_ERR, (__location__ " Failed to read debuglevel from parent\n"));
                return;
        }
-       DEBUGLEVEL = debug_level;
+       debuglevel_set(debug_level);
 
        /* get relevant tunables */
        ret = ctdb_ctrl_get_all_tunables(ctdb, CONTROL_TIMEOUT(), CTDB_CURRENT_NODE, &ctdb->tunable);
index e9958ce205a0e8c024525c65d753bb17bd5ef09f..cc6b4416dd96625a1feac9932b645a8b102a6044 100644 (file)
@@ -257,7 +257,7 @@ int main(int argc, const char *argv[])
        if (! debug_level_parse(debuglevelstr, &loglevel)) {
                 loglevel = DEBUG_DEBUG;
         }
-       DEBUGLEVEL = loglevel;
+       debuglevel_set(loglevel);
 
        if (argc < 2) {
                usage();
index 22ba40f6e3bf1780344f9eba55502ff741621a0d..13e069180a3b40d27d2120a654b73fe043c09cdd 100644 (file)
@@ -104,7 +104,7 @@ int main(int argc, const char *argv[])
        }
 
        setup_logging("dummy_client", DEBUG_STDERR);
-       DEBUGLEVEL = log_level;
+       debuglevel_set(log_level);
 
        if (options.sockpath == NULL) {
                options.sockpath = path_socket(mem_ctx, "ctdbd");
index cfce51aeeb62869350956ec57a23a9bfa175c12b..ba9c49617719686fdebd68889b91e9a239720290 100644 (file)
@@ -98,7 +98,7 @@ static bool verify_options_basic(struct test_options *opts)
                return false;
        }
 
-       DEBUGLEVEL = log_level;
+       debuglevel_set(log_level);
 
        return true;
 }
index 8fa1ce63203fed32e41d235fc79c36cef57bab04..f96167f93666e1fa437f4efcc88949e3df47e88f 100644 (file)
@@ -6188,6 +6188,7 @@ int main(int argc, const char *argv[])
        int extra_argc;
        const struct ctdb_cmd *cmd;
        int loglevel;
+       bool ok;
        int ret;
 
        setlinebuf(stdout);
@@ -6246,11 +6247,11 @@ int main(int argc, const char *argv[])
 
        /* Enable logging */
        setup_logging("ctdb", DEBUG_STDERR);
-       if (debug_level_parse(options.debuglevelstr, &loglevel)) {
-               DEBUGLEVEL = loglevel;
-       } else {
-               DEBUGLEVEL = DEBUG_ERR;
+       ok = debug_level_parse(options.debuglevelstr, &loglevel);
+       if (!ok) {
+               loglevel = DEBUG_ERR;
        }
+       debuglevel_set(loglevel);
 
        signal(SIGALRM, alarm_handler);
        alarm(options.maxruntime);
index 8537a57967006fc6024167d9bb30c81a9a29ba05..fc443bd08e28cfbad6b64af07aa420076afab9e2 100644 (file)
@@ -330,16 +330,17 @@ int main(int argc, char **argv)
        struct tevent_req *req;
        int debug_level;
        bool status;
+       bool ok;
        int ret;
 
        /* Set the debug level */
        t = getenv("CTDB_DEBUGLEVEL");
        if (t != NULL) {
-               if (debug_level_parse(t, &debug_level)) {
-                       DEBUGLEVEL = debug_level;
-               } else {
-                       DEBUGLEVEL = DEBUG_ERR;
+               ok = debug_level_parse(t, &debug_level);
+               if (!ok) {
+                       debug_level = DEBUG_ERR;
                }
+               debuglevel_set(debug_level);
        }
 
        if (argc != 2 && argc != 4) {
index 847ec1f0a0c298eda6c14e32c358d9bd724540cc..b5f120bb3a464eff5949046bdec795e5b6a0fa71 100644 (file)
@@ -560,7 +560,17 @@ static const char *default_classname_table[] = {
 static int debug_class_list_initial[ARRAY_SIZE(default_classname_table)];
 
 static size_t debug_num_classes = 0;
-int     *DEBUGLEVEL_CLASS = debug_class_list_initial;
+static int    *DEBUGLEVEL_CLASS = debug_class_list_initial;
+
+int debuglevel_get_class(size_t idx)
+{
+       return DEBUGLEVEL_CLASS[idx];
+}
+
+void debuglevel_set_class(size_t idx, int level)
+{
+       DEBUGLEVEL_CLASS[idx] = level;
+}
 
 
 /* -------------------------------------------------------------------------- **
index 2895d15788752dc50ff8381f38cc1d385880b499..e6f54a7657f074c00a89998c368f328fe305e40c 100644 (file)
@@ -47,12 +47,6 @@ bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
 bool dbghdrclass( int level, int cls, const char *location, const char *func);
 bool dbghdr( int level, const char *location, const char *func);
 
-/*
- * Redefine DEBUGLEVEL because so we don't have to change every source file
- * that *unnecessarily* references it.
- */
-#define DEBUGLEVEL DEBUGLEVEL_CLASS[DBGC_ALL]
-
 /*
  * Define all new debug classes here. A class is represented by an entry in
  * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
@@ -109,7 +103,10 @@ bool dbghdr( int level, const char *location, const char *func);
 #define DBGC_CLASS            0     /* override as shown above */
 #endif
 
-extern int  *DEBUGLEVEL_CLASS;
+#define DEBUGLEVEL debuglevel_get()
+
+#define debuglevel_get() debuglevel_get_class(DBGC_ALL)
+#define debuglevel_set(lvl) debuglevel_set_class(DBGC_ALL, (lvl))
 
 /* Debugging macros
  *
@@ -176,13 +173,16 @@ extern int  *DEBUGLEVEL_CLASS;
 #endif
 #endif
 
+int debuglevel_get_class(size_t idx);
+void debuglevel_set_class(size_t idx, int level);
+
 #define CHECK_DEBUGLVL( level ) \
   ( ((level) <= MAX_DEBUG_LEVEL) && \
-    unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)))
+    unlikely(debuglevel_get_class(DBGC_CLASS) >= (level)))
 
 #define CHECK_DEBUGLVLC( dbgc_class, level ) \
   ( ((level) <= MAX_DEBUG_LEVEL) && \
-    unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)))
+    unlikely(debuglevel_get_class(dbgc_class) >= (level)))
 
 #define DEBUGLVL( level ) \
   ( CHECK_DEBUGLVL(level) \
@@ -194,24 +194,24 @@ extern int  *DEBUGLEVEL_CLASS;
 
 #define DEBUG( level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-         unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))           \
+       unlikely(debuglevel_get_class(DBGC_CLASS) >= (level))             \
        && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
        && (dbgtext body) )
 
 #define DEBUGC( dbgc_class, level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-         unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))           \
+       unlikely(debuglevel_get_class(dbgc_class) >= (level))             \
        && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
        && (dbgtext body) )
 
 #define DEBUGADD( level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-         unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))   \
+         unlikely(debuglevel_get_class(DBGC_CLASS) >= (level)) \
        && (dbgtext body) )
 
 #define DEBUGADDC( dbgc_class, level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-          unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))) \
+          unlikely((debuglevel_get_class(dbgc_class) >= (level))) \
        && (dbgtext body) )
 
 /* Print a separator to the debug log. */
@@ -221,7 +221,7 @@ extern int  *DEBUGLEVEL_CLASS;
 /* Prefix messages with the function name */
 #define DBG_PREFIX(level, body ) \
        (void)( ((level) <= MAX_DEBUG_LEVEL) &&                 \
-               unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))     \
+               unlikely(debuglevel_get_class(DBGC_CLASS) >= (level))   \
                && (dbghdrclass(level, DBGC_CLASS, __location__, __func__ )) \
                && (dbgtext("%s: ", __func__))                          \
                && (dbgtext body) )
@@ -229,7 +229,7 @@ extern int  *DEBUGLEVEL_CLASS;
 /* Prefix messages with the function name - class specific */
 #define DBGC_PREFIX(dbgc_class, level, body ) \
        (void)( ((level) <= MAX_DEBUG_LEVEL) &&                 \
-               unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))     \
+               unlikely(debuglevel_get_class(dbgc_class) >= (level))   \
                && (dbghdrclass(level, dbgc_class, __location__, __func__ )) \
                && (dbgtext("%s: ", __func__))                          \
                && (dbgtext body) )
index 04efa14d0513eaf1ed4be8de4e5ebd713c179c23..22ac53f3c66dc7f62388be20b90d1727ebd73b39 100644 (file)
@@ -23,6 +23,7 @@
 #include "version.h"
 #include "param/pyparam.h"
 #include "lib/socket/netif.h"
+#include "lib/util/debug.h"
 
 void init_glue(void);
 static PyObject *PyExc_NTSTATUSError;
@@ -161,13 +162,13 @@ static PyObject *py_set_debug_level(PyObject *self, PyObject *args)
        unsigned level;
        if (!PyArg_ParseTuple(args, "I", &level))
                return NULL;
-       (DEBUGLEVEL) = level;
+       debuglevel_set(level);
        Py_RETURN_NONE;
 }
 
 static PyObject *py_get_debug_level(PyObject *self)
 {
-       return PyInt_FromLong(DEBUGLEVEL);
+       return PyInt_FromLong(debuglevel_get());
 }
 
 static PyObject *py_fault_setup(PyObject *self)
index b4532fa4840a2ee3e75d04fd8c0843203c1e3a6b..e52380b03f0d3a3dcf38aaf365c86ba1392ed3ee 100644 (file)
@@ -86,7 +86,7 @@ static void asyncdns_process(void)
        struct query_record r;
        unstring qname;
 
-       DEBUGLEVEL = -1;
+       debuglevel_set(-1);
 
        while (1) {
                NTSTATUS status;
index 7f69d7b3c8be5bd96bbaf960b8e8eddc8def9ed6..e71bb469eeefec63cc98882716fe347371c92c6b 100644 (file)
@@ -347,7 +347,7 @@ static PyObject *py_lp_dump_a_parameter(PyObject *self, PyObject *args)
 
 static PyObject *py_lp_log_level(PyObject *self, PyObject *unused)
 {
-       int ret = DEBUGLEVEL_CLASS[DBGC_CLASS];
+       int ret = debuglevel_get();
        return PyInt_FromLong(ret);
 }