static int set_expected(int expected_votes) { int err; if ((err=votequorum_setexpected(v_handle, expected_votes)) != CS_OK) { fprintf(stderr, "Unable to set expected votes: %s\n", cs_strerror(err)); } return err==CS_OK?0:err; }
static void setexpected (int sock, char *arg) { int ret; char response[100]; q_lib_init (); ret = votequorum_setexpected (vq_handle, atoi(arg)); if (ret != CS_OK) { snprintf (response, 100, "%s", FAIL_STR); qb_log (LOG_ERR, "set expected votes FAILED: %d", ret); goto send_response; } snprintf (response, 100, "%s", OK_STR); send_response: send (sock, response, strlen (response) + 1, 0); }
static int set_expected(int expected_votes) { votequorum_handle_t v_handle; votequorum_callbacks_t v_callbacks; int err; v_callbacks.votequorum_notify_fn = NULL; v_callbacks.votequorum_expectedvotes_notify_fn = NULL; if ( (err=votequorum_initialize(&v_handle, &v_callbacks)) != CS_OK) { fprintf(stderr, "votequorum_initialize FAILED: %d, this is probably a configuration error\n", err); return err; } if ( (err=votequorum_setexpected(v_handle, expected_votes)) != CS_OK) fprintf(stderr, "set expected votes FAILED: %d\n", err); votequorum_finalize(v_handle); return err==CS_OK?0:err; }
int main(int argc, char *argv[]) { struct votequorum_info info; votequorum_callbacks_t callbacks; int err; if (argc > 1 && strcmp(argv[1], "-h")==0) { fprintf(stderr, "usage: %s [new-expected] [new-votes]\n", argv[0]); return 0; } callbacks.votequorum_notify_fn = votequorum_notification_fn; callbacks.votequorum_expectedvotes_notify_fn = votequorum_expectedvotes_notification_fn; if ( (err=votequorum_initialize(&g_handle, &callbacks)) != CS_OK) fprintf(stderr, "votequorum_initialize FAILED: %d\n", err); if ( (err = votequorum_trackstart(g_handle, g_handle, CS_TRACK_CHANGES)) != CS_OK) fprintf(stderr, "votequorum_trackstart FAILED: %d\n", err); if ( (err=votequorum_getinfo(g_handle, 0, &info)) != CS_OK) fprintf(stderr, "votequorum_getinfo FAILED: %d\n", err); else { printf("node votes %d\n", info.node_votes); printf("expected votes %d\n", info.node_expected_votes); printf("highest expected %d\n", info.highest_expected); printf("total votes %d\n", info.total_votes); printf("quorum %d\n", info.quorum); printf("flags "); if (info.flags & VOTEQUORUM_INFO_FLAG_TWONODE) printf("2Node "); if (info.flags & VOTEQUORUM_INFO_FLAG_QUORATE) printf("Quorate "); if (info.flags & VOTEQUORUM_INFO_WAIT_FOR_ALL) printf("WaitForAll "); if (info.flags & VOTEQUORUM_INFO_LAST_MAN_STANDING) printf("LastManStanding "); if (info.flags & VOTEQUORUM_INFO_AUTO_TIE_BREAKER) printf("AutoTieBreaker "); if (info.flags & VOTEQUORUM_INFO_LEAVE_REMOVE) printf("LeaveRemove "); printf("\n"); } if (argc >= 2 && atoi(argv[1])) { if ( (err=votequorum_setexpected(g_handle, atoi(argv[1]))) != CS_OK) fprintf(stderr, "set expected votes FAILED: %d\n", err); } if (argc >= 3 && atoi(argv[2])) { if ( (err=votequorum_setvotes(g_handle, 0, atoi(argv[2]))) != CS_OK) fprintf(stderr, "set votes FAILED: %d\n", err); } if (argc >= 2) { if ( (err=votequorum_getinfo(g_handle, 0, &info)) != CS_OK) fprintf(stderr, "votequorum_getinfo2 FAILED: %d\n", err); else { printf("-------------------\n"); printf("node votes %d\n", info.node_votes); printf("expected votes %d\n", info.node_expected_votes); printf("highest expected %d\n", info.highest_expected); printf("total votes %d\n", info.total_votes); printf("votequorum %d\n", info.quorum); printf("flags "); if (info.flags & VOTEQUORUM_INFO_FLAG_TWONODE) printf("2Node "); if (info.flags & VOTEQUORUM_INFO_FLAG_QUORATE) printf("Quorate "); if (info.flags & VOTEQUORUM_INFO_WAIT_FOR_ALL) printf("WaitForAll "); if (info.flags & VOTEQUORUM_INFO_LAST_MAN_STANDING) printf("LastManStanding "); if (info.flags & VOTEQUORUM_INFO_AUTO_TIE_BREAKER) printf("AutoTieBreaker "); if (info.flags & VOTEQUORUM_INFO_LEAVE_REMOVE) printf("LeaveRemove "); printf("\n"); } } printf("Waiting for votequorum events, press ^C to finish\n"); printf("-------------------\n"); while (1) { if (votequorum_dispatch(g_handle, CS_DISPATCH_ALL) != CS_OK) { fprintf(stderr, "votequorum_dispatch error\n"); return -1; } } return 0; }