diff options
author | Martin Schwenke <martin@meltin.net> | 2011-11-29 14:20:26 +1100 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2011-12-06 13:59:32 +1100 |
commit | 5f69ad3c0a9cea324f4751ae92e3f7957a633a5a (patch) | |
tree | 16f19c678b91ae1d8bd37fb9513a063f3ead5c40 | |
parent | c3ee62439fe9db1560db29d13b7433bfadcda40d (diff) | |
download | samba-5f69ad3c0a9cea324f4751ae92e3f7957a633a5a.tar.gz samba-5f69ad3c0a9cea324f4751ae92e3f7957a633a5a.tar.xz samba-5f69ad3c0a9cea324f4751ae92e3f7957a633a5a.zip |
ctdb tool - simplify main() by taking most code out of a loop
Most of the action in main() happens inside a for loop and an if
statement. This causes 2 levels of extra indent for the code and
makes it harder to read.
Instead, the current body of the loop is put below the loop and its
corresponding failure check.
To see how small this change really is, view with "diff -w". ;-)
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 8527396b7290cfc8378779631e91d2ae09e2a106)
-rw-r--r-- | ctdb/tools/ctdb.c | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index a356c28c47..3d3cf9ae44 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -5329,69 +5329,69 @@ int main(int argc, const char *argv[]) for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) { if (strcmp(control, ctdb_commands[i].name) == 0) { - int j; + break; + } + } - if (ctdb_commands[i].without_daemon == true) { - close(2); - } + if (i == ARRAY_SIZE(ctdb_commands)) { + DEBUG(DEBUG_ERR, ("Unknown control '%s'\n", control)); + exit(1); + } - /* initialise ctdb */ - ctdb = ctdb_cmdline_client(ev, TIMELIMIT()); + if (ctdb_commands[i].without_daemon == true) { + close(2); + } - if (ctdb_commands[i].without_daemon == false) { - const char *socket_name; + /* initialise ctdb */ + ctdb = ctdb_cmdline_client(ev, TIMELIMIT()); - if (ctdb == NULL) { - DEBUG(DEBUG_ERR, ("Failed to init ctdb\n")); - exit(1); - } + if (ctdb_commands[i].without_daemon == false) { + const char *socket_name; - /* initialize a libctdb connection as well */ - socket_name = ctdb_get_socketname(ctdb); - ctdb_connection = ctdb_connect(socket_name, - ctdb_log_file, stderr); - if (ctdb_connection == NULL) { - fprintf(stderr, "Failed to connect to daemon from libctdb\n"); - exit(1); - } - - /* verify the node exists */ - verify_node(ctdb); - - if (options.pnn == CTDB_CURRENT_NODE) { - int pnn; - pnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn); - if (pnn == -1) { - return -1; - } - options.pnn = pnn; - } - } + if (ctdb == NULL) { + DEBUG(DEBUG_ERR, ("Failed to init ctdb\n")); + exit(1); + } - if (ctdb_commands[i].auto_all && - options.pnn == CTDB_BROADCAST_ALL) { - uint32_t *nodes; - uint32_t num_nodes; - ret = 0; + /* initialize a libctdb connection as well */ + socket_name = ctdb_get_socketname(ctdb); + ctdb_connection = ctdb_connect(socket_name, + ctdb_log_file, stderr); + if (ctdb_connection == NULL) { + fprintf(stderr, "Failed to connect to daemon from libctdb\n"); + exit(1); + } - nodes = ctdb_get_connected_nodes(ctdb, TIMELIMIT(), ctdb, &num_nodes); - CTDB_NO_MEMORY(ctdb, nodes); - - for (j=0;j<num_nodes;j++) { - options.pnn = nodes[j]; - ret |= ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1); - } - talloc_free(nodes); - } else { - ret = ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1); + /* verify the node exists */ + verify_node(ctdb); + + if (options.pnn == CTDB_CURRENT_NODE) { + int pnn; + pnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn); + if (pnn == -1) { + return -1; } - break; + options.pnn = pnn; } } - if (i == ARRAY_SIZE(ctdb_commands)) { - DEBUG(DEBUG_ERR, ("Unknown control '%s'\n", control)); - exit(1); + if (ctdb_commands[i].auto_all && + options.pnn == CTDB_BROADCAST_ALL) { + uint32_t *nodes; + uint32_t num_nodes; + int j; + ret = 0; + + nodes = ctdb_get_connected_nodes(ctdb, TIMELIMIT(), ctdb, &num_nodes); + CTDB_NO_MEMORY(ctdb, nodes); + + for (j=0;j<num_nodes;j++) { + options.pnn = nodes[j]; + ret |= ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1); + } + talloc_free(nodes); + } else { + ret = ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1); } return ret; |