void dyv_write( PFILE *f, const dyv *dv) { int size, i; size = dyv_size( dv); pfprintf( f, "%d\n", size); for (i=0; i<size; ++i) pfprintf( f, "%.16f\n", dyv_ref(dv,i)); return; }
int match_nl_table_cmd_to_type(FILE *fp, bool print, int valid, struct nlattr *tb[]) { unsigned int type, ifindex; int err; char iface[IFNAMSIZ]; struct nl_sock *fd = NULL; if (!tb[NET_MAT_IDENTIFIER_TYPE]) { MAT_LOG(ERR, "Warning: received rule msg without identifier type!\n"); return -EINVAL; } if (!tb[NET_MAT_IDENTIFIER]) { MAT_LOG(ERR, "Warning: received rule msg without identifier!\n"); return -EINVAL; } if (valid > 0 && !tb[valid]) { MAT_LOG(ERR, "Warning: received cmd without valid attribute expected %i\n", valid); return -ENOMSG; } if (nla_len(tb[NET_MAT_IDENTIFIER_TYPE]) < (int)sizeof(type)) { MAT_LOG(ERR, "Warning: invalid identifier type len\n"); return -EINVAL; } type = nla_get_u32(tb[NET_MAT_IDENTIFIER_TYPE]); switch (type) { case NET_MAT_IDENTIFIER_IFINDEX: fd = nl_socket_alloc(); err = nl_connect(fd, NETLINK_ROUTE); if (err < 0) { MAT_LOG(ERR,"Warning: Unable to connect socket\n"); break; } err = rtnl_link_alloc_cache(fd, AF_UNSPEC, &link_cache); if (err < 0) { MAT_LOG(ERR,"Warning: Unable to allocate cache\n"); break; } ifindex = nla_get_u32(tb[NET_MAT_IDENTIFIER]); rtnl_link_i2name(link_cache, (int)ifindex, iface, IFNAMSIZ); if (ifindex) pfprintf(fp, print, "%s (%u):\n", iface, ifindex); break; default: MAT_LOG(ERR, "Warning: unknown interface identifier type %i\n", type); break; } if (fd) { nl_close(fd); nl_socket_free(fd); } return 0; }
/** * Conditionally PLogs a message. The message is logged only if module is enabled. * * @param msg The message format specification (ala printf). * @return ESR_SUCCESS if success, anything else if an error occurs. */ ESR_ReturnCode PLogMessage(const char* msg, ...) { va_list args; ESR_ReturnCode rc; #if USE_STACKTRACE size_t depth; #endif #if defined (ANDROID) #if defined (HAVE_ANDROID_OS) return ( ESR_SUCCESS );/* Get rid of this for phone device */ #endif #endif if (Glogger == NULL) return ESR_INVALID_STATE; #ifdef USE_STACKTRACE return ESR_SUCCESS; rc = PStackTraceGetDepth(&depth); if (rc == ESR_NOT_SUPPORTED) { /* Debugging symbols are missing */ return ESR_SUCCESS; } else if (rc != ESR_SUCCESS) { pfprintf(PSTDERR, L("PStackTraceGetDepth"), ESR_rc2str(rc)); goto CLEANUP; } /* Remove PLogMessage() from depth */ --depth; if (GlogLevel < depth) return ESR_SUCCESS; #endif va_start(args, msg); rc = logIt(msg, args, ESR_FALSE); va_end(args); return rc; #if USE_STACKTRACE CLEANUP: return rc; #endif }
/** * Initializes variables declared in the superinterface. */ ESR_ReturnCode PFileCreateImpl(PFile* self, const LCHAR* filename, ESR_BOOL isLittleEndian) { PFileImpl* impl = (PFileImpl*) self; ESR_ReturnCode rc; #ifdef USE_THREAD ESR_BOOL threadingEnabled; #endif #ifdef USE_THREAD impl->lock = NULL; #endif impl->littleEndian = isLittleEndian; impl->Interface.destroy = &PFileDestroyImpl; impl->Interface.getFilename = &PFileGetFilenameImpl; impl->Interface.vfprintf = &PFileVfprintfImpl; impl->filename = MALLOC(sizeof(LCHAR) * (LSTRLEN(filename) + 1), MTAG); if (impl->filename == NULL) { rc = ESR_OUT_OF_MEMORY; PLogError(ESR_rc2str(rc)); goto CLEANUP; } LSTRCPY(impl->filename, filename); #ifdef USE_THREAD rc = PtrdIsEnabled(&threadingEnabled); if (rc != ESR_SUCCESS) { pfprintf(PSTDERR, L("[%s:%d] PtrdIsEnabled failed with %s\n"), __FILE__, __LINE__, ESR_rc2str(rc)); goto CLEANUP; } if (threadingEnabled) { rc = PtrdMonitorCreate(&impl->lock); if (rc != ESR_SUCCESS) goto CLEANUP; } #endif return ESR_SUCCESS; CLEANUP: self->destroy(self); return rc; }
static ESR_ReturnCode logIt(const LCHAR *format, va_list args, ESR_BOOL showStackTrace) { ESR_ReturnCode rc = ESR_SUCCESS; ESR_ReturnCode flushRC = ESR_SUCCESS; #ifdef USE_STACKTRACE #define BUFFER_SIZE P_MAX_STACKTRACE + 2000 #else #define BUFFER_SIZE 2000 #endif LCHAR buffer[BUFFER_SIZE] = L(""); // TODO: Remove once logging subsystem supports "warn" level if (strstr(format, "ESR_BUFFER_OVERFLOW")==format) return ESR_SUCCESS; #ifdef USE_STACKTRACE if (Glogger == NULL) { /* * There are three possible scenerios for why logging would occur although the PLog module * is uninitialized: * * 1) The code fails before PLog is initialized (perhaps in other portable components) * 2) The user forgets to initialize the PLog module * 3) The code fails after PLog is uninitialized (on shutdown) * * We do our best by logging any errors but this might result in the memory leak of * the PStackTrace module in case 3. */ rc = PStackTraceCreate(); if (rc != ESR_SUCCESS) { PLOG_PANIC(L("PStackTraceCreate"), rc); goto CLEANUP; } } else { #ifdef USE_THREAD rc = PtrdMutexLock(Gmutex); if (rc != ESR_SUCCESS) return rc; #endif } if (locked) return ESR_INVALID_STATE; locked = ESR_TRUE; if (GlogFormat & LOG_OUTPUT_FORMAT_DATE_TIME) { PTimeStamp now; struct tm* loctime; LCHAR timeStr[TIME_BUF_SIZE]; size_t timeStrSize; PTimeStampSet(&now); loctime = localtime(&now.secs); timeStrSize = LSTRFTIME(timeStr, TIME_BUF_SIZE, TIME_FORMAT, loctime); passert(timeStrSize == (TIME_BUF_SIZE - 5)); psprintf(timeStr + (TIME_BUF_SIZE - 5), ".%03hu", now.msecs); psprintf(buffer + LSTRLEN(buffer), L("%s|"), timeStr); passert(LSTRLEN(buffer) < BUFFER_SIZE); } if (GlogFormat & LOG_OUTPUT_FORMAT_THREAD_ID) { rc = psprintf(buffer + LSTRLEN(buffer), L("trd=%u|"), PtrdGetCurrentThreadId()); passert(LSTRLEN(buffer) < BUFFER_SIZE); } if (GlogFormat & LOG_OUTPUT_FORMAT_MODULE_NAME && showStackTrace) { size_t len = P_MAX_STACKTRACE; LCHAR text[P_MAX_STACKTRACE]; LCHAR* index; size_t i; rc = PStackTraceGetValue((LCHAR*) & text, &len); if (rc == ESR_SUCCESS) { for (i = 0; i < 2; ++i) { rc = PStackTracePopLevel((LCHAR*) & text); if (rc != ESR_SUCCESS) { PLOG_PANIC(L("PStackTracePopLevel"), rc); goto CLEANUP; } } index = text; while (index) { index = LSTRSTR(index, L(" at\n")); if (index != NULL) { *(index + 1) = L('<'); *(index + 2) = L('-'); *(index + 3) = L(' '); } } } else if (rc == ESR_NOT_SUPPORTED) LSTRCPY(text, L("")); else if (rc != ESR_SUCCESS) { PLOG_PANIC(L("PStackTraceGetValue"), rc); goto CLEANUP; } rc = psprintf(buffer + LSTRLEN(buffer), L("Module=%s|"), text); passert(LSTRLEN(buffer) < BUFFER_SIZE); } pvsprintf(buffer + LSTRLEN(buffer), format, args); #else pvsprintf(buffer + LSTRLEN(buffer), format, args); #endif passert(LSTRLEN(buffer) < BUFFER_SIZE); psprintf(buffer + LSTRLEN(buffer), L("\n")); passert(LSTRLEN(buffer) < BUFFER_SIZE); if (Glogger != NULL) { rc = Glogger->printf(Glogger, L("%s"), buffer); if (rc != ESR_SUCCESS) goto CLEANUP; flushRC = Glogger->flush(Glogger); } else { /* We need to log but the logging module is disabled or is locked so we output to stderr instead */ { pfprintf(PSTDERR, L("%s"), buffer); pfflush(PSTDERR); } } locked = ESR_FALSE; #ifdef USE_THREAD PtrdMutexUnlock(Gmutex); #endif return flushRC; CLEANUP: if (Glogger != NULL && Glogger->flush != NULL) flushRC = Glogger->flush(Glogger); locked = ESR_FALSE; #ifdef USE_THREAD PtrdMutexUnlock(Gmutex); #endif return rc != ESR_SUCCESS ? rc : flushRC; }