ctdb-daemon: Consolidate initialization of logging and debug level
authorAmitay Isaacs <amitay@gmail.com>
Wed, 30 Nov 2016 05:46:19 +0000 (16:46 +1100)
committerMartin Schwenke <martins@samba.org>
Mon, 5 Dec 2016 07:09:22 +0000 (08:09 +0100)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/include/ctdb_private.h
ctdb/server/ctdb_logging.c
ctdb/server/ctdbd.c

index cecc36fd156e89fd3bef202ccdd2a376d37023dd..0a68dae427bb8cf552e67a02f03195898bd2241f 100644 (file)
@@ -676,7 +676,8 @@ struct lock_request *ctdb_lock_db(TALLOC_CTX *mem_ctx,
 
 extern const char *debug_extra;
 
-bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging);
+bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging,
+                      const char *debug_level);
 
 struct ctdb_log_state *ctdb_vfork_with_logging(TALLOC_CTX *mem_ctx,
                                               struct ctdb_context *ctdb,
index 198718029d2f14a6dc323e6e1d67311ec6e186f2..fdf0673308b2ad2c8b35c49297627a5ca54f6ded 100644 (file)
@@ -52,7 +52,8 @@ struct ctdb_log_state {
 static struct ctdb_log_state *log_state;
 
 /* Initialise logging */
-bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging)
+bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging,
+                      const char *debug_level)
 {
        int ret;
 
@@ -61,7 +62,7 @@ bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging)
                return false;
        }
 
-       ret = logging_init(mem_ctx, logging, NULL, "ctdbd");
+       ret = logging_init(mem_ctx, logging, debug_level, "ctdbd");
        if (ret != 0) {
                return false;
        }
index b054b7fb9294b81ec9014281e74718e19b6833e1..58f402708fa142c5c64a73f2e6749d46eae9912e 100644 (file)
@@ -66,6 +66,7 @@ static struct {
        int         torture;
 } options = {
        .socket = CTDB_RUNDIR "/ctdbd.socket",
+       .debuglevel = "NOTICE",
        .nlist = NULL,
        .public_address_list = NULL,
        .transport = "tcp",
@@ -154,7 +155,6 @@ int main(int argc, const char *argv[])
        const char **extra_argv;
        poptContext pc;
        struct tevent_context *ev;
-       int log_level;
 
        pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
 
@@ -198,12 +198,12 @@ int main(int argc, const char *argv[])
                ctdb_set_flags(ctdb, CTDB_FLAG_TORTURE);
        }
 
-       /* Set the debug level */
-       if (debug_level_parse(options.debuglevel, &log_level)) {
-               DEBUGLEVEL = log_level;
-       } else {
-               DEBUGLEVEL = DEBUG_NOTICE;
+       /* Initialize logging and set the debug level */
+       if (!ctdb_logging_init(ctdb, options.logging, options.debuglevel)) {
+               exit(1);
        }
+       setenv("CTDB_LOGGING", options.logging, 1);
+       setenv("CTDB_DEBUGLEVEL", debug_level_to_string(DEBUGLEVEL), 1);
 
        setenv("CTDB_SOCKET", options.socket, 1);
        ret = ctdb_set_socketname(ctdb, options.socket);
@@ -217,10 +217,6 @@ int main(int argc, const char *argv[])
 
        script_log_level = options.script_log_level;
 
-       if (!ctdb_logging_init(ctdb, options.logging)) {
-               exit(1);
-       }
-
        DEBUG(DEBUG_NOTICE,("CTDB starting on node\n"));
 
        gettimeofday(&ctdb->ctdbd_start_time, NULL);