diff options
author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2009-07-01 09:17:13 +1000 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2009-07-01 09:17:13 +1000 |
commit | 93026f4cbf33eae2865c94c87ba47967c4d4a92f (patch) | |
tree | 7824e3917b79c5f24fafce777e9e7d9e94488a31 | |
parent | 9802a0c2f6c327b9533e2ed228b5a0ee4fb32aa8 (diff) | |
download | samba-93026f4cbf33eae2865c94c87ba47967c4d4a92f.tar.gz samba-93026f4cbf33eae2865c94c87ba47967c4d4a92f.tar.xz samba-93026f4cbf33eae2865c94c87ba47967c4d4a92f.zip |
update the handling of debug levels so that we always can use a literal instead of a numeric value.
validate the input values used and refuse setting the debug level to an unknown value
(This used to be ctdb commit daec49cea1790bcc64599959faf2159dec2c5929)
-rw-r--r-- | ctdb/common/cmdline.c | 12 | ||||
-rw-r--r-- | ctdb/common/ctdb_util.c | 38 | ||||
-rw-r--r-- | ctdb/include/ctdb.h | 10 | ||||
-rw-r--r-- | ctdb/tools/ctdb.c | 50 |
4 files changed, 62 insertions, 48 deletions
diff --git a/ctdb/common/cmdline.c b/ctdb/common/cmdline.c index 3acbf96e13..332a448a68 100644 --- a/ctdb/common/cmdline.c +++ b/ctdb/common/cmdline.c @@ -24,16 +24,19 @@ #include "../include/ctdb.h" #include "../include/ctdb_private.h" #include "../common/rb_tree.h" +#include <ctype.h> /* Handle common command line options for ctdb test progs */ static struct { const char *socketname; + const char *debuglevel; int torture; const char *events; } ctdb_cmdline = { .torture = 0, + .debuglevel = "ERR", }; enum {OPT_EVENTSYSTEM=1}; @@ -54,7 +57,7 @@ static void ctdb_cmdline_callback(poptContext con, struct poptOption popt_ctdb_cmdline[] = { { NULL, 0, POPT_ARG_CALLBACK, (void *)ctdb_cmdline_callback }, { "socket", 0, POPT_ARG_STRING, &ctdb_cmdline.socketname, 0, "local socket name", "filename" }, - { "debug", 'd', POPT_ARG_INT, &LogLevel, 0, "debug level"}, + { "debug", 'd', POPT_ARG_STRING, &ctdb_cmdline.debuglevel, 0, "debug level"}, { "torture", 0, POPT_ARG_NONE, &ctdb_cmdline.torture, 0, "enable nastiness in library", NULL }, { "events", 0, POPT_ARG_STRING, NULL, OPT_EVENTSYSTEM, "event system", NULL }, { NULL } @@ -91,6 +94,13 @@ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev) } } + /* Set the debug level */ + if (isalpha(ctdb_cmdline.debuglevel[0]) || ctdb_cmdline.debuglevel[0] == '-') { + LogLevel = get_debug_by_desc(ctdb_cmdline.debuglevel); + } else { + LogLevel = strtol(ctdb_cmdline.debuglevel, NULL, 0); + } + /* set up the tree to store server ids */ ctdb->server_ids = trbt_create(ctdb, 0); diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c index d64f51574e..3af1346528 100644 --- a/ctdb/common/ctdb_util.c +++ b/ctdb/common/ctdb_util.c @@ -624,3 +624,41 @@ void ctdb_unblock_signal(int signum) sigaddset(&set,signum); sigprocmask(SIG_UNBLOCK,&set,NULL); } + +struct debug_levels debug_levels[] = { + {DEBUG_EMERG, "EMERG"}, + {DEBUG_ALERT, "ALERT"}, + {DEBUG_CRIT, "CRIT"}, + {DEBUG_ERR, "ERR"}, + {DEBUG_WARNING, "WARNING"}, + {DEBUG_NOTICE, "NOTICE"}, + {DEBUG_INFO, "INFO"}, + {DEBUG_DEBUG, "DEBUG"}, + {0, NULL} +}; + +const char *get_debug_by_level(int32_t level) +{ + int i; + + for (i=0; debug_levels[i].description != NULL; i++) { + if (debug_levels[i].level == level) { + return debug_levels[i].description; + } + } + return "Unknown"; +} + +int32_t get_debug_by_desc(const char *desc) +{ + int i; + + for (i=0; debug_levels[i].description != NULL; i++) { + if (!strcmp(debug_levels[i].description, desc)) { + return debug_levels[i].level; + } + } + + return DEBUG_ERR; +} + diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index fc8985b17f..53669b255f 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -644,4 +644,14 @@ int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_monitoring_wire **script_status); +struct debug_levels { + int32_t level; + const char *description; +}; +extern struct debug_levels debug_levels[]; + +const char *get_debug_by_level(int32_t level); +int32_t get_debug_by_desc(const char *desc); + + #endif diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index fc34e99fd6..d9b4a6090b 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -2181,50 +2181,6 @@ static int control_listvars(struct ctdb_context *ctdb, int argc, const char **ar return 0; } -static struct { - int32_t level; - const char *description; -} debug_levels[] = { - {DEBUG_EMERG, "EMERG"}, - {DEBUG_ALERT, "ALERT"}, - {DEBUG_CRIT, "CRIT"}, - {DEBUG_ERR, "ERR"}, - {DEBUG_WARNING, "WARNING"}, - {DEBUG_NOTICE, "NOTICE"}, - {DEBUG_INFO, "INFO"}, - {DEBUG_DEBUG, "DEBUG"} -}; - -static const char *get_debug_by_level(int32_t level) -{ - int i; - - for (i=0;i<ARRAY_SIZE(debug_levels);i++) { - if (debug_levels[i].level == level) { - return debug_levels[i].description; - } - } - return "Unknown"; -} - -static int32_t get_debug_by_desc(const char *desc) -{ - int i; - - for (i=0;i<ARRAY_SIZE(debug_levels);i++) { - if (!strcmp(debug_levels[i].description, desc)) { - return debug_levels[i].level; - } - } - - fprintf(stderr, "Invalid debug level '%s'\nMust be one of\n", desc); - for (i=0;i<ARRAY_SIZE(debug_levels);i++) { - fprintf(stderr, " %s\n", debug_levels[i].description); - } - - exit(10); -} - /* display debug level on a node */ @@ -2304,7 +2260,7 @@ static int control_setdebug(struct ctdb_context *ctdb, int argc, const char **ar if (argc == 0) { printf("You must specify the debug level. Valid levels are:\n"); - for (i=0;i<ARRAY_SIZE(debug_levels);i++) { + for (i=0; debug_levels[i].description != NULL; i++) { printf("%s (%d)\n", debug_levels[i].description, debug_levels[i].level); } @@ -2317,12 +2273,12 @@ static int control_setdebug(struct ctdb_context *ctdb, int argc, const char **ar level = strtol(argv[0], NULL, 0); } - for (i=0;i<ARRAY_SIZE(debug_levels);i++) { + for (i=0; debug_levels[i].description != NULL; i++) { if (level == debug_levels[i].level) { break; } } - if (i == ARRAY_SIZE(debug_levels)) { + if (debug_levels[i].description == NULL) { printf("Invalid debug level\n"); return -1; } |