/* Guess a value for the install PREFIX. */ static const char * guess_prefix( const char *argv0, const char *name ) { char *prefix; /* Try to guess from argv0. */ if( argv0 ) { if( g_path_is_absolute( argv0 ) ) { /* Must point to our executable. */ if( (prefix = extract_prefix( argv0, name )) ) { #ifdef DEBUG printf( "vips_guess_prefix: found \"%s\" from " "argv0\n", prefix ); #endif /*DEBUG*/ return( prefix ); } } /* Look along path for name. */ if( (prefix = find_file( name )) ) { #ifdef DEBUG printf( "vips_guess_prefix: found \"%s\" from " "PATH\n", prefix ); #endif /*DEBUG*/ return( prefix ); } } #ifdef HAVE_REALPATH /* Try to guess from cwd. Only if this is a relative path, though. No * realpath on winders, but fortunately it seems to always generate * a full path in argv[0]. */ if( !g_path_is_absolute( argv0 ) ) { char full_path[PATH_MAX]; char resolved[PATH_MAX]; vips_snprintf( full_path, PATH_MAX, "%s" G_DIR_SEPARATOR_S "%s", get_current_dir(), argv0 ); if( realpath( full_path, resolved ) ) { if( (prefix = extract_prefix( resolved, name )) ) { #ifdef DEBUG printf( "vips_guess_prefix: found \"%s\" " "from cwd\n", prefix ); #endif /*DEBUG*/ return( prefix ); } } } #endif /*HAVE_REALPATH*/ /* Fall back to the configure-time prefix. */ return( VIPS_PREFIX ); }
/* Search a path for a file ... we overwrite the PATH string passed in. */ static char * scan_path( char *path, const char *name ) { char *p, *q; char *prefix; for( p = path; (q = vips_break_token( p, G_SEARCHPATH_SEPARATOR_S )); p = q ) { char str[PATH_MAX]; /* Form complete path. */ vips_snprintf( str, PATH_MAX, "%s" G_DIR_SEPARATOR_S "%s", p, name ); #ifdef DEBUG printf( "scan_path: looking in \"%s\" for \"%s\"\n", p, name ); #endif /*DEBUG*/ if( vips_existsf( "%s", str ) && (prefix = extract_prefix( str, name )) ) { return( prefix ); } } return( NULL ); }
void dns_dampening_score_qtype(dns_dampening_t * damp, const isc_sockaddr_t * addr, isc_stdtime_t now, dns_messageid_t message_id, int qtype) { isc_netaddr_t netaddr, prefix; dns_dampening_entry_t * entry; uint16_t points; dns_dampening_implementation_t *impl; RUNTIME_CHECK( damp != NULL ); RUNTIME_CHECK( addr != NULL ); isc_netaddr_fromsockaddr(&netaddr, addr); extract_prefix(&prefix, &netaddr, &(damp->prefixlen)); for(impl = damp->workers; impl - damp->workers < damp->workers_count; impl++) { if(damp->exempt != NULL) { int match; if (ISC_R_SUCCESS == dns_acl_match(&netaddr, NULL, damp->exempt, NULL, &match, NULL) && match > 0) { DAMPENING_STATISTICS_INC(impl,skipped); continue; } } DAMPENING_STATISTICS_DO(impl, lock, LOCK(&impl->lock)); DAMPENING_STATISTICS_DO(impl, search, entry = impl->search(impl->data, &prefix)); if(entry != NULL) { switch(qtype) { case dns_rdatatype_any: points = damp->score.qtype_any; break; default : points = 0; break; } if(entry->last_id == message_id) { points += (entry->last_id_count++)*damp->score.duplicates; } else { entry->last_id = message_id; entry->last_id_count = 1; } DAMPENING_STATISTICS_DO(impl, update, impl->update(impl->data, &entry, points, now)); } UNLOCK(&impl->lock); } }
static int determine_matches(const char *image, char **l, bool allow_any, char ***ret) { _cleanup_strv_free_ char **k = NULL; int r; /* Determine the matches to apply. If the list is empty we derive the match from the image name. If the list * contains exactly the "-" we return a wildcard list (which is the empty list), but only if this is expressly * permitted. */ if (strv_isempty(l)) { char *prefix; r = extract_prefix(image, &prefix); if (r < 0) return log_error_errno(r, "Failed to extract prefix of image name '%s': %m", image); if (!arg_quiet) log_info("(Matching unit files with prefix '%s'.)", prefix); r = strv_consume(&k, prefix); if (r < 0) return log_oom(); } else if (strv_equal(l, STRV_MAKE("-"))) { if (!allow_any) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Refusing all unit file match."); if (!arg_quiet) log_info("(Matching all unit files.)"); } else { k = strv_copy(l); if (!k) return log_oom(); if (!arg_quiet) { _cleanup_free_ char *joined = NULL; joined = strv_join(k, "', '"); if (!joined) return log_oom(); log_info("(Matching unit files with prefixes '%s'.)", joined); } } *ret = TAKE_PTR(k); return 0; }
static char *dol_lookup(void *data, const char *path) { lup *lu = data; // some shortcuts if (strcmp(path, "nid") == 0) return fdja_ls(lu->node, "nid"); if (strcmp(path, "exid") == 0) return strdup(execution_id); if (strcmp(path, "exnid") == 0 || strcmp(path, "enid") == 0) { char *nid = fdja_ls(lu->node, "nid"); char *r = flu_sprintf("%s-%s", execution_id, nid); free(nid); return r; } if (strcmp(path, "domain") == 0) return flon_execution_domain(); if (strncmp(path, "domain", 5) == 0 && (path[6] == '-' || path[6] == '+')) return flon_execution_domain_delta(strtol(path + 6, NULL, 10)); // regular case, var or fld char k = extract_prefix(path); char *pth = (char *)path; fdja_value *v = NULL; if (k != 0) pth = strchr(path, '.') + 1; if (k == 'v') v = lookup_var(lu->node, *path, pth); else if (k == 'w') v = lookup_war(lu->node, pth); else v = fdja_l(payload(lu->msg), pth); if (v == NULL) return strdup(""); if (v->type == 's' || v->type == 'q' || v->type == 'y') return fdja_to_string(v); return fdja_tod(v); }
void dns_dampening_score_size(dns_dampening_t * damp, const isc_sockaddr_t * addr, isc_stdtime_t now, int length) { isc_netaddr_t netaddr, prefix; dns_dampening_entry_t * entry; uint16_t points; dns_dampening_implementation_t *impl; RUNTIME_CHECK( damp != NULL ); RUNTIME_CHECK( addr != NULL ); isc_netaddr_fromsockaddr(&netaddr, addr); extract_prefix(&prefix, &netaddr, &(damp->prefixlen)); for(impl = damp->workers; impl - damp->workers < damp->workers_count; impl++) { if(damp->exempt != NULL) { int match; if (ISC_R_SUCCESS == dns_acl_match(&netaddr, NULL, damp->exempt, NULL, &match, NULL) && match > 0) { DAMPENING_STATISTICS_INC(impl,skipped); continue; } } DAMPENING_STATISTICS_DO(impl, lock, LOCK(&impl->lock)); DAMPENING_STATISTICS_DO(impl, search, entry = impl->search(impl->data, &prefix)); if(entry != NULL) { length = ISC_MAX(length, damp->score.minimum_size); length = ISC_MIN(length, damp->score.maximum_size); points = damp->score.size_penalty * (length - damp->score.minimum_size) / (damp->score.maximum_size - damp->score.minimum_size); DAMPENING_STATISTICS_DO(impl, update, impl->update(impl->data, &entry, points, now)); } UNLOCK(&impl->lock); } }
history_item_t history_t::decode_item(const char *base, size_t len) { wcstring cmd; time_t when = 0; path_list_t paths; size_t indent = 0, cursor = 0; std::string key, value, line; /* Read the "- cmd:" line */ size_t advance = read_line(base, cursor, len, line); trim_leading_spaces(line); if (! extract_prefix(key, value, line) || key != "- cmd") goto done; cursor += advance; cmd = str2wcstring(value); /* Read the remaining lines */ for (;;) { /* Read a line */ size_t advance = read_line(base, cursor, len, line); /* Count and trim leading spaces */ size_t this_indent = trim_leading_spaces(line); if (indent == 0) indent = this_indent; if (this_indent == 0 || indent != this_indent) break; if (! extract_prefix(key, value, line)) break; /* We are definitely going to consume this line */ unescape_yaml(value); cursor += advance; if (key == "when") { /* Parse an int from the timestamp */ long tmp = 0; if (sscanf(value.c_str(), "%ld", &tmp) > 0) { when = tmp; } } else if (key == "paths") { /* Read lines starting with " - " until we can't read any more */ for (;;) { size_t advance = read_line(base, cursor, len, line); if (trim_leading_spaces(line) <= indent) break; if (strncmp(line.c_str(), "- ", 2)) break; /* We're going to consume this line */ cursor += advance; /* Skip the leading dash-space and then store this path it */ line.erase(0, 2); unescape_yaml(line); paths.push_front(str2wcstring(line)); } } } /* Reverse the paths, since we pushed them to the front each time */ done: paths.reverse(); return history_item_t(cmd, when, paths); }
void OSOReaderToMaster::hint (string_view hintstring) { std::string h (hintstring); // FIXME -- use string_view ops here if (extract_prefix (h, "%filename{\"")) { m_sourcefile = readuntil (h, "\""); return; } if (extract_prefix (h, "%line{")) { m_sourceline = atoi (h.c_str()); return; } if (extract_prefix (h, "%structfields{")) { ASSERT (m_master->m_symbols.size() && "structfields hint but no sym"); Symbol &sym (m_master->m_symbols.back()); StructSpec *structspec = sym.typespec().structspec(); if (structspec->numfields() == 0) { while (1) { std::string afield = readuntil (h, ",}", true); if (! afield.length()) break; // std::cerr << " struct field " << afield << "\n"; structspec->add_field (TypeSpec(), ustring(afield)); } } return; } if (extract_prefix (h, "%mystructfield{")) { ASSERT (m_master->m_symbols.size() && "mystructfield hint but no sym"); Symbol &sym (m_master->m_symbols.back()); sym.fieldid (atoi(h.c_str()+15)); return; } if (extract_prefix (h, "%read{")) { ASSERT (m_master->m_symbols.size() && "read hint but no sym"); Symbol &sym (m_master->m_symbols.back()); int first, last; sscanf (h.c_str(), "%d,%d", &first, &last); sym.set_read (first, last); return; } if (extract_prefix (h, "%write{")) { ASSERT (m_master->m_symbols.size() && "write hint but no sym"); Symbol &sym (m_master->m_symbols.back()); int first, last; sscanf (h.c_str(), "%d,%d", &first, &last); sym.set_write (first, last); return; } if (extract_prefix(h, "%argrw{")) { const char* str = h.c_str(); ASSERT(*str == '\"'); str++; // skip open quote size_t i = 0; for (; *str != '\"'; i++, str++) { ASSERT(*str == 'r' || *str == 'w' || *str == 'W' || *str == '-'); m_master->m_ops.back().argwrite(i, *str == 'w' || *str =='W'); m_master->m_ops.back().argread(i, *str == 'r' || *str =='W'); } ASSERT(m_nargs == i); // Fix old bug where oslc forgot to mark getmatrix last arg as write static ustring getmatrix("getmatrix"); if (m_master->m_ops.back().opname() == getmatrix) m_master->m_ops.back().argwrite(m_nargs-1, true); } if (extract_prefix(h, "%argderivs{")) { while (1) { std::string afield = readuntil (h, ",}", true); if (! afield.length()) break; int arg = atoi (afield.c_str()); if (arg >= 0) m_master->m_ops.back().argtakesderivs (arg, true); } } if (extract_prefix (h, "%meta{") && m_master->m_symbols.size()) { Symbol &sym (m_master->m_symbols.back()); int lockval = -1; int ok = sscanf (h.c_str(), " int , lockgeom , %d", &lockval); if (ok) sym.lockgeom (lockval); } }
dns_dampening_state_t dns_dampening_query(dns_dampening_t * damp, const isc_sockaddr_t * addr, isc_stdtime_t now, int * penalty) { isc_netaddr_t netaddr, prefix; dns_dampening_state_t final_state = DNS_DAMPENING_STATE_NORMAL, state = DNS_DAMPENING_STATE_NORMAL; dns_dampening_entry_t * entry; dns_dampening_implementation_t *impl; int max_penalty = -2; RUNTIME_CHECK( damp != NULL ); RUNTIME_CHECK( addr != NULL ); isc_netaddr_fromsockaddr(&netaddr, addr); extract_prefix(&prefix, &netaddr, &(damp->prefixlen)); for(impl = damp->workers; impl - damp->workers < damp->workers_count; impl++) { if(damp->exempt != NULL) { int match; if (ISC_R_SUCCESS == dns_acl_match(&netaddr, NULL, damp->exempt, NULL, &match, NULL) && match > 0) { max_penalty = ISC_MAX(max_penalty, -1); DAMPENING_STATISTICS_INC(impl,skipped); continue; } } DAMPENING_STATISTICS_DO(impl, lock, LOCK(&impl->lock)); if(damp->statistics.report_interval > 0 && damp->statistics.report_interval + impl->statistics.last_report <= now) { if(isc_log_wouldlog(dns_lctx, ISC_LOG_INFO)) isc_log_write(dns_lctx, DNS_LOGCATEGORY_DAMPENING, DNS_LOGMODULE_REQUEST, ISC_LOG_INFO, "Stats for #%d: queries %u/%u/%u: lock=%ld.%06ld, search=%ld.%06ld, update=%ld.%06ld, add=%ld.%06ld", impl - damp->workers, impl->statistics.allowed, impl->statistics.denied, impl->statistics.skipped, impl->statistics.lock.tv_sec, impl->statistics.lock.tv_usec, impl->statistics.search.tv_sec, impl->statistics.search.tv_usec, impl->statistics.update.tv_sec, impl->statistics.update.tv_usec, impl->statistics.add.tv_sec, impl->statistics.add.tv_usec); memset(&impl->statistics, 0, sizeof(impl->statistics)); impl->statistics.last_report = now; } DAMPENING_STATISTICS_DO(impl, search, entry = impl->search(impl->data, &prefix)); if(entry == NULL) { state = DNS_DAMPENING_STATE_NORMAL; DAMPENING_STATISTICS_DO(impl, add, impl->add(impl->data, &prefix, damp->score.first_query, now)); max_penalty = ISC_MAX(max_penalty, 0); } else { state = entry->dampening == 1 ? DNS_DAMPENING_STATE_SUPPRESS : DNS_DAMPENING_STATE_NORMAL; max_penalty = ISC_MAX(max_penalty, entry->penalty); DAMPENING_STATISTICS_DO(impl, update, impl->update(impl->data, &entry, damp->score.per_query, now)); } if(state == DNS_DAMPENING_STATE_NORMAL) { DAMPENING_STATISTICS_INC(impl, allowed); } else { DAMPENING_STATISTICS_INC(impl, denied); final_state = state; /* any dampening suffice */ } UNLOCK(&impl->lock); } if(penalty != NULL) *penalty = max_penalty; return final_state; }