[SCM] CTDB repository - branch master updated -
ctdb-1.0.85-22-g421c056
Ronnie Sahlberg
sahlberg at samba.org
Tue Jun 30 23:03:43 GMT 2009
The branch, master has been updated
via 421c0566094b91221fab2ea68f2c9bd35d5dfbcb (commit)
via daec49cea1790bcc64599959faf2159dec2c5929 (commit)
via f4b0825d9da34578b9f90dc9bd7f99fcc2519ddf (commit)
from 5cdc04669db8c2ddbbff5af82307a16e8d807b83 (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 421c0566094b91221fab2ea68f2c9bd35d5dfbcb
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Wed Jul 1 09:21:07 2009 +1000
show the valid debuglevels that can be used in the error text when an invalid level was specified to ctdb setdebug
commit daec49cea1790bcc64599959faf2159dec2c5929
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Wed Jul 1 09:17:13 2009 +1000
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
commit f4b0825d9da34578b9f90dc9bd7f99fcc2519ddf
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Wed Jul 1 08:26:00 2009 +1000
when no debuglevel is specified, make 'ctdb setdebug' show the available options
-----------------------------------------------------------------------
Summary of changes:
common/cmdline.c | 12 ++++++++-
common/ctdb_util.c | 38 ++++++++++++++++++++++++++++
include/ctdb.h | 10 +++++++
tools/ctdb.c | 70 ++++++++++++++++-----------------------------------
4 files changed, 81 insertions(+), 49 deletions(-)
Changeset truncated at 500 lines:
diff --git a/common/cmdline.c b/common/cmdline.c
index 3acbf96..332a448 100644
--- a/common/cmdline.c
+++ b/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/common/ctdb_util.c b/common/ctdb_util.c
index d64f515..3af1346 100644
--- a/common/ctdb_util.c
+++ b/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/include/ctdb.h b/include/ctdb.h
index fc8985b..53669b2 100644
--- a/include/ctdb.h
+++ b/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/tools/ctdb.c b/tools/ctdb.c
index b6ca332..b670f92 100644
--- a/tools/ctdb.c
+++ b/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
*/
@@ -2299,19 +2255,37 @@ static int control_setreclock(struct ctdb_context *ctdb, int argc, const char **
*/
static int control_setdebug(struct ctdb_context *ctdb, int argc, const char **argv)
{
- int ret;
+ int i, ret;
int32_t level;
- if (argc < 1) {
- usage();
+ 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);
+ }
+
+ return 0;
}
- if (isalpha(argv[0][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) {
+ 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);
+ }
+ return -1;
+ }
+
ret = ctdb_ctrl_set_debuglevel(ctdb, options.pnn, level);
if (ret != 0) {
DEBUG(DEBUG_ERR, ("Unable to set debug level on node %u\n", options.pnn));
--
CTDB repository
More information about the samba-cvs
mailing list