ctdb-daemon: Use a local variable instead of repeating getenv()
authorMartin Schwenke <martin@meltin.net>
Thu, 26 Apr 2018 10:32:30 +0000 (20:32 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 1 May 2018 11:31:18 +0000 (13:31 +0200)
Makes the error handling easier and the code more compact.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdbd.c

index 38a5f9d39358e5bf0668fe92f7459123cc40ce11..4a3c5f65b305d66e1ca0e0f444f35e8c00ec507a 100644 (file)
@@ -141,6 +141,7 @@ int main(int argc, const char *argv[])
        const char **extra_argv;
        poptContext pc;
        struct tevent_context *ev;
+       const char *ctdb_base;
 
        /* Environment variable overrides default */
        ctdbd_pidfile = getenv("CTDB_PIDFILE");
@@ -280,10 +281,14 @@ int main(int argc, const char *argv[])
 
        /* Default value for CTDB_BASE - don't override */
        setenv("CTDB_BASE", CTDB_ETCDIR, 0);
+       ctdb_base = getenv("CTDB_BASE");
+       if (ctdb_base == NULL) {
+               D_ERR("CTDB_BASE not set\n");
+               exit(1);
+       }
 
        /* tell ctdb what nodes are available */
-       ctdb->nodes_file =
-               talloc_asprintf(ctdb, "%s/nodes", getenv("CTDB_BASE"));
+       ctdb->nodes_file = talloc_asprintf(ctdb, "%s/nodes", ctdb_base);
        if (ctdb->nodes_file == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
                exit(1);
@@ -301,7 +306,7 @@ int main(int argc, const char *argv[])
 
        ctdb->event_script_dir = talloc_asprintf(ctdb,
                                                 "%s/events.d",
-                                                getenv("CTDB_BASE"));
+                                                ctdb_base);
        if (ctdb->event_script_dir == NULL) {
                DBG_ERR("Out of memory\n");
                exit(1);