std::string SzbaseWrapper::search_data( const std::string& param , const std::string& from , const std::string& to , TimeType time_type , SearchDir dir , ProbeType pt ) const throw( szbase_init_error, szbase_param_not_found_error, szbase_error ) { if( !SzbaseWrapper::is_initialized() ) throw szbase_init_error("Szbase not initialized"); TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) ); if( !tparam ) throw szbase_param_not_found_error( "Param " + param + ", does not exist." ); std::string result; switch (time_type) { case TimeType::NANOSECOND: result = search_data_helper<sz4::nanosecond_time_t>( base , tparam , from , to , dir , pt ); break; case TimeType::SECOND: result = search_data_helper<sz4::second_time_t> ( base , tparam , from , to , dir , pt ); break; } purge_cache(); return result; }
int main(int argc, char** argv) { if (argc < 2) { cc::errln("Error: too few arguments."); return EXIT_FAILURE; } else if (argc > 2) { cc::errln("Error: too many arguments."); return EXIT_FAILURE; } auto path = argv[1]; auto fd = safe_open(path, O_RDONLY).get(); auto fs = file_size(fd).get(); safe_close(fd).get(); auto count = check(path); auto sizes = {4, 8, 12, 16, 24, 32, 40, 48, 56, 64, 256, 1024, 4096, 16384, 65536, 262144}; purge_cache().get(); print_header(); test_read_range(read_plain, path, "read_plain", sizes, fs, count); test_read_range(read_direct, path, "read_direct", sizes, fs, count); test_read_range(read_fadvise, path, "read_fadvise", sizes, fs, count); test_read_range(aio_read_direct, path, "aio_read_direct", sizes, fs, count); test_read_range(aio_read_fadvise, path, "aio_read_fadvise", sizes, fs, count); test_read_range(read_async_plain, path, "read_async_plain", sizes, fs, count); test_read_range(read_async_direct, path, "read_async_direct", sizes, fs, count); test_read_range(read_async_fadvise, path, "read_async_fadvise", sizes, fs, count); test_read(std::bind(read_mmap_plain, path), "mmap_plain", count, fs); test_read(std::bind(read_mmap_direct, path), "mmap_direct", count, fs); test_read(std::bind(read_mmap_fadvise, path), "mmap_fadvise", count, fs); }
double SzbaseWrapper::get_avg( const std::string& param , time_t time , ProbeType type ) const throw( szbase_init_error, szbase_get_value_error ) { if( !SzbaseWrapper::is_initialized() ) throw szbase_init_error("Szbase not initialized"); TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) ); if( !tparam ) throw szbase_get_value_error( "Cannot get value from param " + param + ", param not found" ); sz4::weighted_sum<double, unsigned> sum; try { base->get_weighted_sum( tparam , unsigned( time ) , unsigned( next( time , type , 1 ) ) , type.get_szarp_pt() , sum ); } catch( sz4::exception& e ) { throw szbase_get_value_error( "Cannot get value from param " + param + ": " + e.what() ); } purge_cache(); return sz4::scale_value(sum.avg(), tparam); }
time_t SzbaseWrapper::get_latest( const std::string& param , ProbeType type ) const throw( szbase_init_error, szbase_get_value_error ) { if( !SzbaseWrapper::is_initialized() ) throw szbase_init_error("Szbase not initialized"); TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) ); if( !tparam ) throw szbase_get_value_error( "Cannot get latest time of param " + param + ", param not found" ); unsigned t; try { base->get_last_time( tparam, t ); } catch( sz4::exception& e) { throw szbase_get_value_error( "Cannot get latest time of param " + param + ": " + e.what() ); } purge_cache(); /** * Round by hand because search returns probes rounded to * either 10min or 10sec, not to exact pt */ return t == unsigned( -1 ) ? -1 : round( t , type ); }
void game_cache_options::purge_cache_callback() { if(purge_cache()) { show_message( _("Cache Purged"), _("The game data cache has been purged.")); } else { show_error_message(_("The game data cache could not be purged.")); } update_cache_size_display(); }
std::string SzbaseWrapper::get_data( const std::string& param , const std::string& from , const std::string& to , ValueType value_type , TimeType time_type , ProbeType pt ) const throw( szbase_init_error, szbase_param_not_found_error, szbase_error ) { if( !SzbaseWrapper::is_initialized() ) throw szbase_init_error("Szbase not initialized"); std::ostringstream ss; TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) ); if( !tparam ) throw szbase_param_not_found_error( "Param " + param + ", does not exist." ); try{ switch (time_type) { case TimeType::NANOSECOND: ::get_data<sz4::nanosecond_time_t>( base , tparam , from , to , value_type , pt.get_szarp_pt() , ss ); break; case TimeType::SECOND: ::get_data<sz4::second_time_t> ( base , tparam , from , to , value_type , pt.get_szarp_pt() , ss ); break; } } catch ( sz4::exception& e ) { throw szbase_error( "Cannot get data for param " + param + ": " + e.what() ); } purge_cache(); return ss.str(); }
/* Open LDAP and Notifier connection. * @return 0 on success, 1 on error. */ static int do_connection(univention_ldap_parameters_t *lp) { LDAPMessage *res; int rc; struct timeval timeout = { .tv_sec = 10, .tv_usec = 0, }; if (univention_ldap_open(lp) != LDAP_SUCCESS) goto fail; if (notifier_client_new(NULL, lp->host, 1) != 0) goto fail; /* check if we are connected to an OpenLDAP */ rc = ldap_search_ext_s(lp->ld, lp->base, LDAP_SCOPE_BASE, "objectClass=univentionBase", NULL, 0, NULL, NULL, &timeout, 0, &res); ldap_msgfree(res); switch (rc) { case LDAP_SUCCESS: return 0; case LDAP_NO_SUCH_OBJECT: univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Failed to find \"(objectClass=univentionBase)\" on LDAP server %s:%d", lp->host, lp->port); break; default: univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Failed to search for \"(objectClass=univentionBase)\" on LDAP server %s:%d with message %s", lp->host, lp->port, ldap_err2string(rc)); break; } fail: notifier_client_destroy(NULL); if (lp->ld) ldap_unbind_ext(lp->ld, NULL, NULL); lp->ld = NULL; return 1; } int main(int argc, char* argv[]) { univention_ldap_parameters_t *lp; univention_ldap_parameters_t *lp_local; char *server_role; #ifdef WITH_KRB5 univention_krb5_parameters_t *kp = NULL; bool do_kinit = false; #else void *kp = NULL ; #endif int debugging = 0; bool from_scratch = false; bool foreground = false; bool initialize_only = false; bool write_transaction_file = false; int rv; NotifierID id = -1; #ifndef WITH_DB42 NotifierID old_id = -1; #else CacheMasterEntry master_entry; #endif struct stat stbuf; char *f = NULL; univention_debug_init("stderr", 1, 1); if ((lp = univention_ldap_new()) == NULL) exit(1); lp->authmethod = LDAP_AUTH_SASL; if ((lp_local = univention_ldap_new()) == NULL) exit(1); #if WITH_KRB5 if ((kp=univention_krb5_new()) == NULL) exit(1); #endif /* parse arguments */ for (;;) { int c; c = getopt(argc, argv, "d:FH:h:p:b:D:w:y:xZY:U:R:Km:Bc:giol:"); if (c < 0) break; switch (c) { case 'd': debugging=atoi(optarg); break; case 'F': foreground = true; break; case 'H': lp->uri=strdup(optarg); break; case 'h': lp->host=strdup(optarg); break; case 'p': lp->port=atoi(optarg); break; case 'b': lp->base=strdup(optarg); break; case 'm': if ((module_dirs = realloc(module_dirs, (module_dir_count+2)*sizeof(char*))) == NULL) { return 1; } module_dirs[module_dir_count] = strdup(optarg); module_dirs[module_dir_count+1] = NULL; module_dir_count++; break; case 'c': cache_dir=strdup(optarg); break; case 'l': ldap_dir = strdup(optarg); if (asprintf(&transaction_file, "%s/listener/listener", ldap_dir) < 0) abort(); break; case 'D': lp->binddn=strdup(optarg); break; case 'w': lp->bindpw=strdup(optarg); #ifdef WITH_KRB5 kp->password=strdup(optarg); #endif /* remove password from process list */ memset(optarg, 'X', strlen(optarg)); break; case 'Z': lp->start_tls++; break; case 'x': lp->authmethod = LDAP_AUTH_SIMPLE; break; case 'y': lp->bindpw=read_pwd_from_file(optarg); #ifdef WITH_KRB5 kp->password=strdup(lp->bindpw); #endif break; case 'Y': lp->sasl_mech=strdup(optarg); break; case 'U': asprintf(&lp->sasl_authzid, "u:%s", optarg); /* kp->username=strdup(optarg); */ case 'R': lp->sasl_realm=strdup(optarg); #ifdef WITH_KRB5 kp->realm=strdup(optarg); #endif break; #ifdef WITH_KRB5 case 'K': do_kinit = true; break; #endif case 'g': from_scratch = true; break; case 'i': initialize_only = true; from_scratch = true; foreground = true; break; case 'o': write_transaction_file = true; break; case 'B': backup_notifier = 1; break; default: usage(); exit(1); } } if (asprintf(&f, "%s/bad_cache", cache_dir) < 0) abort(); if (stat(f, &stbuf) == 0) { exit(3); } free(f); univention_debug_set_level(UV_DEBUG_LISTENER, debugging); univention_debug_set_level(UV_DEBUG_LDAP, debugging); univention_debug_set_level(UV_DEBUG_KERBEROS, debugging); snprintf(pidfile, PATH_MAX, "%s/pid", cache_dir); signals_init(); if (!foreground && daemonize() != 0) exit(EXIT_FAILURE); drop_privileges(); if (from_scratch) purge_cache(cache_dir); prepare_cache(cache_dir); /* choose server to connect to */ if (lp->host == NULL && lp->uri == NULL) { select_server(lp); univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "no server given, choosing one by myself (%s)", lp->host); } #ifdef WITH_KRB5 if (!do_kinit) kp = NULL; if (kp != NULL && univention_krb5_init(kp) != 0) { univention_debug(UV_DEBUG_KERBEROS, UV_DEBUG_ERROR, "kinit failed"); exit(1); } #endif while (do_connection(lp) != 0) { univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "can not connect to ldap server %s:%d", lp->host, lp->port); if (suspend_connect()) { if (initialize_only) { univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "can not connect to any ldap server, exit"); exit(1); } univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "can not connect to any ldap server, retrying in 30 seconds"); sleep(30); } select_server(lp); univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "chosen server: %s:%d", lp->host, lp->port); } univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "connection okay to host %s:%d", lp->host, lp->port); /* connect to local LDAP server */ server_role = univention_config_get_string("server/role"); if ( server_role != NULL ) { if (!strcmp(server_role, "domaincontroller_backup") || !strcmp(server_role, "domaincontroller_slave")) { // if not master lp_local->host = strdup("localhost"); // or fqdn e.g. from univention_config_get_string("ldap/server/name"); lp_local->base = strdup(lp->base); lp_local->binddn = strdup(lp->binddn); lp_local->bindpw = strdup(lp->bindpw); } free(server_role); } /* XXX: we shouldn't block all signals for so long */ signals_block(); cache_init(); handlers_init(); /* pass data to handlers */ if (lp->base != NULL) handlers_set_data_all("basedn", lp->base); if (lp->binddn != NULL) handlers_set_data_all("binddn", lp->binddn); if (lp->bindpw != NULL) handlers_set_data_all("bindpw", lp->bindpw); if (lp->host != NULL) handlers_set_data_all("ldapserver", lp->host); convert_cookie(); if (notifier_get_id_s(NULL, &id) != 0) { univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to receive current ID"); return 1; } if (initialize_only) { INIT_ONLY=1; } /* update schema */ if ((rv=change_update_schema(lp)) != LDAP_SUCCESS) return rv; /* do initial import of entries */ if ((rv=change_new_modules(lp)) != LDAP_SUCCESS) { univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "change_new_modules: %s", ldap_err2string(rv)); return rv; } signals_unblock(); /* if no ID is set, assume the database has just been initialized */ #ifdef WITH_DB42 if ((rv=cache_get_master_entry(&master_entry)) == DB_NOTFOUND) { master_entry.id = id; if ((rv=cache_update_master_entry(&master_entry, NULL)) != 0) exit(1); } else if (rv != 0) exit(1); #else cache_get_int("notifier_id", &old_id, -1); if ((long)old_id == -1) { cache_set_int("notifier_id", id); } #endif if (!initialize_only) { rv = notifier_listen(lp, kp, write_transaction_file, lp_local); } if (rv != 0) univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "listener: %d", rv); univention_ldap_close(lp); univention_ldap_close(lp_local); exit_handler(0); }