int main(int argc, char **argv) { int rc = cib_ok; int timeout = 0; char *client_epoch = getenv("QUERY_STRING"); if (client_epoch && client_epoch[0] == '\0') client_epoch = NULL; if (client_epoch) { char *amp = strchrnul(client_epoch, '&'); if (amp - client_epoch < MAX_EPOCH_LENGTH) { /* * Make a copy of the query string, but without any * possible ampersand and subsequent parameters. This * can be strcmp'd easily later, but allows adding * params to the query string to force the browser not * to cache these requests. */ client_epoch = strndupa(client_epoch, amp - client_epoch); } } origin = getenv("HTTP_ORIGIN"); /* Final arg appeared circa pcmk 1.1.8 */ crm_log_init(NULL, LOG_CRIT, FALSE, FALSE, argc, argv, TRUE); cib = cib_new(); rc = cib_connect(); if (rc != cib_ok && client_epoch == NULL) { /* Client had no epoch, wait to connect */ do { sleep(1); rc = cib_connect(); } while (rc == cib_connection && ++timeout < CONNECT_TIMEOUT); } if (rc == cib_ok) { get_new_epoch(); if (client_epoch != NULL && strcmp(client_epoch, new_epoch) == 0) { /* Wait a while to see if something changes */ mainloop = g_main_loop_new(NULL, FALSE); mainloop_add_signal(SIGTERM, mon_shutdown); mainloop_add_signal(SIGINT, mon_shutdown); g_timeout_add(CONNECT_TIMEOUT * 1000, mon_timer_popped, NULL); g_main_loop_run(mainloop); cleanup(); g_main_loop_unref(mainloop); mainloop = NULL; } } cleanup(); finish(); return 0; /* never reached */ }
static gboolean mon_timer_reconnect(gpointer data) { int rc = 0; if (timer_id_reconnect > 0) { g_source_remove(timer_id_reconnect); } rc = cib_connect(TRUE); if (rc != 0) { cl_log(LOG_WARNING, "CIB reconnect failed: %d", rc); timer_id_reconnect = g_timeout_add(reconnect_msec, mon_timer_reconnect, NULL); } else { cl_log(LOG_INFO, "CIB reconnect successful"); } return FALSE; }
int servant_pcmk(const char *diskname, int mode, const void* argp) { int exit_code = 0; crm_cluster_t crm_cluster; cl_log(LOG_INFO, "Monitoring Pacemaker health"); set_proc_title("sbd: watcher: Pacemaker"); setenv("PCMK_watchdog", "true", 1); if(debug == 0) { /* We don't want any noisy crm messages */ set_crm_log_level(LOG_CRIT); } #ifdef SUPPORT_PLUGIN cluster_stack = get_cluster_type(); if (cluster_stack != pcmk_cluster_classic_ais) { check_ais = 0; } else { check_ais = 1; cl_log(LOG_INFO, "Legacy plug-in detected, AIS quorum check enabled"); if(is_openais_cluster()) { crm_cluster.destroy = ais_membership_destroy; crm_cluster.cpg.cpg_deliver_fn = ais_membership_dispatch; /* crm_cluster.cpg.cpg_confchg_fn = pcmk_cpg_membership; TODO? */ crm_cluster.cpg.cpg_confchg_fn = NULL; } while (!crm_cluster_connect(&crm_cluster)) { cl_log(LOG_INFO, "Waiting to sign in with cluster ..."); sleep(reconnect_msec / 1000); } } #endif if (current_cib == NULL) { cib = cib_new(); do { exit_code = cib_connect(TRUE); if (exit_code != 0) { sleep(reconnect_msec / 1000); } } while (exit_code == -ENOTCONN); if (exit_code != 0) { clean_up(-exit_code); } } mainloop = g_main_new(FALSE); mainloop_add_signal(SIGTERM, mon_shutdown); mainloop_add_signal(SIGINT, mon_shutdown); timer_id_notify = g_timeout_add(timeout_loop * 1000, mon_timer_notify, NULL); #ifdef SUPPORT_PLUGIN if (check_ais) { timer_id_ais = g_timeout_add(timeout_loop * 1000, mon_timer_ais, NULL); } #endif g_main_run(mainloop); g_main_destroy(mainloop); clean_up(0); return 0; /* never reached */ }