tools/ctdb: CTDB_BASE is the default location of configuration files
authorMartin Schwenke <martin@meltin.net>
Mon, 21 Oct 2013 08:43:47 +0000 (19:43 +1100)
committerMartin Schwenke <martin@meltin.net>
Tue, 22 Oct 2013 04:37:54 +0000 (15:37 +1100)
Ensure that environment variable CTDB_BASE is set.

Update defaults for nodes and natgw_nodes to use CTDB_BASE.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>

tools/ctdb.c

index bad09c9c42ec6c4b7ae3648b11c648b52f3ff656..49fb278b10ab62385757cf3efd9836f43777e0aa 100644 (file)
@@ -810,7 +810,12 @@ static struct pnn_node *read_nodes_file(TALLOC_CTX *mem_ctx)
        /* read the nodes file */
        nodes_list = getenv("CTDB_NODES");
        if (nodes_list == NULL) {
-               nodes_list = "/etc/ctdb/nodes";
+               nodes_list = talloc_asprintf(mem_ctx, "%s/nodes",
+                                            getenv("CTDB_BASE"));
+               if (nodes_list == NULL) {
+                       DEBUG(DEBUG_ALERT,(__location__ " Out of memory\n"));
+                       exit(1);
+               }
        }
        lines = file_lines_load(nodes_list, &nlines, mem_ctx);
        if (lines == NULL) {
@@ -1162,7 +1167,12 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a
        /* read the natgw nodes file into a linked list */
        natgw_list = getenv("CTDB_NATGW_NODES");
        if (natgw_list == NULL) {
-               natgw_list = "/etc/ctdb/natgw_nodes";
+               natgw_list = talloc_asprintf(tmp_ctx, "%s/natgw_nodes",
+                                            getenv("CTDB_BASE"));
+               if (natgw_list == NULL) {
+                       DEBUG(DEBUG_ALERT,(__location__ " Out of memory\n"));
+                       exit(1);
+               }
        }
        lines = file_lines_load(natgw_list, &nlines, ctdb);
        if (lines == NULL) {
@@ -6201,6 +6211,9 @@ int main(int argc, const char *argv[])
 
        control = extra_argv[0];
 
+       /* Default value for CTDB_BASE - don't override */
+       setenv("CTDB_BASE", ETCDIR "/ctdb", 0);
+
        ev = event_context_init(NULL);
        if (!ev) {
                DEBUG(DEBUG_ERR, ("Failed to initialize event system\n"));