diff options
Diffstat (limited to 'cpgx/cpgx.c')
-rw-r--r-- | cpgx/cpgx.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/cpgx/cpgx.c b/cpgx/cpgx.c index 4b4bc0d..e574f87 100644 --- a/cpgx/cpgx.c +++ b/cpgx/cpgx.c @@ -132,11 +132,12 @@ static int client_size = 0; static struct client *client = NULL; static struct pollfd *pollfd = NULL; -static struct cpg_name dct_cpg_name; -static cpg_handle_t dct_cpg_handle; -static int dct_cpg_client; -static int dct_cpg_fd; +static struct cpg_name our_cpg_name; +static cpg_handle_t our_cpg_handle; +static int our_cpg_client; +static int our_cpg_fd; +static char our_name[32]; static char iptables_a[128]; static char iptables_d[128]; static char exec_addr[64]; @@ -744,7 +745,7 @@ void send_time(void) ev++; } - _send_message(dct_cpg_handle, buf, len, EV_MSGTIME); + _send_message(our_cpg_handle, buf, len, EV_MSGTIME); free(buf); } @@ -818,7 +819,7 @@ void send_sync(uint8_t nodeid) log_debug("send_sync to %u len %d count %d events %u-%u", nodeid, len, count, start_eventid, end_eventid); - _send_message(dct_cpg_handle, buf, len, EV_MSGSYNC); + _send_message(our_cpg_handle, buf, len, EV_MSGSYNC); free(buf); } @@ -1091,8 +1092,8 @@ static void confchg_cb(cpg_handle_t handle, const struct cpg_name *group_name, if (leave_wait && in_left(&c, our_nodeid)) { leave_wait = 0; leave_done = 1; - cpg_finalize(dct_cpg_handle); - client_dead(dct_cpg_client); + cpg_finalize(our_cpg_handle); + client_dead(our_cpg_client); add_history_confchg(&c); update_nodes_list(last_config, last_config_eventid); return; @@ -1322,7 +1323,7 @@ static void process_cpg(int ci) { cpg_error_t error; - error = cpg_dispatch(dct_cpg_handle, CPG_DISPATCH_ALL); + error = cpg_dispatch(our_cpg_handle, CPG_DISPATCH_ALL); if (error != CPG_OK) { log_error("cpg_dispatch error %d", error); return; @@ -1342,8 +1343,11 @@ int do_join(void) int i = 0, fd, ci; uint32_t nodeid; - sprintf(dct_cpg_name.value, "dct_cpg"); - dct_cpg_name.length = 8; + if (!our_name[0]) + strcpy(our_name, "cpgx"); + + sprintf(our_cpg_name.value, our_name); + our_cpg_name.length = strlen(our_name) + 1; error = cpg_initialize(&h, &cpg_callbacks); if (error != CPG_OK) { @@ -1368,13 +1372,13 @@ int do_join(void) ci = client_add(fd, process_cpg, cluster_dead); - dct_cpg_handle = h; - dct_cpg_client = ci; - dct_cpg_fd = fd; + our_cpg_handle = h; + our_cpg_client = ci; + our_cpg_fd = fd; log_debug("do join our_nodeid %u", our_nodeid); retry: - error = cpg_join(h, &dct_cpg_name); + error = cpg_join(h, &our_cpg_name); if (error == CPG_ERR_TRY_AGAIN) { sleep(1); if (!(++i % 10)) @@ -1403,7 +1407,7 @@ int do_leave(void) int i = 0; retry: - error = cpg_leave(dct_cpg_handle, &dct_cpg_name); + error = cpg_leave(our_cpg_handle, &our_cpg_name); if (error == CPG_ERR_TRY_AGAIN) { sleep(1); if (!(++i % 10)) @@ -1657,6 +1661,7 @@ void print_usage(void) printf(" (program exits without leaving cpg then rejoins)\n"); printf(" -d [0|1] die included in test [off|on], default 0\n"); printf(" (program kills and restarts %s)\n", exec_name); + printf(" -n <name> name of the cpg, default \"cpgx\"\n"); printf(" -s <num> sync up to num events, default %d\n", DEFAULT_SYNC_MAX); printf(" -t <sec> timeout after no dispatch for this many seconds, default %d\n", DEFAULT_TIMEOUT_SEC); @@ -1694,7 +1699,7 @@ int main(int argc, char **argv) int optchar; while (cont) { - optchar = getopt(argc, argv, "H:D:l:e:d:s:t:i:jw:a:p:I:chV"); + optchar = getopt(argc, argv, "H:D:l:e:d:n:s:t:i:jw:a:p:I:chV"); switch (optchar) { case 'H': @@ -1717,6 +1722,10 @@ int main(int argc, char **argv) opt_die = atoi(optarg); break; + case 'n': + strncpy(our_name, optarg, 31); + break; + case 's': sync_max = atoi(optarg); break; |