TALLOC_CTX *mem_ctx;
struct conf_tool_context *ctx;
int ret, result;
+ int level;
bool ok;
mem_ctx = talloc_new(NULL);
}
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) {
{
struct log_backend *backend = NULL;
char *option = NULL;
+ int level;
int ret;
setup_logging(app_name, DEBUG_STDERR);
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");
}
setup_logging("ctdb-path", DEBUG_STDERR);
- DEBUGLEVEL = DEBUG_ERR;
+ debuglevel_set(DEBUG_ERR);
ret = path_tool_run(ctx, &result);
if (ret != 0) {
TALLOC_CTX *mem_ctx;
struct event_tool_context *ctx;
int ret, result = 0;
+ int level;
bool ok;
mem_ctx = talloc_new(NULL);
}
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) {
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: {
}
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;
}
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);
if (! debug_level_parse(debuglevelstr, &loglevel)) {
loglevel = DEBUG_DEBUG;
}
- DEBUGLEVEL = loglevel;
+ debuglevel_set(loglevel);
if (argc < 2) {
usage();
}
setup_logging("dummy_client", DEBUG_STDERR);
- DEBUGLEVEL = log_level;
+ debuglevel_set(log_level);
if (options.sockpath == NULL) {
options.sockpath = path_socket(mem_ctx, "ctdbd");
return false;
}
- DEBUGLEVEL = log_level;
+ debuglevel_set(log_level);
return true;
}
int extra_argc;
const struct ctdb_cmd *cmd;
int loglevel;
+ bool ok;
int ret;
setlinebuf(stdout);
/* 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);
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) {
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;
+}
/* -------------------------------------------------------------------------- **
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
#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
*
#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) \
#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. */
/* 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) )
/* 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) )
#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;
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)
struct query_record r;
unstring qname;
- DEBUGLEVEL = -1;
+ debuglevel_set(-1);
while (1) {
NTSTATUS status;
static PyObject *py_lp_log_level(PyObject *self, PyObject *unused)
{
- int ret = DEBUGLEVEL_CLASS[DBGC_CLASS];
+ int ret = debuglevel_get();
return PyInt_FromLong(ret);
}