i4_bool g1_critical_map_maker_class::add_critical(w32 x,w32 y,w8 d, g1_graph_node critical) //{{{ { //unsigned '<' is always false (for x<0...) if (d>0 && (x>=map->width() || y>=map->height() || critical_full(x,y,critical))) { return i4_F; } set_critical(x,y,critical); cnx[head] = x; cny[head] = y; crit[head] = critical; if (++head>=queue_length) { head=0; } if (head==tail) { i4_warning("queue overrun."); } return i4_T; }
void MemoryDump::set_critical(const std::vector<ChildNode> &nodes, int level) { double m = -1; for (auto node : nodes) { if (node.node->subtree_size > m) { m = node.node->subtree_size; } } for (auto node : nodes) { if (node.node->subtree_size >= 0.5 * m) { if (node.node->visited >= 0) continue; node.node->visited = level; node.node->critical = true; set_critical(node.node->children, level + 1); } } }
double MemoryDump::update_subtree_size() { total_size = 0; for (auto node : top_nodes) { std::set<uintptr_t> path; pre_update_subtree_size(*node.node, path); clear_visited(*node.node); } for (auto node : top_nodes) { std::set<uintptr_t> path; total_size += update_subtree_size(*node.node, path); } clear_visited(); set_critical(top_nodes); clear_visited(); return total_size; }
int main (int argc, char **argv) { /* Local Vars */ int ret; int i; unsigned int len; gnutls_x509_crt_t cert[1]; char *subject = NULL; size_t subject_len; time_t expiration_time, activation_time; /* Set signal handling and alarm */ if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) critical("Setup SIGALRM trap failed!"); /* Process check arguments */ if (process_arguments(argc, argv) != OK) unknown("Parsing arguments failed!"); /* Start plugin timeout */ alarm(mp_timeout); /* Init GnuTLS */ gnutls_global_init(); for(i = 0; i < cert_files; i++) { if (mp_verbose) printf("Cert: %s\n", cert_file[i]); /* Read the Cert */ gnutls_datum_t data = { NULL, 0 }; ret = mp_slurp(cert_file[i], &(data.data)); data.size = ret; if (ret <= 0) { set_critical("Error loading cert file '%s'.", cert_file[i]); continue; } /* Load the Cert to a list. */ len = 1; ret = gnutls_x509_crt_list_import(cert, &len, &data, GNUTLS_X509_FMT_PEM, GNUTLS_X509_CRT_LIST_IMPORT_FAIL_IF_EXCEED); if (ret < 0) { set_critical("%s error: %s", cert_file[i], gnutls_strerror(ret)); continue; }; /* Read der Cert CN */ if (subject == NULL) { subject = mp_malloc(128); subject_len = 128; } ret = gnutls_x509_crt_get_dn_by_oid(cert[0], GNUTLS_OID_X520_COMMON_NAME, 0, 0, subject, &subject_len); if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER) { subject_len+=1; subject = mp_realloc(subject, subject_len); ret = gnutls_x509_crt_get_dn_by_oid(cert[0], GNUTLS_OID_X520_COMMON_NAME, 0, 0, subject, &subject_len); } if (ret != 0) { set_critical("%s error: %s", cert_file[i], gnutls_strerror(ret)); continue; } if (mp_verbose) { printf(" * Subject: %s\n", subject); } /* Check expire time */ expiration_time = gnutls_x509_crt_get_expiration_time (cert[0]); activation_time = gnutls_x509_crt_get_activation_time (cert[0]); if (mp_verbose) { printf (" * Certificate is valid since: %s", ctime (&activation_time)); printf (" * Certificate expires: %s", ctime (&expiration_time)); } int days = (int)difftime(expiration_time, time(0))/86400; switch (get_status((expiration_time-time(0)), expire_thresholds)) { case STATE_OK: set_ok(cert_file[i]); break; case STATE_WARNING: set_warning("%s expires in %d day%s", cert_file[i], days, days==1?"":"s"); break; case STATE_CRITICAL: set_critical("%s expires in %d day%s", cert_file[i], days, days==1?"":"s"); break; } if (activation_time > time(0)) { int days = (int)difftime(activation_time, time(0))/86400; set_critical("%s activates in %d day%s", cert_file[i], days, days==1?"":"s"); } } // Dissconnect gnutls_global_deinit (); mp_exit("X509"); }