SCJson print_all(CONF_VALUE **value) { SCJson result = nullptr; VLog("all:\n"); // 遍历 for (size_t i = 0; value[i] != NULL; ++i) { VLog("key:%s ", value[i]->key); if (nullptr == result) { result = BaseJson::createObject(); } auto name = value[i]->key; result->addStringForKey(name, ""); size_t j = 0; while (value[i]->value[j] != NULL) { VLog(" value:%s", value[i]->value[j]); auto string = value[i]->value[j]; result->setStringForKey(name, string); ++j; } VLog("\n"); } result->print(1, 1); return result; }
void Log(LogLevel level, const char *fmt, ...) { va_list ap; va_start(ap, fmt); VLog(level, fmt, ap); va_end(ap); }
void Trace::Error(const char *fmt, ...) { va_list args; va_start(args,fmt); VLog("*ERROR*",fmt, args); va_end(args); }
void Trace::Log(const char* category, const char *fmt, ...) { va_list args; va_start(args,fmt); VLog(category, fmt, args); va_end(args); }
void CfOut(OutputLevel level, const char *errstr, const char *fmt, ...) { va_list ap; va_start(ap, fmt); VLog(level, errstr, fmt, ap); va_end(ap); }
void CfOut(enum cfreport level, const char *errstr, const char *fmt, ...) { va_list ap; va_start(ap, fmt); VLog(stdout, level, errstr, fmt, ap); va_end(ap); }
void Trace::Debug(const char *fmt, ...) { #ifndef NDEBUG va_list args; va_start(args,fmt); VLog("-D-",fmt, args); va_end(args); #endif }
static void * CheckSignal(void *unused) { int i, errorcode; struct vl_ctx ctx; if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE))) return (void *)(intptr_t)errorcode; VLog(0, ("Dump name hash table out\n")); for (i = 0; i < HASHSIZE; i++) { HashNDump(&ctx, i); } VLog(0, ("Dump id hash table out\n")); for (i = 0; i < HASHSIZE; i++) { HashIdDump(&ctx, i); } return ((void *)(intptr_t)ubik_EndTrans(ctx.trans)); } /*CheckSignal */
static void * CheckSignal(void *unused) { register int i, errorcode; struct ubik_trans *trans; if (errorcode = Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)) return (void *)errorcode; VLog(0, ("Dump name hash table out\n")); for (i = 0; i < HASHSIZE; i++) { HashNDump(trans, i); } VLog(0, ("Dump id hash table out\n")); for (i = 0; i < HASHSIZE; i++) { HashIdDump(trans, i); } return ((void *)ubik_EndTrans(trans)); } /*CheckSignal */
/** * Receives the data at the specified @c url. * * @return true upon success, false upon failure. * @todo Better error handling per https://b33p.net/kosada/node/4724 */ bool VuoUrl_fetch(const char *url, void **data, unsigned int *dataLength) { struct VuoUrl_curlBuffer buffer = {NULL, 0}; CURL *curl; CURLcode res; curl = curl_easy_init(); if (!curl) { VLog("Error: cURL initialization failed."); return false; } curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // Don't use signals for the timeout logic, since they're not thread-safe. VuoText resolvedUrl = VuoUrl_normalize(url, true); VuoRetain(resolvedUrl); curl_easy_setopt(curl, CURLOPT_URL, resolvedUrl); VuoRelease(resolvedUrl); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, VuoUrl_curlCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&buffer); res = curl_easy_perform(curl); if(res != CURLE_OK) { if (res == CURLE_FILE_COULDNT_READ_FILE) VLog("Error: Could not read path: \"%s\"", resolvedUrl); else VLog("Error: cURL request failed: %s (%d)\n", curl_easy_strerror(res), res); return false; } curl_easy_cleanup(curl); *data = buffer.memory; *dataLength = buffer.size; return true; }
void CLogging::Log( const LogType type, const DevLevel::DevLevel devLevel, const char* const pszFormat, ... ) { assert( pszFormat != nullptr && *pszFormat ); va_list list; va_start( list, pszFormat ); VLog( type, devLevel, pszFormat, list ); va_end( list ); }
/** * Return true if this name is a member of the local realm. */ int vldb_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell) { struct afsconf_dir *dir = (struct afsconf_dir *)rock; afs_int32 islocal = 0; /* default to no */ int code; code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell); if (code) { VLog(0, ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n", code, name, inst, cell)); } return islocal; }
void cfPS(EvalContext *ctx, LogLevel level, PromiseResult status, const Promise *pp, Attributes attr, const char *fmt, ...) { /* * This stub implementation of cfPS delegates to the new logging backend. * * Due to the fact very little of the code has been converted, this code * does a full initialization and shutdown of logging subsystem for each * cfPS. * * Instead, LoggingInit should be called at the moment EvalContext is * created, LoggingPromiseEnter/LoggingPromiseFinish should be called around * ExpandPromise and LoggingFinish should be called when EvalContext is * going to be destroyed. * * But it requires all calls to cfPS to be eliminated. */ /* FIXME: Ensure that NULL pp is never passed into cfPS */ if (pp) { PromiseLoggingInit(ctx); PromiseLoggingPromiseEnter(ctx, pp); if (level == LOG_LEVEL_ERR) { LogPromiseContext(ctx, pp); } } va_list ap; va_start(ap, fmt); VLog(level, fmt, ap); va_end(ap); if (pp) { char *last_msg = PromiseLoggingPromiseFinish(ctx, pp); PromiseLoggingFinish(ctx); /* Now complete the exits status classes and auditing */ ClassAuditLog(ctx, pp, attr, status); UpdatePromiseComplianceStatus(status, pp, last_msg); free(last_msg); } }
void LogDebug(enum LogModule mod, const char *fmt, ...) { assert(mod < LOG_MOD_MAX); /* Did we forget any entry in log_modules? Should be a static assert. */ assert(sizeof(log_modules) / sizeof(log_modules[0]) == LOG_MOD_MAX); if (LogModuleEnabled(mod)) { va_list ap; va_start(ap, fmt); VLog(LOG_LEVEL_DEBUG, fmt, ap); va_end(ap); /* VLog(LOG_LEVEL_DEBUG, "%s: ...", */ /* debug_modules_description[mod_order], ...); */ } }
/** * Reads the contents of the URL into a memory buffer. * A callback function for use by @c curl_easy_setopt(). */ static size_t VuoUrl_curlCallback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; struct VuoUrl_curlBuffer *mem = (struct VuoUrl_curlBuffer *)userp; mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); if(mem->memory == NULL) { VLog("Error: realloc() returned NULL (out of memory?)."); return 0; } memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = 0; return realsize; }
static void playNextAudioFrame(struct nodeInstanceData *context, VuoOutputTrigger(decodedAudio, VuoList_VuoAudioSamples)) { if(context->lastAudioSamples) { // Send Audio if(VuoListGetCount_VuoAudioSamples(context->lastAudioSamples) > 0) { VuoAudioSamples as = VuoListGetValueAtIndex_VuoAudioSamples(context->lastAudioSamples, 1); decodedAudio(context->lastAudioSamples); } VuoRelease(context->lastAudioSamples); context->lastAudioSamples = NULL; } uint64_t cur_time = dispatch_time(DISPATCH_TIME_NOW, 0); if(!context->movie) return; context->lastAudioSamples = VuoListCreate_VuoAudioSamples(); double frameTimestampInSecs = 0; bool gotFrame = VuoMovie_getNextAudioSample(context->movie, context->lastAudioSamples, &frameTimestampInSecs); if(gotFrame) { VuoRetain(context->lastAudioSamples); context->lastAudioTimestamp = frameTimestampInSecs; } else { VLog("bad"); if(context->lastAudioSamples) VuoRelease(context->lastAudioSamples); context->lastAudioSamples = NULL; } uint64_t presentationTime = (cur_time + NSEC_PER_SEC * AUDIO_SEC_PER_SAMPLE - 100000); dispatch_source_set_timer(context->audio_timer, presentationTime, DISPATCH_TIME_FOREVER, NSEC_PER_SEC / 100000 ); }
void CfFOut(char *filename, OutputLevel level, char *errstr, char *fmt, ...) { FILE *fp = fopen(filename, "a"); if (fp == NULL) { CfOut(OUTPUT_LEVEL_ERROR, "fopen", "Could not open log file %s\n", filename); fp = stdout; } va_list ap; va_start(ap, fmt); VLog(fp, level, errstr, fmt, ap); va_end(ap); if (fp != stdout) { fclose(fp); } }
void CfFOut(char *filename, enum cfreport level, char *errstr, char *fmt, ...) { FILE *fp = fopen(filename, "a"); if (fp == NULL) { CfOut(cf_error, "fopen", "Could not open log file %s\n", filename); fp = stdout; } va_list ap; va_start(ap, fmt); VLog(fp, level, errstr, fmt, ap); va_end(ap); if (fp != stdout) { fclose(fp); } }
void CfVOut(OutputLevel level, const char *errstr, const char *fmt, va_list ap) { VLog(stdout, level, errstr, fmt, ap); }
void CLogging::VLog( const LogType type, const char* const pszFormat, va_list list ) { return VLog( type, DevLevel::ALWAYS, pszFormat, list ); }
void Logger::Log(const std::string& message, const LogLevel& logLevel) { if (!m_initialized) Initialize(); VLog(message, logLevel); }
int main(int argc, char **argv) { afs_int32 code; afs_uint32 myHost; struct rx_service *tservice; struct rx_securityClass **securityClasses; afs_int32 numClasses; struct afsconf_dir *tdir; struct ktc_encryptionKey tkey; struct afsconf_cell info; struct hostent *th; char hostname[VL_MAXNAMELEN]; int noAuth = 0; char clones[MAXHOSTSPERCELL]; afs_uint32 host = ntohl(INADDR_ANY); struct cmd_syndesc *opts; char *vl_dbaseName; char *configDir; char *logFile; char *auditFileName = NULL; char *interface = NULL; char *optstring = NULL; #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; rx_extraPackets = 100; /* should be a switch, I guess... */ sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGABRT, &nsa, NULL); sigaction(SIGSEGV, &nsa, NULL); #endif osi_audit_init(); /* Initialize dirpaths */ if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) { #ifdef AFS_NT40_ENV ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0); #endif fprintf(stderr, "%s: Unable to obtain AFS server directory.\n", argv[0]); exit(2); } vl_dbaseName = strdup(AFSDIR_SERVER_VLDB_FILEPATH); configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH); logFile = strdup(AFSDIR_SERVER_VLOG_FILEPATH); cmd_DisableAbbreviations(); cmd_DisablePositionalCommands(); opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL); /* vlserver specific options */ cmd_AddParmAtOffset(opts, OPT_noauth, "-noauth", CMD_FLAG, CMD_OPTIONAL, "disable authentication"); cmd_AddParmAtOffset(opts, OPT_smallmem, "-smallmem", CMD_FLAG, CMD_OPTIONAL, "optimise for small memory systems"); /* general server options */ cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE, CMD_OPTIONAL, "location of audit log"); cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE, CMD_OPTIONAL, "interface to use for audit logging"); cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE, CMD_OPTIONAL, "configuration location"); cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL, "debug level"); cmd_AddParmAtOffset(opts, OPT_database, "-database", CMD_SINGLE, CMD_OPTIONAL, "database file"); cmd_AddParmAlias(opts, OPT_database, "-db"); cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE, CMD_OPTIONAL, "location of logfile"); cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL, "number of threads"); #if !defined(AFS_NT40_ENV) cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG, CMD_OPTIONAL, "log to syslog"); #endif /* rx options */ cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL, "enable RX transport statistics"); cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG, CMD_OPTIONAL, "enable RX RPC statistics"); cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG, CMD_OPTIONAL, "disable jumbograms"); cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL, "enable jumbograms"); cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL, "bind only to the primary interface"); cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE, CMD_OPTIONAL, "maximum MTU for RX"); cmd_AddParmAtOffset(opts, OPT_trace, "-trace", CMD_SINGLE, CMD_OPTIONAL, "rx trace file"); /* rxkad options */ cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG, CMD_OPTIONAL, "permit Kerberos 5 principals with dots"); code = cmd_Parse(argc, argv, &opts); if (code) return -1; cmd_OptionAsString(opts, OPT_config, &configDir); cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH); cmd_SetCommandName("vlserver"); /* vlserver options */ cmd_OptionAsFlag(opts, OPT_noauth, &noAuth); cmd_OptionAsFlag(opts, OPT_smallmem, &smallMem); if (cmd_OptionAsString(opts, OPT_trace, &optstring) == 0) { extern char rxi_tracename[80]; strcpy(rxi_tracename, optstring); free(optstring); optstring = NULL; } /* general server options */ cmd_OptionAsString(opts, OPT_auditlog, &auditFileName); if (cmd_OptionAsString(opts, OPT_auditiface, &interface) == 0) { if (osi_audit_interface(interface)) { printf("Invalid audit interface '%s'\n", interface); return -1; } free(interface); } cmd_OptionAsInt(opts, OPT_debug, &LogLevel); cmd_OptionAsString(opts, OPT_database, &vl_dbaseName); cmd_OptionAsString(opts, OPT_logfile, &logFile); if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) { if (lwps > MAXLWP) { printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP); lwps = MAXLWP; } } #ifndef AFS_NT40_ENV if (cmd_OptionPresent(opts, OPT_syslog)) { serverLogSyslog = 1; cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility); } #endif /* rx options */ if (cmd_OptionPresent(opts, OPT_peer)) rx_enablePeerRPCStats(); if (cmd_OptionPresent(opts, OPT_process)) rx_enableProcessRPCStats(); if (cmd_OptionPresent(opts, OPT_nojumbo)) rxJumbograms = 0; if (cmd_OptionPresent(opts, OPT_jumbo)) rxJumbograms = 1; cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind); cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU); /* rxkad options */ cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck); if (auditFileName) { osi_audit_file(auditFileName); } #ifndef AFS_NT40_ENV serverLogSyslogTag = "vlserver"; #endif OpenLog(logFile); /* set up logging */ SetupLogSignals(); tdir = afsconf_Open(configDir); if (!tdir) { VLog(0, ("vlserver: can't open configuration files in dir %s, giving up.\n", configDir)); exit(1); } /* initialize audit user check */ osi_audit_set_user_check(tdir, vldb_IsLocalRealmMatch); #ifdef AFS_NT40_ENV /* initialize winsock */ if (afs_winsockInit() < 0) { ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0); VLog(0, ("vlserver: couldn't initialize winsock. \n")); exit(1); } #endif /* get this host */ gethostname(hostname, sizeof(hostname)); th = gethostbyname(hostname); if (!th) { VLog(0, ("vlserver: couldn't get address of this host (%s).\n", hostname)); exit(1); } memcpy(&myHost, th->h_addr, sizeof(afs_uint32)); #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV) signal(SIGXCPU, CheckSignal_Signal); #endif /* get list of servers */ code = afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info, clones); if (code) { printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n"); exit(2); } vldb_confdir = tdir; /* Preserve our configuration dir */ /* rxvab no longer supported */ memset(&tkey, 0, sizeof(tkey)); if (noAuth) afsconf_SetNoAuthFlag(tdir, 1); if (rxBind) { afs_int32 ccode; #ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL, ADDRSPERSITE, reason, AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else #endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } if (ccode == 1) { host = SHostAddrs[0]; rx_InitHost(host, htons(AFSCONF_VLDBPORT)); } } if (!rxJumbograms) { rx_SetNoJumbo(); } if (rxMaxMTU != -1) { if (rx_SetMaxMTU(rxMaxMTU) != 0) { VLog(0, ("rxMaxMTU %d invalid\n", rxMaxMTU)); return -1; } } ubik_nBuffers = 512; ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir); ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects, afsconf_CheckAuth, tdir); ubik_SyncWriterCacheProc = vlsynccache; code = ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones, vl_dbaseName, &VL_dbase); if (code) { VLog(0, ("vlserver: Ubik init failed: %s\n", afs_error_message(code))); exit(2); } rx_SetRxDeadTime(50); memset(rd_HostAddress, 0, sizeof(rd_HostAddress)); memset(wr_HostAddress, 0, sizeof(wr_HostAddress)); initialize_dstats(); afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses); tservice = rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", securityClasses, numClasses, VL_ExecuteRequest); if (tservice == (struct rx_service *)0) { VLog(0, ("vlserver: Could not create VLDB_SERVICE rx service\n")); exit(3); } rx_SetMinProcs(tservice, 2); if (lwps < 4) lwps = 4; rx_SetMaxProcs(tservice, lwps); if (rxkadDisableDotCheck) { rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS, (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK); } tservice = rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses, numClasses, RXSTATS_ExecuteRequest); if (tservice == (struct rx_service *)0) { VLog(0, ("vlserver: Could not create rpc stats rx service\n")); exit(3); } rx_SetMinProcs(tservice, 2); rx_SetMaxProcs(tservice, 4); LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog); VLog(0, ("%s\n", cml_version_number)); /* allow super users to manage RX statistics */ rx_SetRxStatUserOk(vldb_rxstat_userok); rx_StartServer(1); /* Why waste this idle process?? */ return 0; /* not reachable */ }