diff options
author | Martin Schwenke <martin@meltin.net> | 2014-03-03 12:45:23 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2014-03-23 04:20:14 +0100 |
commit | 9bede494743f0ce13493fe718ed8f0c3c5f2959c (patch) | |
tree | 9044d8dda651c31e8966ea0871cc0c14c95d00df /ctdb | |
parent | ba69742ccd822562ca2135d2466e09bf1216644b (diff) | |
download | samba-9bede494743f0ce13493fe718ed8f0c3c5f2959c.tar.gz samba-9bede494743f0ce13493fe718ed8f0c3c5f2959c.tar.xz samba-9bede494743f0ce13493fe718ed8f0c3c5f2959c.zip |
ctdb-tools-ctdb: Read NAT gateway nodes from a separate function
Now it gets easier to refactor.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/tools/ctdb.c | 91 |
1 files changed, 53 insertions, 38 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 4869850f53..433526dfc8 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -1123,6 +1123,55 @@ struct natgw_node { const char *addr; }; +static struct natgw_node *read_natgw_nodes_file(struct ctdb_context *ctdb, + TALLOC_CTX *mem_ctx) +{ + int i; + const char *natgw_list; + int nlines; + char **lines; + struct natgw_node *natgw_node; + struct natgw_node *natgw_nodes = NULL; + + natgw_list = getenv("CTDB_NATGW_NODES"); + if (natgw_list == NULL) { + natgw_list = talloc_asprintf(mem_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) { + ctdb_set_error(ctdb, "Failed to load natgw node list '%s'\n", natgw_list); + return NULL;; + } + for (i=0;i<nlines;i++) { + char *node; + + node = lines[i]; + /* strip leading spaces */ + while((*node == ' ') || (*node == '\t')) { + node++; + } + if (*node == '#') { + continue; + } + if (strcmp(node, "") == 0) { + continue; + } + natgw_node = talloc(ctdb, struct natgw_node); + natgw_node->addr = talloc_strdup(natgw_node, node); + CTDB_NO_MEMORY_NULL(ctdb, natgw_node->addr); + natgw_node->next = natgw_nodes; + natgw_nodes = natgw_node; + } + + return natgw_nodes; +} + + /* talloc off the existing nodemap... */ static struct ctdb_node_map *talloc_nodemap(struct ctdb_node_map *nodemap) { @@ -1230,11 +1279,7 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a { TALLOC_CTX *tmp_ctx = talloc_new(ctdb); int i, ret; - const char *natgw_list; - int nlines; - char **lines; struct natgw_node *natgw_nodes = NULL; - struct natgw_node *natgw_node; struct ctdb_node_map *orig_nodemap=NULL; struct ctdb_node_map *cnodemap, *nodemap; uint32_t mypnn, pnn; @@ -1255,40 +1300,10 @@ 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 = 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) { - ctdb_set_error(ctdb, "Failed to load natgw node list '%s'\n", natgw_list); - talloc_free(tmp_ctx); - return -1; - } - for (i=0;i<nlines;i++) { - char *node; - - node = lines[i]; - /* strip leading spaces */ - while((*node == ' ') || (*node == '\t')) { - node++; - } - if (*node == '#') { - continue; - } - if (strcmp(node, "") == 0) { - continue; - } - natgw_node = talloc(ctdb, struct natgw_node); - natgw_node->addr = talloc_strdup(natgw_node, node); - CTDB_NO_MEMORY(ctdb, natgw_node->addr); - natgw_node->next = natgw_nodes; - natgw_nodes = natgw_node; + natgw_nodes = read_natgw_nodes_file(ctdb, tmp_ctx); + if (natgw_nodes == NULL) { + ret = -1; + goto done; } ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, |