diff options
author | Martin Schwenke <martin@meltin.net> | 2014-08-08 13:36:00 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2014-10-28 05:42:04 +0100 |
commit | a22c8ca05618a63d6923fcf7dc567d1cd6119009 (patch) | |
tree | 9b9ec1166c1eb34170e67eba218b316e5a94c57c /ctdb/tools | |
parent | d9d572a23cf527780caae9d7ff143376e9057f6a (diff) | |
download | samba-a22c8ca05618a63d6923fcf7dc567d1cd6119009.tar.gz |
ctdb-logging: Rework debug level parsing
Put declarations into ctdb_logging.h, factor out some common code,
clean up #includes.
Remove the check so see if the 1st character of the debug level is
'-'. This is wrong, since it is trying to check for a negative
numeric debug level (which is no longer supported) and would need to
be handled in the else anyway.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tools')
-rw-r--r-- | ctdb/tools/ctdb.c | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index c34e33d1e56..458ea9e4abe 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -4845,11 +4845,17 @@ static int control_getdebug(struct ctdb_context *ctdb, int argc, const char **ar DEBUG(DEBUG_ERR, ("Unable to get debuglevel response from node %u\n", options.pnn)); return ret; } else { + const char *desc = get_debug_by_level(level); + if (desc == NULL) { + /* This should never happen */ + desc = "Unknown"; + } if (options.machinereadable){ printf(":Name:Level:\n"); - printf(":%s:%d:\n",get_debug_by_level(level),level); + printf(":%s:%d:\n", desc, level); } else { - printf("Node %u is at debug level %s (%d)\n", options.pnn, get_debug_by_level(level), level); + printf("Node %u is at debug level %s (%d)\n", + options.pnn, desc, level); } } return 0; @@ -4999,34 +5005,18 @@ static int control_setrecmasterrole(struct ctdb_context *ctdb, int argc, const c */ static int control_setdebug(struct ctdb_context *ctdb, int argc, const char **argv) { - int i, ret; + int ret; int32_t level; if (argc == 0) { printf("You must specify the debug level. Valid levels are:\n"); - for (i=0; debug_levels[i].description != NULL; i++) { - printf("%s (%d)\n", debug_levels[i].description, debug_levels[i].level); - } - + print_debug_levels(stdout); return 0; } - if (isalpha(argv[0][0]) || argv[0][0] == '-') { - level = get_debug_by_desc(argv[0]); - } else { - level = strtol(argv[0], NULL, 0); - } - - for (i=0; debug_levels[i].description != NULL; i++) { - if (level == debug_levels[i].level) { - break; - } - } - if (debug_levels[i].description == NULL) { + if (!parse_debug(argv[0], &level)) { printf("Invalid debug level, must be one of\n"); - for (i=0; debug_levels[i].description != NULL; i++) { - printf("%s (%d)\n", debug_levels[i].description, debug_levels[i].level); - } + print_debug_levels(stdout); return -1; } |