/*! * \internal * \brief Respond to client clear-failure request * * \param[in] xml Request XML */ void attrd_client_clear_failure(xmlNode *xml) { #if 0 /* @TODO Track the minimum supported protocol version across all nodes, * then enable this more-efficient code. */ if (compare_version("2", minimum_protocol_version) <= 0) { /* Propagate to all peers (including ourselves). * This ends up at attrd_peer_message(). */ send_attrd_message(NULL, xml); return; } #endif const char *rsc = crm_element_value(xml, F_ATTRD_RESOURCE); const char *op = crm_element_value(xml, F_ATTRD_OPERATION); const char *interval_spec = crm_element_value(xml, F_ATTRD_INTERVAL); /* Map this to an update */ crm_xml_add(xml, F_ATTRD_TASK, ATTRD_OP_UPDATE); /* Add regular expression matching desired attributes */ if (rsc) { char *pattern; if (op == NULL) { pattern = crm_strdup_printf(ATTRD_RE_CLEAR_ONE, rsc); } else { guint interval_ms = crm_parse_interval_spec(interval_spec); pattern = crm_strdup_printf(ATTRD_RE_CLEAR_OP, rsc, op, interval_ms); } crm_xml_add(xml, F_ATTRD_REGEX, pattern); free(pattern); } else { crm_xml_add(xml, F_ATTRD_REGEX, ATTRD_RE_CLEAR_ALL); } /* Make sure attribute and value are not set, so we delete via regex */ if (crm_element_value(xml, F_ATTRD_ATTRIBUTE)) { crm_xml_replace(xml, F_ATTRD_ATTRIBUTE, NULL); } if (crm_element_value(xml, F_ATTRD_VALUE)) { crm_xml_replace(xml, F_ATTRD_VALUE, NULL); } attrd_client_update(xml); }
static int version_check(FILE *f, const char *from, const char *to) { FILE *g = NULL; char *a = NULL, *b = NULL; int r; assert(f); assert(from); assert(to); r = get_file_version(f, &a); if (r < 0) goto finish; if (r == 0) { r = -EINVAL; fprintf(stderr, "Source file %s does not carry version information!\n", from); goto finish; } g = fopen(to, "re"); if (!g) { if (errno == ENOENT) { r = 0; goto finish; } r = -errno; fprintf(stderr, "Failed to open %s for reading: %m\n", to); goto finish; } r = get_file_version(g, &b); if (r < 0) goto finish; if (r == 0 || compare_product(a, b) != 0) { r = -EEXIST; fprintf(stderr, "Skipping %s, since it's owned by another boot loader.\n", to); goto finish; } if (compare_version(a, b) < 0) { r = -EEXIST; fprintf(stderr, "Skipping %s, since it's a newer boot loader version already.\n", to); goto finish; } r = 0; finish: free(a); free(b); if (g) fclose(g); return r; }
static void nap_version_check(void) { /* Check we are running a compatible version of the NAP firmware. */ char nap_version_string[64] = {0}; nap_conf_rd_version_string(nap_version_string); if (compare_version(nap_version_string, REQUIRED_NAP_VERSION_STR) < 0) { while (1) { log_error("NAP firmware version >= %s required, please update!" "(instructions can be found at http://docs.swift-nav.com/)", REQUIRED_NAP_VERSION_STR); chThdSleepSeconds(2); } } }
/*! * \internal * \brief Compile regular expressions to match failure-related node attributes * * \param[in] rsc Resource being checked for failures * \param[in] data_set Data set (for CRM feature set version) * \param[out] failcount_re Storage for regular expression for fail count * \param[out] lastfailure_re Storage for regular expression for last failure * * \note The caller is responsible for freeing the expressions with regfree(). */ static void generate_fail_regexes(resource_t *rsc, pe_working_set_t *data_set, regex_t *failcount_re, regex_t *lastfailure_re) { char *rsc_name = rsc_fail_name(rsc); const char *version = crm_element_value(data_set->input, XML_ATTR_CRM_VERSION); gboolean is_legacy = (compare_version(version, "3.0.13") < 0); generate_fail_regex(CRM_FAIL_COUNT_PREFIX, rsc_name, is_legacy, is_set(rsc->flags, pe_rsc_unique), failcount_re); generate_fail_regex(CRM_LAST_FAILURE_PREFIX, rsc_name, is_legacy, is_set(rsc->flags, pe_rsc_unique), lastfailure_re); free(rsc_name); }
void get_meta_attributes(GHashTable * meta_hash, resource_t * rsc, node_t * node, pe_working_set_t * data_set) { GHashTable *node_hash = NULL; const char *version = crm_element_value(data_set->input, XML_ATTR_CRM_VERSION); if (node) { node_hash = node->details->attrs; } if (rsc->xml) { xmlAttrPtr xIter = NULL; for (xIter = rsc->xml->properties; xIter; xIter = xIter->next) { const char *prop_name = (const char *)xIter->name; const char *prop_value = crm_element_value(rsc->xml, prop_name); add_hash_param(meta_hash, prop_name, prop_value); } } unpack_instance_attributes(data_set->input, rsc->xml, XML_TAG_META_SETS, node_hash, meta_hash, NULL, FALSE, data_set->now); if(version == NULL || compare_version(version, "3.0.9") < 0) { /* populate from the regular attributes until the GUI can create * meta attributes */ unpack_instance_attributes(data_set->input, rsc->xml, XML_TAG_ATTR_SETS, node_hash, meta_hash, NULL, FALSE, data_set->now); } /* set anything else based on the parent */ if (rsc->parent != NULL) { g_hash_table_foreach(rsc->parent->meta, dup_attr, meta_hash); } /* and finally check the defaults */ unpack_instance_attributes(data_set->input, data_set->rsc_defaults, XML_TAG_META_SETS, node_hash, meta_hash, NULL, FALSE, data_set->now); }
static int version_check(int fd, const char *from, const char *to) { _cleanup_free_ char *a = NULL, *b = NULL; _cleanup_close_ int fd2 = -1; int r; assert(fd >= 0); assert(from); assert(to); r = get_file_version(fd, &a); if (r < 0) return r; if (r == 0) { log_error("Source file \"%s\" does not carry version information!", from); return -EINVAL; } fd2 = open(to, O_RDONLY|O_CLOEXEC); if (fd2 < 0) { if (errno == ENOENT) return 0; return log_error_errno(errno, "Failed to open \"%s\" for reading: %m", to); } r = get_file_version(fd2, &b); if (r < 0) return r; if (r == 0 || compare_product(a, b) != 0) { log_notice("Skipping \"%s\", since it's owned by another boot loader.", to); return -EEXIST; } if (compare_version(a, b) < 0) { log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to); return -ESTALE; } return 0; }
static gboolean throttle_timer_cb(gpointer data) { static bool send_updates = FALSE; enum throttle_state_e now = throttle_none; if(send_updates) { now = throttle_mode(); throttle_send_command(now); } else if(compare_version(fsa_our_dc_version, "3.0.8") < 0) { /* Optimize for the true case */ crm_trace("DC version %s doesn't support throttling", fsa_our_dc_version); } else { send_updates = TRUE; now = throttle_mode(); throttle_send_command(now); } return TRUE; }
/* A_ELECTION_COUNT */ void do_election_count_vote(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data) { struct timeval your_age; int age; int election_id = -1; int log_level = LOG_INFO; gboolean use_born_on = FALSE; gboolean done = FALSE; gboolean we_loose = FALSE; const char *op = NULL; const char *vote_from = NULL; const char *your_version = NULL; const char *election_owner = NULL; const char *reason = "unknown"; crm_node_t *our_node = NULL, *your_node = NULL; ha_msg_input_t *vote = fsa_typed_data(fsa_dt_ha_msg); static time_t last_election_loss = 0; /* if the membership copy is NULL we REALLY shouldnt be voting * the question is how we managed to get here. */ CRM_CHECK(msg_data != NULL, return); CRM_CHECK(crm_peer_cache != NULL, return); CRM_CHECK(vote != NULL, crm_err("Bogus data from %s", msg_data->origin); return); CRM_CHECK(vote->msg != NULL, crm_err("Bogus data from %s", msg_data->origin); return); your_age.tv_sec = 0; your_age.tv_usec = 0; op = crm_element_value(vote->msg, F_CRM_TASK); vote_from = crm_element_value(vote->msg, F_CRM_HOST_FROM); your_version = crm_element_value(vote->msg, F_CRM_VERSION); election_owner = crm_element_value(vote->msg, F_CRM_ELECTION_OWNER); crm_element_value_int(vote->msg, F_CRM_ELECTION_ID, &election_id); crm_element_value_int(vote->msg, F_CRM_ELECTION_AGE_S, (int *)&(your_age.tv_sec)); crm_element_value_int(vote->msg, F_CRM_ELECTION_AGE_US, (int *)&(your_age.tv_usec)); CRM_CHECK(vote_from != NULL, vote_from = fsa_our_uname); your_node = crm_get_peer(0, vote_from); our_node = crm_get_peer(0, fsa_our_uname); if (voted == NULL) { crm_debug("Created voted hash"); voted = g_hash_table_new_full(crm_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); } if (is_heartbeat_cluster()) { use_born_on = TRUE; } else if (is_classic_ais_cluster()) { use_born_on = TRUE; } age = crm_compare_age(your_age); if (cur_state == S_STARTING) { reason = "Still starting"; we_loose = TRUE; } else if (our_node == NULL || crm_is_peer_active(our_node) == FALSE) { reason = "We are not part of the cluster"; log_level = LOG_ERR; we_loose = TRUE; } else if (election_id != current_election_id && crm_str_eq(fsa_our_uuid, election_owner, TRUE)) { log_level = LOG_DEBUG_2; reason = "Superceeded"; done = TRUE; } else if (your_node == NULL || crm_is_peer_active(your_node) == FALSE) { /* Possibly we cached the message in the FSA queue at a point that it wasn't */ reason = "Peer is not part of our cluster"; log_level = LOG_WARNING; done = TRUE; } else if (crm_str_eq(op, CRM_OP_NOVOTE, TRUE)) { char *op_copy = strdup(op); char *uname_copy = strdup(vote_from); CRM_ASSERT(crm_str_eq(fsa_our_uuid, election_owner, TRUE)); /* update the list of nodes that have voted */ g_hash_table_replace(voted, uname_copy, op_copy); reason = "Recorded"; done = TRUE; } else if (crm_str_eq(vote_from, fsa_our_uname, TRUE)) { char *op_copy = strdup(op); char *uname_copy = strdup(vote_from); CRM_ASSERT(crm_str_eq(fsa_our_uuid, election_owner, TRUE)); /* update ourselves in the list of nodes that have voted */ g_hash_table_replace(voted, uname_copy, op_copy); reason = "Recorded"; done = TRUE; } else if (compare_version(your_version, CRM_FEATURE_SET) < 0) { reason = "Version"; we_loose = TRUE; } else if (compare_version(your_version, CRM_FEATURE_SET) > 0) { reason = "Version"; } else if (age < 0) { reason = "Uptime"; we_loose = TRUE; } else if (age > 0) { reason = "Uptime"; /* TODO: Check for y(our) born < 0 */ } else if (use_born_on && your_node->born < our_node->born) { reason = "Born"; we_loose = TRUE; } else if (use_born_on && your_node->born > our_node->born) { reason = "Born"; } else if (fsa_our_uname == NULL) { reason = "Unknown host name"; we_loose = TRUE; } else if (strcasecmp(fsa_our_uname, vote_from) > 0) { reason = "Host name"; we_loose = TRUE; } else { reason = "Host name"; CRM_ASSERT(strcmp(fsa_our_uname, vote_from) != 0); /* cant happen... * } else if(strcasecmp(fsa_our_uname, vote_from) == 0) { * * default... * } else { // strcasecmp(fsa_our_uname, vote_from) < 0 * we win */ } if (done) { do_crm_log(log_level + 1, "Election %d (current: %d, owner: %s): Processed %s from %s (%s)", election_id, current_election_id, election_owner, op, vote_from, reason); } else if (we_loose) { xmlNode *novote = create_request(CRM_OP_NOVOTE, NULL, vote_from, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL); do_crm_log(log_level, "Election %d (owner: %s) lost: %s from %s (%s)", election_id, election_owner, op, vote_from, reason); update_dc(NULL); crm_timer_stop(election_timeout); if (fsa_input_register & R_THE_DC) { crm_trace("Give up the DC to %s", vote_from); register_fsa_input(C_FSA_INTERNAL, I_RELEASE_DC, NULL); } else if (cur_state != S_STARTING) { crm_trace("We werent the DC anyway"); register_fsa_input(C_FSA_INTERNAL, I_PENDING, NULL); } crm_xml_add(novote, F_CRM_ELECTION_OWNER, election_owner); crm_xml_add_int(novote, F_CRM_ELECTION_ID, election_id); send_cluster_message(crm_get_peer(0, vote_from), crm_msg_crmd, novote, TRUE); free_xml(novote); fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local); last_election_loss = time(NULL); } else { do_crm_log(log_level, "Election %d (owner: %s) pass: %s from %s (%s)", election_id, election_owner, op, vote_from, reason); if (last_election_loss) { time_t tm_now = time(NULL); if (tm_now - last_election_loss < (time_t) loss_dampen) { crm_info("Election %d ignore: We already lost an election less than %ds ago (%s)", election_id, loss_dampen, ctime(&last_election_loss)); update_dc(NULL); return; } last_election_loss = 0; } register_fsa_input(C_FSA_INTERNAL, I_ELECTION, NULL); g_hash_table_destroy(voted); voted = NULL; } }
int main(void) { /* Initialise SysTick timer that will be used as the ChibiOS kernel tick * timer. */ STBase->RVR = SYSTEM_CLOCK / CH_FREQUENCY - 1; STBase->CVR = 0; STBase->CSR = CLKSOURCE_CORE_BITS | ENABLE_ON_BITS | TICKINT_ENABLED_BITS; /* Kernel initialization, the main() function becomes a thread and the RTOS * is active. */ chSysInit(); /* Piksi hardware initialization. */ init(); settings_setup(); usarts_setup(); check_nap_auth(); static char nap_version_string[64] = {0}; nap_conf_rd_version_string(nap_version_string); log_info("NAP firmware version: %s\n", nap_version_string); /* Check we are running a compatible version of the NAP firmware. */ const char *required_nap_version = "v0.9-46"; if (compare_version(nap_version_string, required_nap_version) < 0) { log_error("NAP firmware version newer than %s required, please update!\n" "(instructions can be found at http://docs.swift-nav.com/)\n", required_nap_version); while (1) { chThdSleepSeconds(60); } } static s32 serial_number; serial_number = nap_conf_rd_serial_number(); max2769_setup(); timing_setup(); position_setup(); manage_acq_setup(); manage_track_setup(); system_monitor_setup(); base_obs_setup(); solution_setup(); simulator_setup(); sbp_fileio_setup(); ext_setup(); if (serial_number < 0) { READ_ONLY_PARAMETER("system_info", "serial_number", "(unknown)", TYPE_STRING); } else { READ_ONLY_PARAMETER("system_info", "serial_number", serial_number, TYPE_INT); } READ_ONLY_PARAMETER("system_info", "firmware_version", GIT_VERSION, TYPE_STRING); READ_ONLY_PARAMETER("system_info", "firmware_built", __DATE__ " " __TIME__, TYPE_STRING); static struct setting hw_rev = { "system_info", "hw_revision", NULL, 0, settings_read_only_notify, NULL, NULL, false }; hw_rev.addr = (char *)nap_conf_rd_hw_rev_string(); hw_rev.len = strlen(hw_rev.addr); settings_register(&hw_rev, TYPE_STRING); READ_ONLY_PARAMETER("system_info", "nap_version", nap_version_string, TYPE_STRING); READ_ONLY_PARAMETER("system_info", "nap_channels", nap_track_n_channels, TYPE_INT); READ_ONLY_PARAMETER("system_info", "nap_fft_index_bits", nap_acq_fft_index_bits, TYPE_INT); chThdCreateStatic(wa_nav_msg_thread, sizeof(wa_nav_msg_thread), NORMALPRIO-1, nav_msg_thread, NULL); /* Send message to inform host we are up and running. */ u32 startup_flags = 0; sbp_send_msg(SBP_MSG_STARTUP, sizeof(startup_flags), (u8 *)&startup_flags); while (1) { chThdSleepSeconds(60); } }
/* A_ELECTION_COUNT */ enum election_result election_count_vote(election_t *e, xmlNode *vote, bool can_win) { int age = 0; int election_id = -1; int log_level = LOG_INFO; gboolean use_born_on = FALSE; gboolean done = FALSE; gboolean we_loose = FALSE; const char *op = NULL; const char *from = NULL; const char *reason = "unknown"; const char *election_owner = NULL; crm_node_t *our_node = NULL, *your_node = NULL; static int election_wins = 0; xmlNode *novote = NULL; time_t tm_now = time(NULL); static time_t expires = 0; static time_t last_election_loss = 0; /* if the membership copy is NULL we REALLY shouldn't be voting * the question is how we managed to get here. */ CRM_CHECK(vote != NULL, return election_error); if(e == NULL) { crm_info("Not voting in election: not initialized"); return election_lost; } else if(crm_peer_cache == NULL) { crm_info("Not voting in election: no peer cache"); return election_lost; } op = crm_element_value(vote, F_CRM_TASK); from = crm_element_value(vote, F_CRM_HOST_FROM); election_owner = crm_element_value(vote, F_CRM_ELECTION_OWNER); crm_element_value_int(vote, F_CRM_ELECTION_ID, &election_id); your_node = crm_get_peer(0, from); our_node = crm_get_peer(0, e->uname); if (e->voted == NULL) { crm_debug("Created voted hash"); e->voted = g_hash_table_new_full(crm_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); } if (is_heartbeat_cluster()) { use_born_on = TRUE; } else if (is_classic_ais_cluster()) { use_born_on = TRUE; } if(can_win == FALSE) { reason = "Not eligible"; we_loose = TRUE; } else if (our_node == NULL || crm_is_peer_active(our_node) == FALSE) { reason = "We are not part of the cluster"; log_level = LOG_ERR; we_loose = TRUE; } else if (election_id != e->count && crm_str_eq(our_node->uuid, election_owner, TRUE)) { log_level = LOG_TRACE; reason = "Superseded"; done = TRUE; } else if (your_node == NULL || crm_is_peer_active(your_node) == FALSE) { /* Possibly we cached the message in the FSA queue at a point that it wasn't */ reason = "Peer is not part of our cluster"; log_level = LOG_WARNING; done = TRUE; } else if (crm_str_eq(op, CRM_OP_NOVOTE, TRUE)) { char *op_copy = strdup(op); char *uname_copy = strdup(from); CRM_ASSERT(crm_str_eq(our_node->uuid, election_owner, TRUE)); /* update the list of nodes that have voted */ g_hash_table_replace(e->voted, uname_copy, op_copy); reason = "Recorded"; done = TRUE; } else { struct timeval your_age; const char *your_version = crm_element_value(vote, F_CRM_VERSION); int tv_sec = 0; int tv_usec = 0; crm_element_value_int(vote, F_CRM_ELECTION_AGE_S, &tv_sec); crm_element_value_int(vote, F_CRM_ELECTION_AGE_US, &tv_usec); your_age.tv_sec = tv_sec; your_age.tv_usec = tv_usec; age = crm_compare_age(your_age); if (crm_str_eq(from, e->uname, TRUE)) { char *op_copy = strdup(op); char *uname_copy = strdup(from); CRM_ASSERT(crm_str_eq(our_node->uuid, election_owner, TRUE)); /* update ourselves in the list of nodes that have voted */ g_hash_table_replace(e->voted, uname_copy, op_copy); reason = "Recorded"; done = TRUE; } else if (compare_version(your_version, CRM_FEATURE_SET) < 0) { reason = "Version"; we_loose = TRUE; } else if (compare_version(your_version, CRM_FEATURE_SET) > 0) { reason = "Version"; } else if (age < 0) { reason = "Uptime"; we_loose = TRUE; } else if (age > 0) { reason = "Uptime"; /* TODO: Check for y(our) born < 0 */ } else if (use_born_on && your_node->born < our_node->born) { reason = "Born"; we_loose = TRUE; } else if (use_born_on && your_node->born > our_node->born) { reason = "Born"; } else if (e->uname == NULL) { reason = "Unknown host name"; we_loose = TRUE; } else if (strcasecmp(e->uname, from) > 0) { reason = "Host name"; we_loose = TRUE; } else { reason = "Host name"; CRM_ASSERT(strcasecmp(e->uname, from) < 0); /* can't happen... * } else if(strcasecmp(e->uname, from) == 0) { * */ } } if (expires < tm_now) { election_wins = 0; expires = tm_now + STORM_INTERVAL; } else if (done == FALSE && we_loose == FALSE) { int peers = 1 + g_hash_table_size(crm_peer_cache); /* If every node has to vote down every other node, thats N*(N-1) total elections * Allow some leway before _really_ complaining */ election_wins++; if (election_wins > (peers * peers)) { crm_warn("Election storm detected: %d elections in %d seconds", election_wins, STORM_INTERVAL); election_wins = 0; expires = tm_now + STORM_INTERVAL; crm_write_blackbox(0, NULL); } } if (done) { do_crm_log(log_level + 1, "Election %d (current: %d, owner: %s): Processed %s from %s (%s)", election_id, e->count, election_owner, op, from, reason); return e->state; } else if(we_loose == FALSE) { do_crm_log(log_level, "Election %d (owner: %s) pass: %s from %s (%s)", election_id, election_owner, op, from, reason); if (last_election_loss == 0 || tm_now - last_election_loss > (time_t) loss_dampen) { last_election_loss = 0; election_timeout_stop(e); /* Start a new election by voting down this, and other, peers */ e->state = election_start; return e->state; } crm_info("Election %d ignore: We already lost an election less than %ds ago (%s)", election_id, loss_dampen, ctime(&last_election_loss)); } novote = create_request(CRM_OP_NOVOTE, NULL, from, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL); do_crm_log(log_level, "Election %d (owner: %s) lost: %s from %s (%s)", election_id, election_owner, op, from, reason); election_timeout_stop(e); crm_xml_add(novote, F_CRM_ELECTION_OWNER, election_owner); crm_xml_add_int(novote, F_CRM_ELECTION_ID, election_id); send_cluster_message(your_node, crm_msg_crmd, novote, TRUE); free_xml(novote); last_election_loss = tm_now; e->state = election_lost; return e->state; }
void peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *data) { uint32_t old = 0; uint32_t changed = 0; bool appeared = FALSE; bool is_remote = is_set(node->flags, crm_remote_node); const char *status = NULL; /* Crmd waits to receive some information from the membership layer before * declaring itself operational. If this is being called for a cluster node, * indicate that we have it. */ if (!is_remote) { set_bit(fsa_input_register, R_PEER_DATA); } if (node->uname == NULL) { return; } switch (type) { case crm_status_uname: /* If we've never seen the node, then it also won't be in the status section */ crm_info("%s node %s is now %s", (is_remote? "Remote" : "Cluster"), node->uname, state_text(node->state)); return; case crm_status_rstate: case crm_status_nstate: /* This callback should not be called unless the state actually * changed, but here's a failsafe just in case. */ CRM_CHECK(safe_str_neq(data, node->state), return); crm_info("%s node %s is now %s (was %s)", (is_remote? "Remote" : "Cluster"), node->uname, state_text(node->state), state_text(data)); if (safe_str_eq(CRM_NODE_MEMBER, node->state)) { appeared = TRUE; if (!is_remote) { remove_stonith_cleanup(node->uname); } } crmd_alert_node_event(node); break; case crm_status_processes: if (data) { old = *(const uint32_t *)data; changed = node->processes ^ old; } status = (node->processes & proc_flags) ? ONLINESTATUS : OFFLINESTATUS; crm_info("Client %s/%s now has status [%s] (DC=%s, changed=%6x)", node->uname, peer2text(proc_flags), status, AM_I_DC ? "true" : crm_str(fsa_our_dc), changed); if ((changed & proc_flags) == 0) { /* Peer process did not change */ crm_trace("No change %6x %6x %6x", old, node->processes, proc_flags); return; } else if (is_not_set(fsa_input_register, R_CIB_CONNECTED)) { crm_trace("Not connected"); return; } else if (fsa_state == S_STOPPING) { crm_trace("Stopping"); return; } appeared = (node->processes & proc_flags) != 0; if (safe_str_eq(node->uname, fsa_our_uname) && (node->processes & proc_flags) == 0) { /* Did we get evicted? */ crm_notice("Our peer connection failed"); register_fsa_input(C_CRMD_STATUS_CALLBACK, I_ERROR, NULL); } else if (safe_str_eq(node->uname, fsa_our_dc) && crm_is_peer_active(node) == FALSE) { /* Did the DC leave us? */ crm_notice("Our peer on the DC (%s) is dead", fsa_our_dc); register_fsa_input(C_CRMD_STATUS_CALLBACK, I_ELECTION, NULL); /* @COMPAT DC < 1.1.13: If a DC shuts down normally, we don't * want to fence it. Newer DCs will send their shutdown request * to all peers, who will update the DC's expected state to * down, thus avoiding fencing. We can safely erase the DC's * transient attributes when it leaves in that case. However, * the only way to avoid fencing older DCs is to leave the * transient attributes intact until it rejoins. */ if (compare_version(fsa_our_dc_version, "3.0.9") > 0) { erase_status_tag(node->uname, XML_TAG_TRANSIENT_NODEATTRS, cib_scope_local); } } else if(AM_I_DC && appeared == FALSE) { crm_info("Peer %s left us", node->uname); erase_status_tag(node->uname, XML_TAG_TRANSIENT_NODEATTRS, cib_scope_local); } break; } if (AM_I_DC) { xmlNode *update = NULL; int flags = node_update_peer; gboolean alive = is_remote? appeared : crm_is_peer_active(node); crm_action_t *down = match_down_event(node->uuid, appeared); crm_trace("Alive=%d, appeared=%d, down=%d", alive, appeared, (down? down->id : -1)); if (alive && type == crm_status_processes) { register_fsa_input_before(C_FSA_INTERNAL, I_NODE_JOIN, NULL); } if (down) { const char *task = crm_element_value(down->xml, XML_LRM_ATTR_TASK); if (safe_str_eq(task, CRM_OP_FENCE)) { /* tengine_stonith_callback() confirms fence actions */ crm_trace("Updating CIB %s stonithd reported fencing of %s complete", (down->confirmed? "after" : "before"), node->uname); } else if ((alive == FALSE) && safe_str_eq(task, CRM_OP_SHUTDOWN)) { crm_notice("%s of peer %s is complete "CRM_XS" op=%d", task, node->uname, down->id); /* down->confirmed = TRUE; */ stop_te_timer(down->timer); if (!is_remote) { flags |= node_update_join | node_update_expected; crmd_peer_down(node, FALSE); check_join_state(fsa_state, __FUNCTION__); } update_graph(transition_graph, down); trigger_graph(); } else { crm_trace("Node %s is %salive, was expected to %s (op %d)", node->uname, (alive? "" : "not "), task, down->id); } } else if (appeared == FALSE) { crm_notice("Stonith/shutdown of %s not matched", node->uname); if (!is_remote) { crm_update_peer_join(__FUNCTION__, node, crm_join_none); check_join_state(fsa_state, __FUNCTION__); } abort_transition(INFINITY, tg_restart, "Node failure", NULL); fail_incompletable_actions(transition_graph, node->uuid); } else { crm_trace("Node %s came up, was not expected to be down", node->uname); } if (is_remote) { /* A pacemaker_remote node won't have its cluster status updated * in the CIB by membership-layer callbacks, so do it here. */ flags |= node_update_cluster; /* Trigger resource placement on newly integrated nodes */ if (appeared) { abort_transition(INFINITY, tg_restart, "pacemaker_remote node integrated", NULL); } } /* Update the CIB node state */ update = create_node_state_update(node, flags, NULL, __FUNCTION__); fsa_cib_anon_update(XML_CIB_TAG_STATUS, update, cib_scope_local | cib_quorum_override | cib_can_create); free_xml(update); } trigger_fsa(fsa_source); }
/* * Implements the <IfVersion> container */ static const char *start_ifversion(cmd_parms *cmd, void *mconfig, const char *arg1, const char *arg2, const char *arg3) { const char *endp; int reverse = 0, done = 0, match = 0, compare; const char *p, *error; char c; /* supplying one argument is possible, we assume an equality check then */ if (!arg2) { arg2 = arg1; arg1 = "="; } /* surrounding quotes without operator */ if (!arg3 && *arg2 == '>' && !arg2[1]) { arg3 = ">"; arg2 = arg1; arg1 = "="; } /* the third argument makes version surrounding quotes plus operator * possible. */ endp = arg2 + strlen(arg2); if ( endp == arg2 || (!(arg3 && *arg3 == '>' && !arg3[1]) && *--endp != '>')) { return apr_pstrcat(cmd->pool, cmd->cmd->name, "> directive missing closing '>'", NULL); } p = arg1; if (*p == '!') { reverse = 1; if (p[1]) { ++p; } } c = *p++; if (!*p || (*p == '=' && !p[1] && c != '~')) { if (!httpd_version.major) { ap_get_server_revision(&httpd_version); } done = 1; switch (c) { case '=': /* normal comparison */ if (*arg2 != '/') { compare = compare_version(apr_pstrmemdup(cmd->pool, arg2, endp-arg2), &error); if (error) { return error; } match = !compare; break; } /* regexp otherwise */ if (endp == ++arg2 || *--endp != '/') { return "Missing delimiting / of regular expression."; } case '~': /* regular expression */ match = match_version(cmd->pool, apr_pstrmemdup(cmd->pool, arg2, endp-arg2), &error); if (error) { return error; } break; case '<': compare = compare_version(apr_pstrmemdup(cmd->pool, arg2, endp-arg2), &error); if (error) { return error; } match = ((-1 == compare) || (*p && !compare)); break; case '>': compare = compare_version(apr_pstrmemdup(cmd->pool, arg2, endp-arg2), &error); if (error) { return error; } match = ((1 == compare) || (*p && !compare)); break; default: done = 0; break; } } if (!done) { return apr_pstrcat(cmd->pool, "unrecognized operator '", arg1, "'", NULL); } if ((!reverse && match) || (reverse && !match)) { ap_directive_t *parent = NULL; ap_directive_t *current = NULL; const char *retval; retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd, ¤t, &parent, "<IfVersion"); *(ap_directive_t **)mconfig = current; return retval; } *(ap_directive_t **)mconfig = NULL; return ap_soak_end_container(cmd, "<IfVersion"); }
int transcode_stream::transcode_process(platform::process &process) { std::vector<std::string> vlc_options; vlc_options.push_back("--no-sub-autodetect-file"); if (compare_version(instance::version(), "2.1") >= 0) vlc_options.push_back("--avcodec-fast"); int font_size = -1; process >> font_size; if (font_size > 0) { vlc_options.push_back("--freetype-fontsize"); vlc_options.push_back(std::to_string(font_size)); } vlc::instance instance(vlc_options); std::string mrl, transcode, mux; process >> mrl >> transcode >> mux; std::ostringstream sout; sout << ":sout=" << from_percent(transcode) << ":std{access=fd,mux=" << mux << ",dst=" << process.output_fd() << "}"; auto media = media::from_mrl(instance, mrl); libvlc_media_add_option(media, sout.str().c_str()); std::string subtitle_file; process >> subtitle_file; if (subtitle_file != "(none)") { std::string file = from_percent(subtitle_file); #ifdef WIN32 file = from_utf16(platform::to_windows_path(file)); #endif libvlc_media_add_option(media, (":sub-file=" + file).c_str()); } size_t num_options = 0; process >> num_options; for (size_t i = 0; i < num_options; i++) { std::string option; process >> option; libvlc_media_add_option(media, from_percent(option).c_str()); } struct T { static void callback(const libvlc_event_t *e, void *opaque) { T * const t = reinterpret_cast<T *>(opaque); std::lock_guard<std::mutex> _(t->mutex); if (e->type == libvlc_MediaPlayerTimeChanged) { if (t->info) t->info->time = e->u.media_player_time_changed.new_time; } else if (e->type == libvlc_MediaPlayerPlaying) { t->started = true; if (t->track_ids.video >= -1) { libvlc_video_set_track(t->player, -1); if (t->track_ids.video > 0) libvlc_video_set_track(t->player, t->track_ids.video); } if (t->track_ids.audio >= -1) { libvlc_audio_set_track(t->player, -1); if (t->track_ids.audio >= 0) libvlc_audio_set_track(t->player, t->track_ids.audio); } if (t->track_ids.text >= -1) { libvlc_video_set_spu(t->player, -1); if (t->track_ids.text >= 0) libvlc_video_set_spu(t->player, t->track_ids.text); } } else if (e->type == libvlc_MediaPlayerEndReached) { t->end_reached = true; if (t->info) t->info->end_reached = true; } else if (e->type == libvlc_MediaPlayerEncounteredError) t->encountered_error = true; t->condition.notify_one(); } volatile shared_info *info; struct track_ids track_ids; std::mutex mutex; std::condition_variable condition; bool started; bool end_reached; bool encountered_error; libvlc_media_player_t *player; } t; unsigned info_offset(-1); process >> info_offset; process >> t.track_ids.audio >> t.track_ids.video >> t.track_ids.text; int chapter = -1; int64_t position = -1; float rate = 0.0f; process >> chapter >> position >> rate; t.info = &process.get_shared<shared_info>(info_offset); t.started = false; t.end_reached = false; t.encountered_error = false; t.player = libvlc_media_player_new_from_media(media); if (t.player) { auto event_manager = libvlc_media_player_event_manager(t.player); libvlc_event_attach(event_manager, libvlc_MediaPlayerTimeChanged, &T::callback, &t); libvlc_event_attach(event_manager, libvlc_MediaPlayerPlaying, &T::callback, &t); libvlc_event_attach(event_manager, libvlc_MediaPlayerEndReached, &T::callback, &t); libvlc_event_attach(event_manager, libvlc_MediaPlayerEncounteredError, &T::callback, &t); if (libvlc_media_player_play(t.player) == 0) { std::unique_lock<std::mutex> l(t.mutex); while (!t.end_reached && !t.encountered_error && process) { if (t.started) { l.unlock(); if (chapter >= 0) libvlc_media_player_set_chapter(t.player, chapter); if (position > 0) libvlc_media_player_set_time(t.player, position); if (std::abs(rate - 1.0f) > 0.01f) libvlc_media_player_set_rate(t.player, rate); l.lock(); t.started = false; } t.condition.wait(l); } l.unlock(); libvlc_media_player_stop(t.player); } libvlc_event_detach(event_manager, libvlc_MediaPlayerEncounteredError, &T::callback, &t); libvlc_event_detach(event_manager, libvlc_MediaPlayerEndReached, &T::callback, &t); libvlc_event_detach(event_manager, libvlc_MediaPlayerPlaying, &T::callback, &t); libvlc_event_detach(event_manager, libvlc_MediaPlayerTimeChanged, &T::callback, &t); libvlc_media_player_release(t.player); } return 0; }
void do_election_count_vote(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { int election_id = -1; int log_level = LOG_INFO; gboolean done = FALSE; gboolean we_loose = FALSE; const char *op = NULL; const char *vote_from = NULL; const char *your_version = NULL; const char *election_owner = NULL; const char *reason = "unknown"; crm_node_t *our_node = NULL, *your_node = NULL; ha_msg_input_t *vote = fsa_typed_data(fsa_dt_ha_msg); static time_t last_election_win = 0; static time_t last_election_loss = 0; /* if the membership copy is NULL we REALLY shouldnt be voting * the question is how we managed to get here. */ CRM_CHECK(msg_data != NULL, return); CRM_CHECK(crm_peer_cache != NULL, return); CRM_CHECK(vote != NULL, crm_err("Bogus data from %s", msg_data->origin); return); CRM_CHECK(vote->msg != NULL, crm_err("Bogus data from %s", msg_data->origin); return); /* 受信メッセージデータを取り出す */ op = crm_element_value(vote->msg, F_CRM_TASK); vote_from = crm_element_value(vote->msg, F_CRM_HOST_FROM); your_version = crm_element_value(vote->msg, F_CRM_VERSION); election_owner = crm_element_value(vote->msg, F_CRM_ELECTION_OWNER); crm_element_value_int(vote->msg, F_CRM_ELECTION_ID, &election_id); CRM_CHECK(vote_from != NULL, vote_from = fsa_our_uname); /* CRM_OP_VOTEメッセージの送信元のノード情報を取得する */ your_node = crm_get_peer(0, vote_from); /* 自ノードのノード情報を取得する */ our_node = crm_get_peer(0, fsa_our_uname); if(voted == NULL) { crm_debug("Created voted hash"); /* votedハッシュテーブルが未作成の場合は作成する */ voted = g_hash_table_new_full( g_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); } if(cur_state == S_STARTING) { /* 自ノードの状態が、まだ、S_STARTING状態の場合は、DCになれないのでCRM_OP_NOVOTEメッセージを送信する */ reason = "Still starting"; we_loose = TRUE; } else if(our_node == NULL || crm_is_member_active(our_node) == FALSE) { /* 自ノードがまだクラスタ構成として認識されていないか、アクティブでない場合は */ /* DCになれないのでCRM_OP_NOVOTEメッセージを送信する */ reason = "We are not part of the cluster"; log_level = LOG_ERR; we_loose = TRUE; } else if(your_node == NULL || crm_is_member_active(your_node) == FALSE) { /* CRM_OP_VOTEメッセージの送信元のノードがクラスタ構成として認識されていないか、アクティブでない場合は */ /* ログのみを出力する */ reason = "Peer is not part of our cluster"; log_level = LOG_WARNING; done = TRUE; } else if(election_id != current_election_id && crm_str_eq(fsa_our_uuid, election_owner, TRUE)) { /* 現在のelection_idと受信したelection_idが違う場合も、ログのみ出力する */ log_level = LOG_DEBUG_2; reason = "Superceeded"; done = TRUE; } else if(crm_str_eq(op, CRM_OP_NOVOTE, TRUE)) { /* DCになれないと思ったノードが送信したCRM_OP_NOVOTEメッセージの場合 */ char *op_copy = crm_strdup(op); char *uname_copy = crm_strdup(vote_from); CRM_ASSERT(crm_str_eq(fsa_our_uuid, election_owner, TRUE)); /* update the list of nodes that have voted */ /* votedハッシュテーブルにノードデータをセットする */ g_hash_table_replace(voted, uname_copy, op_copy); reason = "Recorded"; done = TRUE; } else if(crm_str_eq(vote_from, fsa_our_uname, TRUE)) { /* 自ノードが送信したCRM_OP_VOTEメッセージを処理する場合 */ char *op_copy = crm_strdup(op); char *uname_copy = crm_strdup(vote_from); CRM_ASSERT(crm_str_eq(fsa_our_uuid, election_owner, TRUE)); /* update ourselves in the list of nodes that have voted */ /* votedハッシュテーブルにノードデータをセットする */ g_hash_table_replace(voted, uname_copy, op_copy); reason = "Recorded"; done = TRUE; } else if(compare_version(your_version, CRM_FEATURE_SET) < 0) { /* 受信したCRM_OP_VOTEメッセージの送り元のversionがCRM_FEATURE_SETよりも小さい場合 */ /* 自ノードは、DCになれない */ reason = "Version"; we_loose = TRUE; } else if(compare_version(your_version, CRM_FEATURE_SET) > 0) { /* 受信したCRM_OP_VOTEメッセージの送り元のversionがCRM_FEATURE_SETよりも大きい場合、ログのみ出力する */ reason = "Version"; } else if(your_node->born < our_node->born) { /* 受信したCRM_OP_VOTEメッセージの送り元の方がbornが自ノードよりも小さい場合 */ reason = "Age"; /* 自ノードは、DCになれない */ we_loose = TRUE; } else if(your_node->born > our_node->born) { /* 受信したCRM_OP_VOTEメッセージの送り元の方がbornが自ノードよりも大きい場合 */ /* 自ノードは、DCの候補 */ reason = "Age"; } else if(fsa_our_uname == NULL) { /* 自ノードのノード名称がセットされていない場合 */ /* 自ノードは、DCになれない */ reason = "Unknown host name"; we_loose = TRUE; } else if(strcasecmp(fsa_our_uname, vote_from) > 0) { /* 自ノードのノード名が送信元...*/ /* 自ノードは、DCになれない */ reason = "Host name"; we_loose = TRUE; } else { /* その他の場合 */ reason = "Host name"; CRM_ASSERT(strcmp(fsa_our_uname, vote_from) != 0); /* cant happen... * } else if(strcasecmp(fsa_our_uname, vote_from) == 0) { * * default... * } else { // strcasecmp(fsa_our_uname, vote_from) < 0 * we win */ } if(done) { do_crm_log(log_level+1, "Election %d (current: %d, owner: %s): Processed %s from %s (%s)", election_id, current_election_id, election_owner, op, vote_from, reason); } else if(we_loose) { /* born値の比較などから、DCノードになれないと判断した場合 */ /* CRM_OP_NOVOTEメッセージをCRMD宛に生成する */ xmlNode *novote = create_request( CRM_OP_NOVOTE, NULL, vote_from, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL); do_crm_log(log_level+1, "Election %d (owner: %s) lost: %s from %s (%s)", election_id, election_owner, op, vote_from, reason); /* DCノードにNULLをセットする */ update_dc(NULL); /* election_timeoutタイマーを止める */ crm_timer_stop(election_timeout); if(fsa_input_register & R_THE_DC) { crm_debug_3("Give up the DC to %s", vote_from); register_fsa_input(C_FSA_INTERNAL, I_RELEASE_DC, NULL); } else if(cur_state != S_STARTING) { crm_debug_3("We werent the DC anyway"); register_fsa_input(C_FSA_INTERNAL, I_PENDING, NULL); } /* CRM_OP_NOVOTEメッセージのF_CRM_ELECTION_OWNERに受信メッセージのelection_ownerをセットする */ crm_xml_add(novote, F_CRM_ELECTION_OWNER, election_owner); /* CRM_OP_NOVOTEメッセージのF_CRM_ELECTION_IDに受信メッセージのelection_idをセットする */ crm_xml_add_int(novote, F_CRM_ELECTION_ID, election_id); /* CRM_OP_VOTEメッセージの送信元にCRM_OP_NOVOTEメッセージを送信する */ send_cluster_message(vote_from, crm_msg_crmd, novote, TRUE); /* 送信メッセージを解放する */ free_xml(novote); /* CIBのset_slave処理を実行する */ fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local); last_election_loss = time(NULL); last_election_win = 0; } else { do_crm_log(log_level, "Election %d (owner: %s) pass: %s from %s (%s)", election_id, election_owner, op, vote_from, reason); if(last_election_loss) { time_t tm_now = time(NULL); if(tm_now - last_election_loss < (time_t)loss_dampen) { crm_info("Election %d ignore: We already lost an election less than %ds ago", election_id, loss_dampen); update_dc(NULL); return; } last_election_loss = 0; } #if 0 /* Enabling this code can lead to multiple DCs during SimulStart. * Specifically when a node comes up after our last 'win' vote. * * Fixing and enabling this functionality might become important when * we start running realy big clusters, but for now leave it disabled. */ if(last_election_win) { time_t tm_now = time(NULL); if(tm_now - last_election_win < (time_t)win_dampen) { crm_info("Election %d ignore: We already won an election less than %ds ago", election_id, win_dampen); return; } } last_election_win = time(NULL); #endif /* I_ELECTIONへ */ register_fsa_input(C_FSA_INTERNAL, I_ELECTION, NULL); g_hash_table_destroy(voted); voted = NULL; } }
/* Usage: <IfVersion [!]op version-string|regex> */ MODRET start_ifversion(cmd_rec *cmd) { unsigned int ifversion_ctx_count = 1; int compared, matched = FALSE, negated = FALSE; char buf[PR_TUNABLE_BUFFER_SIZE], *config_line = NULL; char *error = NULL, *version_str = NULL, *op_str = NULL; size_t op_len; if (cmd->argc-1 == 0 || cmd->argc-1 > 2) { CONF_ERROR(cmd, "wrong number of parameters"); } if (cmd->argc-1 == 2) { op_str = cmd->argv[1]; if (*op_str == '!' && strlen(op_str) > 1) { negated = TRUE; op_str++; } op_len = strlen(op_str); version_str = cmd->argv[2]; } else { /* Assume that if only a version-string was supplied, the operator * is intended to be the equality operator. */ op_str = "="; op_len = 1; version_str = cmd->argv[1]; } switch (*op_str) { case '=': if (*version_str != '/') { /* Normal equality comparison */ compared = compare_version(cmd->tmp_pool, version_str, &error); if (error != NULL) { CONF_ERROR(cmd, error); } matched = (compared == 0); break; } /* Otherwise, it's a regular expression */ if (version_str[strlen(version_str)-1] != '/') { CONF_ERROR(cmd, "Missing terminating '/' of regular expression"); } /* Fall through to the next case in order to handle/evaluate the * regular expression. Be sure to remove the bracketing '/' characters * for the regex compilation. */ version_str[strlen(version_str)-1] = '\0'; version_str++; case '~': /* Regular expression */ matched = match_version(cmd->tmp_pool, version_str, &error); if (error != NULL) { CONF_ERROR(cmd, error); } break; case '<': compared = compare_version(cmd->tmp_pool, version_str, &error); if (error != NULL) { CONF_ERROR(cmd, error); } if (compared == -1 || (op_len == 2 && compared == 0)) { matched = TRUE; } break; case '>': compared = compare_version(cmd->tmp_pool, version_str, &error); if (error != NULL) { CONF_ERROR(cmd, error); } if (compared == 1 || (op_len == 2 && compared == 0)) { matched = TRUE; } break; default: CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unknown comparison operator '", op_str, "'", NULL)); } if ((matched && !negated) || (!matched && negated)) { pr_log_debug(DEBUG3, "%s: using '%s %s' section at line %u", cmd->argv[0], cmd->argv[1], cmd->argv[2], pr_parser_get_lineno()); return PR_HANDLED(cmd); } pr_log_debug(DEBUG3, "%s: skipping '%s %s' section at line %u", cmd->argv[0], cmd->argv[1], cmd->argv[2], pr_parser_get_lineno()); while (ifversion_ctx_count > 0 && (config_line = pr_parser_read_line(buf, sizeof(buf))) != NULL) { pr_signals_handle(); if (strncasecmp(config_line, "<IfVersion", 10) == 0) { ifversion_ctx_count++; } if (strcasecmp(config_line, "</IfVersion>") == 0) { ifversion_ctx_count--; } } /* If there are still unclosed <IfVersion> sections, signal an error. */ if (ifversion_ctx_count > 0) { CONF_ERROR(cmd, "unclosed <IfVersion> section"); } return PR_HANDLED(cmd); }
gboolean test_attr_expression(xmlNode * expr, GHashTable * hash, crm_time_t * now) { gboolean accept = FALSE; int cmp = 0; const char *h_val = NULL; const char *op = NULL; const char *type = NULL; const char *attr = NULL; const char *value = NULL; attr = crm_element_value(expr, XML_EXPR_ATTR_ATTRIBUTE); op = crm_element_value(expr, XML_EXPR_ATTR_OPERATION); value = crm_element_value(expr, XML_EXPR_ATTR_VALUE); type = crm_element_value(expr, XML_EXPR_ATTR_TYPE); if (attr == NULL || op == NULL) { pe_err("Invlaid attribute or operation in expression" " (\'%s\' \'%s\' \'%s\')", crm_str(attr), crm_str(op), crm_str(value)); return FALSE; } if (hash != NULL) { h_val = (const char *)g_hash_table_lookup(hash, attr); } if (value != NULL && h_val != NULL) { if (type == NULL) { if (safe_str_eq(op, "lt") || safe_str_eq(op, "lte") || safe_str_eq(op, "gt") || safe_str_eq(op, "gte")) { type = "number"; } else { type = "string"; } crm_trace("Defaulting to %s based comparison for '%s' op", type, op); } if (safe_str_eq(type, "string")) { cmp = strcasecmp(h_val, value); } else if (safe_str_eq(type, "number")) { int h_val_f = crm_parse_int(h_val, NULL); int value_f = crm_parse_int(value, NULL); if (h_val_f < value_f) { cmp = -1; } else if (h_val_f > value_f) { cmp = 1; } else { cmp = 0; } } else if (safe_str_eq(type, "version")) { cmp = compare_version(h_val, value); } } else if (value == NULL && h_val == NULL) { cmp = 0; } else if (value == NULL) { cmp = 1; } else { cmp = -1; } if (safe_str_eq(op, "defined")) { if (h_val != NULL) { accept = TRUE; } } else if (safe_str_eq(op, "not_defined")) { if (h_val == NULL) { accept = TRUE; } } else if (safe_str_eq(op, "eq")) { if ((h_val == value) || cmp == 0) { accept = TRUE; } } else if (safe_str_eq(op, "ne")) { if ((h_val == NULL && value != NULL) || (h_val != NULL && value == NULL) || cmp != 0) { accept = TRUE; } } else if (value == NULL || h_val == NULL) { /* the comparision is meaningless from this point on */ accept = FALSE; } else if (safe_str_eq(op, "lt")) { if (cmp < 0) { accept = TRUE; } } else if (safe_str_eq(op, "lte")) { if (cmp <= 0) { accept = TRUE; } } else if (safe_str_eq(op, "gt")) { if (cmp > 0) { accept = TRUE; } } else if (safe_str_eq(op, "gte")) { if (cmp >= 0) { accept = TRUE; } } return accept; }
void filter_action_parameters(xmlNode *param_set, const char *version) { char *key = NULL; char *timeout = NULL; char *interval = NULL; #if CRM_DEPRECATED_SINCE_2_0_5 const char *filter_205[] = { XML_ATTR_TE_TARGET_RC, XML_ATTR_LRM_PROBE, XML_RSC_ATTR_START, XML_RSC_ATTR_NOTIFY, XML_RSC_ATTR_UNIQUE, XML_RSC_ATTR_MANAGED, XML_RSC_ATTR_PRIORITY, XML_RSC_ATTR_MULTIPLE, XML_RSC_ATTR_STICKINESS, XML_RSC_ATTR_FAIL_STICKINESS, XML_RSC_ATTR_TARGET_ROLE, /* ignore clone fields */ XML_RSC_ATTR_INCARNATION, XML_RSC_ATTR_INCARNATION_MAX, XML_RSC_ATTR_INCARNATION_NODEMAX, XML_RSC_ATTR_MASTER_MAX, XML_RSC_ATTR_MASTER_NODEMAX, /* old field names */ "role", "crm_role", "te-target-rc", /* ignore notify fields */ "notify_stop_resource", "notify_stop_uname", "notify_start_resource", "notify_start_uname", "notify_active_resource", "notify_active_uname", "notify_inactive_resource", "notify_inactive_uname", "notify_promote_resource", "notify_promote_uname", "notify_demote_resource", "notify_demote_uname", "notify_master_resource", "notify_master_uname", "notify_slave_resource", "notify_slave_uname" }; #endif const char *attr_filter[] = { XML_ATTR_ID, XML_ATTR_CRM_VERSION, XML_LRM_ATTR_OP_DIGEST, }; gboolean do_delete = FALSE; int lpc = 0; static int meta_len = 0; if(meta_len == 0) { meta_len = strlen(CRM_META); } if(param_set == NULL) { return; } #if CRM_DEPRECATED_SINCE_2_0_5 if(version == NULL || compare_version("1.0.5", version) > 0) { for(lpc = 0; lpc < DIMOF(filter_205); lpc++) { xml_remove_prop(param_set, filter_205[lpc]); } } #endif for(lpc = 0; lpc < DIMOF(attr_filter); lpc++) { xml_remove_prop(param_set, attr_filter[lpc]); } key = crm_meta_name(XML_LRM_ATTR_INTERVAL); interval = crm_element_value_copy(param_set, key); crm_free(key); key = crm_meta_name(XML_ATTR_TIMEOUT); timeout = crm_element_value_copy(param_set, key); xml_prop_iter(param_set, prop_name, prop_value, do_delete = FALSE; if(strncasecmp(prop_name, CRM_META, meta_len) == 0) { do_delete = TRUE; } if(do_delete) { xml_remove_prop(param_set, prop_name); } );
int main(void) { halInit(); /* Kernel initialization, the main() function becomes a thread with * priority NORMALPRIO and the RTOS is active. */ chSysInit(); /* Piksi hardware initialization. */ init(); settings_setup(); signal_init(); check_nap_auth(); static char nap_version_string[64] = {0}; nap_conf_rd_version_string(nap_version_string); log_info("NAP firmware version: %s", nap_version_string); /* Check we are running a compatible version of the NAP firmware. */ const char *required_nap_version = "v0.16"; if (compare_version(nap_version_string, required_nap_version) < 0) { while (1) { log_error("NAP firmware version >= %s required, please update!" "(instructions can be found at http://docs.swift-nav.com/)", required_nap_version); chThdSleepSeconds(2); } } static s32 serial_number; serial_number = nap_conf_rd_serial_number(); frontend_setup(); timing_setup(); ext_event_setup(); position_setup(); track_setup(); track_gps_l1ca_register(); decode_setup(); decode_gps_l1_register(); manage_acq_setup(); manage_track_setup(); system_monitor_setup(); base_obs_setup(); solution_setup(); simulator_setup(); sbp_fileio_setup(); ext_setup(); pps_setup(); READ_ONLY_PARAMETER("system_info", "serial_number", serial_number, TYPE_INT); READ_ONLY_PARAMETER("system_info", "firmware_version", GIT_VERSION, TYPE_STRING); READ_ONLY_PARAMETER("system_info", "firmware_built", __DATE__ " " __TIME__, TYPE_STRING); static struct setting hw_rev = { "system_info", "hw_revision", NULL, 0, settings_read_only_notify, NULL, NULL, false }; hw_rev.addr = (char *)nap_conf_rd_hw_rev_string(); hw_rev.len = strlen(hw_rev.addr); settings_register(&hw_rev, TYPE_STRING); READ_ONLY_PARAMETER("system_info", "nap_version", nap_version_string, TYPE_STRING); READ_ONLY_PARAMETER("system_info", "nap_channels", nap_track_n_channels, TYPE_INT); READ_ONLY_PARAMETER("system_info", "nap_fft_index_bits", nap_acq_fft_index_bits, TYPE_INT); ephemeris_setup(); /* Send message to inform host we are up and running. */ u32 startup_flags = 0; sbp_send_msg(SBP_MSG_STARTUP, sizeof(startup_flags), (u8 *)&startup_flags); while (1) { chThdSleepSeconds(60); } }