/* Update checker's state */ void update_svr_checker_state(int alive, checker_id_t cid, virtual_server *vs, real_server *rs) { element e; list l = rs->failed_checkers; checker_id_t *id; /* Handle alive state. Depopulate failed_checkers and call * perform_svr_state() independently, letting the latter sort * things out itself. */ if (alive) { /* Remove the succeeded check from failed_checkers list. */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { id = ELEMENT_DATA(e); if (*id == cid) { free_list_element(l, e); /* If we don't break, the next iteration will trigger * a SIGSEGV. */ break; } } if (LIST_SIZE(l) == 0) perform_svr_state(alive, vs, rs); } /* Handle not alive state */ else { id = (checker_id_t *) MALLOC(sizeof(checker_id_t)); *id = cid; list_add(l, id); if (LIST_SIZE(l) == 1) perform_svr_state(alive, vs, rs); } }
/* Update checker's state */ void update_svr_checker_state(int alive, checker_id_t cid, virtual_server_t *vs, real_server_t *rs) { element e; list l = rs->failed_checkers; checker_id_t *id; /* Handle alive state. Depopulate failed_checkers and call * perform_svr_state() independently, letting the latter sort * things out itself. */ if (alive) { for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { id = ELEMENT_DATA(e); if (*id == cid) break; } /* call the UP handler unless any more failed checks found */ if (LIST_SIZE(l) == 0 || (LIST_SIZE(l) == 1 && e)) { if (perform_svr_state(alive, vs, rs)) return; } /* Remove the succeeded check from failed_checkers */ if (e) free_list_element(l, e); } /* Handle not alive state */ else { if (LIST_SIZE(l) == 0) { if (perform_svr_state(alive, vs, rs)) return; } else { /* do not add failed check into list twice */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { id = ELEMENT_DATA(e); if (*id == cid) return; } } id = (checker_id_t *) MALLOC(sizeof(checker_id_t)); *id = cid; list_add(l, id); } }