mirror of
https://github.com/samba-team/samba.git
synced 2025-03-20 22:50:26 +03:00
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)
This commit is contained in:
parent
c3ee62439f
commit
5f69ad3c0a
@ -5329,62 +5329,6 @@ 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;
|
||||
|
||||
if (ctdb_commands[i].without_daemon == true) {
|
||||
close(2);
|
||||
}
|
||||
|
||||
/* initialise ctdb */
|
||||
ctdb = ctdb_cmdline_client(ev, TIMELIMIT());
|
||||
|
||||
if (ctdb_commands[i].without_daemon == false) {
|
||||
const char *socket_name;
|
||||
|
||||
if (ctdb == NULL) {
|
||||
DEBUG(DEBUG_ERR, ("Failed to init ctdb\n"));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* 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_commands[i].auto_all &&
|
||||
options.pnn == CTDB_BROADCAST_ALL) {
|
||||
uint32_t *nodes;
|
||||
uint32_t num_nodes;
|
||||
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);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -5394,5 +5338,61 @@ int main(int argc, const char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ctdb_commands[i].without_daemon == true) {
|
||||
close(2);
|
||||
}
|
||||
|
||||
/* initialise ctdb */
|
||||
ctdb = ctdb_cmdline_client(ev, TIMELIMIT());
|
||||
|
||||
if (ctdb_commands[i].without_daemon == false) {
|
||||
const char *socket_name;
|
||||
|
||||
if (ctdb == NULL) {
|
||||
DEBUG(DEBUG_ERR, ("Failed to init ctdb\n"));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* 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_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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user