summaryrefslogtreecommitdiff
path: root/ctdb/common
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-08-08 13:36:00 +1000
committerAmitay Isaacs <amitay@samba.org>2014-10-28 05:42:04 +0100
commita22c8ca05618a63d6923fcf7dc567d1cd6119009 (patch)
tree9b9ec1166c1eb34170e67eba218b316e5a94c57c /ctdb/common
parentd9d572a23cf527780caae9d7ff143376e9057f6a (diff)
downloadsamba-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/common')
-rw-r--r--ctdb/common/cmdline.c12
-rw-r--r--ctdb/common/ctdb_logging.c45
2 files changed, 39 insertions, 18 deletions
diff --git a/ctdb/common/cmdline.c b/ctdb/common/cmdline.c
index ab2b45e9143..4ed3fae64d7 100644
--- a/ctdb/common/cmdline.c
+++ b/ctdb/common/cmdline.c
@@ -96,10 +96,8 @@ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev)
}
/* Set the debug level */
- if (isalpha(ctdb_cmdline.debuglevel[0]) || ctdb_cmdline.debuglevel[0] == '-') {
- DEBUGLEVEL = get_debug_by_desc(ctdb_cmdline.debuglevel);
- } else {
- DEBUGLEVEL = strtol(ctdb_cmdline.debuglevel, NULL, 0);
+ if (!parse_debug(ctdb_cmdline.debuglevel, &DEBUGLEVEL)) {
+ DEBUGLEVEL = DEBUG_ERR;
}
/* set up the tree to store server ids */
@@ -147,10 +145,8 @@ struct ctdb_context *ctdb_cmdline_client(struct tevent_context *ev,
}
/* Set the debug level */
- if (isalpha(ctdb_cmdline.debuglevel[0]) || ctdb_cmdline.debuglevel[0] == '-') {
- DEBUGLEVEL = get_debug_by_desc(ctdb_cmdline.debuglevel);
- } else {
- DEBUGLEVEL = strtol(ctdb_cmdline.debuglevel, NULL, 0);
+ if (!parse_debug(ctdb_cmdline.debuglevel, &DEBUGLEVEL)) {
+ DEBUGLEVEL = DEBUG_ERR;
}
ret = ctdb_socket_connect(ctdb);
diff --git a/ctdb/common/ctdb_logging.c b/ctdb/common/ctdb_logging.c
index c79397d03f0..e76966c822c 100644
--- a/ctdb/common/ctdb_logging.c
+++ b/ctdb/common/ctdb_logging.c
@@ -17,15 +17,18 @@
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "includes.h"
-#include "tdb.h"
-#include "system/time.h"
-#include "../include/ctdb_private.h"
-#include "../include/ctdb_client.h"
+#include <ctype.h>
+#include "replace.h"
+#include "ctdb_logging.h"
const char *debug_extra = "";
-struct debug_levels debug_levels[] = {
+struct debug_levels {
+ int32_t level;
+ const char *description;
+};
+
+static struct debug_levels debug_levels[] = {
{DEBUG_ERR, "ERR"},
{DEBUG_WARNING, "WARNING"},
{DEBUG_NOTICE, "NOTICE"},
@@ -43,18 +46,40 @@ const char *get_debug_by_level(int32_t level)
return debug_levels[i].description;
}
}
- return "Unknown";
+ return NULL;
}
-int32_t get_debug_by_desc(const char *desc)
+static bool get_debug_by_desc(const char *desc, int32_t *level)
{
int i;
for (i=0; debug_levels[i].description != NULL; i++) {
if (!strcasecmp(debug_levels[i].description, desc)) {
- return debug_levels[i].level;
+ *level = debug_levels[i].level;
+ return true;
}
}
- return DEBUG_ERR;
+ return false;
+}
+
+bool parse_debug(const char *str, int32_t *level)
+{
+ if (isalpha(str[0])) {
+ return get_debug_by_desc(str, level);
+ } else {
+ *level = strtol(str, NULL, 0);
+ return get_debug_by_level(*level) != NULL;
+ }
+}
+
+void print_debug_levels(FILE *stream)
+{
+ int i;
+
+ for (i=0; debug_levels[i].description != NULL; i++) {
+ fprintf(stream,
+ "%s (%d)\n",
+ debug_levels[i].description, debug_levels[i].level);
+ }
}