Signed-Off-By: Pete Zaitcev <[email protected]>

---
 pkg/tabled.sysconf |    2 +-
 server/cldu.c      |    9 ++++++---
 server/server.c    |   22 ++++++++++++++++------
 server/tabled.h    |    3 +--
 4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/pkg/tabled.sysconf b/pkg/tabled.sysconf
index bbe35fc..d15c537 100644
--- a/pkg/tabled.sysconf
+++ b/pkg/tabled.sysconf
@@ -2,5 +2,5 @@
 #
 
 #example: 
-#OPTS="--debug"
+#OPTS="--debug 1"
 
diff --git a/server/cldu.c b/server/cldu.c
index 5b50a27..a10b8fe 100644
--- a/server/cldu.c
+++ b/server/cldu.c
@@ -82,7 +82,7 @@ static void add_chunk_node(struct cld_session *sp, const char 
*name);
 
 static struct timeval cldu_rescan_delay = { 50, 0 };
 
-struct hail_log cldu_hail_log = {
+static struct hail_log cldu_hail_log = {
        .func           = applog,
 };
 
@@ -226,7 +226,8 @@ static int cldu_set_cldc(struct cld_session *sp, int 
newactive)
                       hp->host, hp->port);
 
        sp->nsp = ncld_sess_open(hp->host, hp->port, &error,
-                                cldu_sess_event, sp, "tabled", "tabled");
+                                cldu_sess_event, sp, "tabled", "tabled",
+                                &cldu_hail_log);
        if (sp->nsp == NULL) {
                if (error < 1000) {
                        applog(LOG_ERR, "ncld_sess_open(%s,%u) error: %s",
@@ -584,12 +585,14 @@ void cld_init()
 /*
  * This initiates our sole session with a CLD instance.
  */
-int cld_begin(const char *thishost, const char *thisgroup)
+int cld_begin(const char *thishost, const char *thisgroup, int verbose)
 {
        static struct cld_session *sp = &ses;
        struct timespec tm;
        int retry_cnt;
 
+       cldu_hail_log.verbose = verbose;
+
        evtimer_set(&ses.tm_rescan, cldu_tm_rescan, &ses);
 
        if (cldu_setgroup(sp, thisgroup, thishost)) {
diff --git a/server/server.c b/server/server.c
index 18b3359..e1b0dbe 100644
--- a/server/server.c
+++ b/server/server.c
@@ -70,8 +70,8 @@ struct server_socket {
 static struct argp_option options[] = {
        { "config", 'C', "/etc/tabled.conf", 0,
          "Configuration file" },
-       { "debug", 'D', NULL, 0,
-         "Enable debug output" },
+       { "debug", 'D', "LEVEL", 0,
+         "Set debug output to LEVEL (0 = off, 2 = max)" },
        { "stderr", 'E', NULL, 0,
          "Switch the log to standard error" },
        { "pid", 'P', "FILE", 0,
@@ -90,6 +90,7 @@ static const struct argp argp = { options, parse_opt, NULL, 
doc };
 
 static bool server_running = true;
 static bool use_syslog = true;
+static int verbose = 0;
 int debugging = 0;
 
 struct server tabled_srv = {
@@ -176,12 +177,22 @@ static struct {
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state)
 {
+       int v;
+
        switch(key) {
        case 'C':
                tabled_srv.config = arg;
                break;
        case 'D':
-               debugging = 1;
+               v = atoi(arg);
+               if (v < 0 || v > 2) {
+                       fprintf(stderr, "invalid debug level: '%s'\n", arg);
+                       argp_usage(state);
+               }
+               if (v >= 1)
+                       debugging = 1;
+               if (v >= 2)
+                       verbose = 1;
                break;
        case 'E':
                use_syslog = false;
@@ -1886,8 +1897,7 @@ int main (int argc, char *argv[])
        if (use_syslog)
                openlog(PROGRAM_NAME, LOG_PID, LOG_LOCAL3);
        if (debugging)
-               applog(LOG_INFO, "Verbose debug output enabled");
-       cldu_hail_log.verbose = debugging;
+               applog(LOG_INFO, "Debug output enabled");
 
        /*
         * now we can parse the configuration, errors to applog
@@ -1946,7 +1956,7 @@ int main (int argc, char *argv[])
        if (rc)
                goto err_out_net;
 
-       if (cld_begin(tabled_srv.ourhost, tabled_srv.group) != 0) {
+       if (cld_begin(tabled_srv.ourhost, tabled_srv.group, verbose) != 0) {
                rc = 1;
                goto err_cld_session;
        }
diff --git a/server/tabled.h b/server/tabled.h
index 3ef4a49..eced4b6 100644
--- a/server/tabled.h
+++ b/server/tabled.h
@@ -295,10 +295,9 @@ extern void cli_in_end(struct client *cli);
 
 /* cldu.c */
 extern void cld_init(void);
-extern int cld_begin(const char *fqdn, const char *group);
+extern int cld_begin(const char *fqdn, const char *group, int verbose);
 extern void cldu_add_host(const char *host, unsigned int port);
 extern void cld_end(void);
-extern struct hail_log cldu_hail_log;
 
 /* util.c */
 extern size_t strlist_len(GList *l);
--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to