diff --git a/adapter/properties.cpp b/adapter/properties.cpp index 85ed4b5e3c7f99057aa4c621348f47b318e4222d..202f09f097dfe5cbbd4fc04f026446aff8f2cd72 100644 --- a/adapter/properties.cpp +++ b/adapter/properties.cpp @@ -192,11 +192,11 @@ static bool CheckCache(const PropertyCache *cache) /* use OHOS interface */ } - static bool GetSwitchCache(bool isFirst, SwitchCache& switchCache, uint32_t propType, bool defaultValue) { int notLocked; string key = GetPropertyName(propType); + if (isFirst || CheckCache(&switchCache.cache)) { notLocked = LockByProp(propType); if (!notLocked) { @@ -234,7 +234,7 @@ bool IsDebugOn() bool IsSingleDebugOn() { - static SwitchCache *switchCache = new SwitchCache{{nullptr, 0xffffffff, ""}, false}; + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; bool isFirst = !isFirstFlag.test_and_set(); return GetSwitchCache(isFirst, *switchCache, PROP_SINGLE_DEBUG, false); @@ -242,7 +242,7 @@ bool IsSingleDebugOn() bool IsPersistDebugOn() { - static SwitchCache *switchCache = new SwitchCache{{nullptr, 0xffffffff, ""}, false}; + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; bool isFirst = !isFirstFlag.test_and_set(); return GetSwitchCache(isFirst, *switchCache, PROP_PERSIST_DEBUG, false); @@ -250,7 +250,7 @@ bool IsPersistDebugOn() bool IsPrivateSwitchOn() { - static SwitchCache *switchCache = new SwitchCache{{nullptr, 0xffffffff, ""}, true}; + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, true}; static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; bool isFirst = !isFirstFlag.test_and_set(); return GetSwitchCache(isFirst, *switchCache, PROP_PRIVATE, true); @@ -258,7 +258,7 @@ bool IsPrivateSwitchOn() bool IsProcessSwitchOn() { - static SwitchCache *switchCache = new SwitchCache{{nullptr, 0xffffffff, ""}, false}; + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; bool isFirst = !isFirstFlag.test_and_set(); return GetSwitchCache(isFirst, *switchCache, PROP_PROCESS_FLOWCTRL, false); @@ -266,7 +266,7 @@ bool IsProcessSwitchOn() bool IsDomainSwitchOn() { - static SwitchCache *switchCache = new SwitchCache{{nullptr, 0xffffffff, ""}, false}; + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; bool isFirst = !isFirstFlag.test_and_set(); return GetSwitchCache(isFirst, *switchCache, PROP_DOMAIN_FLOWCTRL, false); @@ -343,11 +343,13 @@ uint16_t GetDomainLevel(uint32_t domain) LogLevelCache* levelCache = new LogLevelCache{{nullptr, 0xffffffff, ""}, LOG_LEVEL_MIN}; RefreshCacheBuf(&levelCache->cache, key.c_str()); levelCache->logLevel = GetCacheLevel(levelCache->cache.propertyValue[0]); + uint16_t lvl = levelCache->logLevel; pair::iterator, bool> ret = domainMap->insert({ domain, levelCache }); if (!ret.second) { delete levelCache; + levelCache = nullptr; } - return levelCache->logLevel; + return lvl; } else { // existed domain if (CheckCache(&it->second->cache)) { // changed InsertLock lock(*mtx); @@ -376,13 +378,15 @@ uint16_t GetTagLevel(const string& tag) LogLevelCache* levelCache = new LogLevelCache{{nullptr, 0xffffffff, ""}, LOG_LEVEL_MIN}; RefreshCacheBuf(&levelCache->cache, key.c_str()); levelCache->logLevel = GetCacheLevel(levelCache->cache.propertyValue[0]); + uint16_t lvl = levelCache->logLevel; pair::iterator, bool> ret = tagMap->insert({ tag, levelCache }); if (!ret.second) { delete(levelCache); + levelCache = nullptr; } - return levelCache->logLevel; + return lvl; } else { // existed tag - if (CheckCache(&it->second->cache)) { //changed + if (CheckCache(&it->second->cache)) { // changed InsertLock lock(*mtx); RefreshCacheBuf(&it->second->cache, key.c_str()); it->second->logLevel = GetCacheLevel(it->second->cache.propertyValue[0]); diff --git a/frameworks/native/format.cpp b/frameworks/native/format.cpp index 591107b1b1b7206e8d8716d87a2b0831416f607d..55d84810476f3d6f8d8727e20b03e7adbd177267 100644 --- a/frameworks/native/format.cpp +++ b/frameworks/native/format.cpp @@ -103,7 +103,7 @@ int HilogShowTimeBuffer(char* buffer, int bufLen, HilogShowFormat showFormat, timeLen += ((ret > 0) ? ret : 0); break; case COLOR_SHOWFORMAT: - ret = snprintf_s(buffer, bufLen, bufLen, + ret = snprintf_s(buffer, bufLen, bufLen - 1, "\x1B[38;5;%dm%02d-%02d %02d:%02d:%02d.%03llu\x1b[0m", ColorFromLevel(contentOut.level), ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, nsecTime / NS2MS); timeLen += ((ret > 0) ? ret : 0); @@ -116,7 +116,7 @@ int HilogShowTimeBuffer(char* buffer, int bufLen, HilogShowFormat showFormat, break; } } - return timeLen; + return timeLen; } void HilogShowBuffer(char* buffer, int bufLen, const HilogShowFormatBuffer& contentOut, HilogShowFormat showFormat) @@ -127,7 +127,7 @@ void HilogShowBuffer(char* buffer, int bufLen, const HilogShowFormatBuffer& cont return; } logLen += HilogShowTimeBuffer(buffer, bufLen, showFormat, contentOut); - + if (showFormat == COLOR_SHOWFORMAT) { ret = snprintf_s(buffer + logLen, bufLen - logLen, bufLen - logLen - 1, " \x1B[38;5;%dm%5d\x1b[0m", ColorFromLevel(contentOut.level), contentOut.pid); @@ -161,7 +161,7 @@ void HilogShowBuffer(char* buffer, int bufLen, const HilogShowFormatBuffer& cont ret = snprintf_s(buffer + logLen, bufLen - logLen, bufLen - logLen - 1, " %s", contentOut.data + contentOut.tag_len); logLen += ((ret > 0) ? ret : 0); - } + } } } } \ No newline at end of file diff --git a/frameworks/native/hilog_printf.cpp b/frameworks/native/hilog_printf.cpp index fd0512945e494f31bef129f846b23e30b95bc7a8..44a97fb850c69bef7aba86972ed18ebd531b05bf 100644 --- a/frameworks/native/hilog_printf.cpp +++ b/frameworks/native/hilog_printf.cpp @@ -109,12 +109,18 @@ static uint32_t ParseProcessQuota() continue; } if (proName == processName) { + int ret; processQuotaValue = line.substr(processNameEnd, LOG_FLOWCTRL_QUOTA_STR_LEN); char quotaValue[LOG_FLOWCTRL_QUOTA_STR_LEN]; - strcpy_s(quotaValue, LOG_FLOWCTRL_QUOTA_STR_LEN, processQuotaValue.c_str()); - sscanf_s(quotaValue, "%d", &proQuota); - ifs.close(); - return proQuota; + ret = strcpy_s(quotaValue, LOG_FLOWCTRL_QUOTA_STR_LEN, processQuotaValue.c_str()); + if (ret != 0) { + break; + } + ret = sscanf_s(quotaValue, "%d", &proQuota); + if (ret != 0) { + cout << "invalid quota config" << endl; + } + break; } } ifs.close(); @@ -136,7 +142,7 @@ static int HiLogFlowCtrlProcess(int len, uint16_t logType, bool debug) if (!isFirstFlag.test_and_set()) { processQuota = ParseProcessQuota(); } - + struct timespec tsNow = { 0, 0 }; struct timespec tsStart = atomic_load(&gStartTime); clock_gettime(CLOCK_MONOTONIC, &tsNow); diff --git a/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index e87596b1c31cc2098ec02a03bcc62f04628318e4..c223c74d7ac137674eddf8f3beca7c4af2768a5b 100644 --- a/frameworks/native/include/hilog_common.h +++ b/frameworks/native/include/hilog_common.h @@ -27,7 +27,7 @@ #define INPUT_SOCKET SOCKET_FILE_DIR INPUT_SOCKET_NAME #define CONTROL_SOCKET_NAME "hilogControl" #define CONTROL_SOCKET SOCKET_FILE_DIR CONTROL_SOCKET_NAME -#define HLIOG_FILE_DIR "/data/log/hilog/" +#define HILOG_FILE_DIR "/data/log/hilog/" #define SENDIDN 0 // hilogd: reached end of log; hilogtool: exit log reading #define SENDIDA 1 // hilogd & hilogtool: normal log reading diff --git a/services/hilogd/etc/hilogd.rc b/services/hilogd/etc/hilogd.rc index a4665de64960cd5c32321efb1ae6829857251872..3177d08cab5c6c8c3be180bc818dec1d721b5654 100644 --- a/services/hilogd/etc/hilogd.rc +++ b/services/hilogd/etc/hilogd.rc @@ -16,8 +16,8 @@ on early-init on post-fs-data mkdir /data/log/ 0770 system log - mkdir /data/log/hilog/ 0750 logd logd - restorecon recursive /data/log/hilog/ + mkdir /data/log/hilog/ 0750 logd log + restorecon_recursive /data/log/hilog/ start hilogd service hilogd /system/bin/hilogd diff --git a/services/hilogd/include/log_buffer.h b/services/hilogd/include/log_buffer.h index 4ab724c2703ad99393b98e09d76ce9ac740af436..a0ad2ddd411cfd4c00602a320838211db9e5717c 100644 --- a/services/hilogd/include/log_buffer.h +++ b/services/hilogd/include/log_buffer.h @@ -39,6 +39,7 @@ public: bool Query(LogReader* reader); bool Query(std::shared_ptr reader); void AddLogReader(std::weak_ptr); + void RemoveLogReader(std::shared_ptr reader); size_t Delete(uint16_t logType); size_t GetBuffLen(uint16_t logType); size_t SetBuffLen(uint16_t logType, uint64_t buffSize); @@ -48,7 +49,6 @@ public: int32_t ClearStatisticInfoByDomain(uint32_t domain); void GetBufferLock(); void ReleaseBufferLock(); - void RemoveLogReader(std::shared_ptr reader); private: size_t size; size_t sizeByType[LOG_TYPE_MAX]; diff --git a/services/hilogd/include/log_collector.h b/services/hilogd/include/log_collector.h index aa37e2c03c5aee5e78f57a345d3dbf7c21f8af96..3109a7d8a647ff28c70ac761a82b20dc61ba49f1 100644 --- a/services/hilogd/include/log_collector.h +++ b/services/hilogd/include/log_collector.h @@ -24,7 +24,7 @@ namespace HiviewDFX { class LogCollector { public: LogCollector(HilogBuffer* buffer); - void operator ()(); + void operator ()(); static int FlowCtrlDataRecv(HilogMsg *msg, int ret); static size_t InsertLogToBuffer(const HilogMsg& msg); #ifndef __RECV_MSG_WITH_UCRED_ diff --git a/services/hilogd/include/log_compress.h b/services/hilogd/include/log_compress.h index b2ed40a49b991d73564c0f595628ac1326923278..dcb2afd6e18dcf8104e10ab071ae51d58dcc0a48 100644 --- a/services/hilogd/include/log_compress.h +++ b/services/hilogd/include/log_compress.h @@ -23,6 +23,7 @@ #include "zstd.h" #endif #include + namespace OHOS { namespace HiviewDFX { typedef struct { @@ -31,6 +32,7 @@ typedef struct { } LogPersisterBuffer; const uint16_t CHUNK = 16384; + class LogCompress { public: LogCompress(); @@ -63,5 +65,4 @@ private: }; } } -#endif - /* HILOG_COMPRESS_H */ +#endif /* HILOG_COMPRESS_H */ diff --git a/services/hilogd/include/log_reader.h b/services/hilogd/include/log_reader.h index 0b767a5b5e99f59f896a3d3bf2528f42e1c843d2..24290fa2856118cb8eb045dccc2ef68e1fb07b40 100644 --- a/services/hilogd/include/log_reader.h +++ b/services/hilogd/include/log_reader.h @@ -62,7 +62,7 @@ public: bool isNotified; LogReader(); - virtual ~LogReader() = default; + virtual ~LogReader(); bool GetReload() const; void SetReload(bool); virtual void NotifyForNewData() = 0; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index fd975f02b249b436e8aeb2268829951fa4427311..d1f162ce4512adabca333e017aaf3b4c9547e167 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -227,6 +227,19 @@ void HilogBuffer::AddLogReader(std::weak_ptr reader) logReaderListMutex.unlock(); } +void HilogBuffer::RemoveLogReader(std::shared_ptr reader) +{ + logReaderListMutex.lock(); + const auto findIter = std::find_if(logReaderList.begin(), logReaderList.end(), + [reader](const std::weak_ptr& ptr0) { + return ptr0.lock() == reader; + }); + if (findIter != logReaderList.end()) { + logReaderList.erase(findIter); + } + logReaderListMutex.unlock(); +} + bool HilogBuffer::Query(LogReader* reader) { return Query(std::shared_ptr(reader)); @@ -337,6 +350,7 @@ bool HilogBuffer::ConditionMatch(std::shared_ptr reader) if (((static_cast((0b01 << (reader->readPos->type)) & (reader->queryCondition.types)) == 0) || (static_cast((0b01 << (reader->readPos->level)) & (reader->queryCondition.levels)) == 0))) return false; + int ret = 0; if (reader->queryCondition.nPid > 0) { for (int i = 0; i < reader->queryCondition.nPid; i++) { @@ -370,7 +384,7 @@ bool HilogBuffer::ConditionMatch(std::shared_ptr reader) if (ret == 0) return false; ret = 0; } - + // exclusion if (reader->queryCondition.nNoPid > 0) { for (int i = 0; i < reader->queryCondition.nNoPid; i++) { @@ -412,18 +426,5 @@ void HilogBuffer::ReleaseBufferLock() { hilogBufferMutex.unlock(); } - -void HilogBuffer::RemoveLogReader(std::shared_ptr reader) -{ - logReaderListMutex.lock(); - const auto findIter = std::find_if(logReaderList.begin(), logReaderList.end(), - [reader](const std::weak_ptr& ptr0) { - return ptr0.lock() == reader; - }); - if (findIter != logReaderList.end()) { - logReaderList.erase(findIter); - } - logReaderListMutex.unlock(); -} } // namespace HiviewDFX } // namespace OHOS diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index 9a571dcfdede7651b22c81e31e6e01fb5b8bd427..58af51225d5997d42ff0586f2cae6c2cdf5c3f2a 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -183,8 +183,9 @@ int GenPersistLogHeader(HilogData *data, list& persistList) showBuffer.domain = data->domain; showBuffer.tv_sec = data->tv_sec; showBuffer.tv_nsec = data->tv_nsec; + int offset = data->tag_len; - char *dataCopy= (char*)calloc(data->len, sizeof(char)); + char *dataCopy = (char*)calloc(data->len, sizeof(char)); memcpy_s(dataCopy, offset, data->tag, offset); memcpy_s(dataCopy + offset, data->len - offset, data->content, data->len - offset); showBuffer.data = dataCopy; diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 49ee39e12047ed70cb998ff7137c1b0fb7e9e7d0..200893a44c6cfccb06c538d7277a0fa91c60b965 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -43,18 +43,20 @@ namespace HiviewDFX { using namespace std; namespace fs = std::filesystem; constexpr int MAX_DATA_LEN = 2048; -string g_logPersisterDir = HLIOG_FILE_DIR; +string g_logPersisterDir = HILOG_FILE_DIR; constexpr int DEFAULT_LOG_LEVEL = 1<version = 0; msgHeader->msgType = msgCmd; msgHeader->msgLen = msgLen; } + inline bool IsValidFileName(const std::string& strFileName) { // File name shouldn't contain "[\\/:*?\"<>|]" @@ -62,6 +64,7 @@ inline bool IsValidFileName(const std::string& strFileName) bool bValid = !std::regex_search(strFileName, regExpress); return bValid; } + LogPersisterRotator* MakeRotator(const LogPersistStartMsg& pLogPersistStartMsg) { string fileSuffix = ""; @@ -142,7 +145,7 @@ void HandlePersistStartRequest(char* reqMsg, std::shared_ptr logReade pLogPersistStartRst->result = ERR_LOG_PERSIST_JOBID_INVALID; SetMsgHead(&pLogPersistStartRsp->msgHeader, MC_RSP_LOG_PERSIST_START, sendMsgLen); logReader->hilogtoolConnectSocket->Write(msgToSend, sendMsgLen + sizeof(MessageHeader)); - return; + return; } if (pLogPersistStartMsg->fileSize < MAX_PERSISTER_BUFFER_SIZE) { std::cout << "Persist log file size less than min size" << std::endl; @@ -238,9 +241,11 @@ void HandlePersistQueryRequest(char* reqMsg, std::shared_ptr logReade uint16_t sendMsgLen = 0; int32_t rst = 0; list::iterator it; + if (msgLen > sizeof(LogPersistQueryMsg) * LOG_TYPE_MAX) { return; } + while (pLogPersistQueryMsg && recvMsgLen < msgLen) { list resultList; cout << pLogPersistQueryMsg->logType << endl; @@ -567,7 +572,7 @@ void LogQuerier::NotifyForNewData() rsp.data.type = -1; /* set header */ SetMsgHead(&(rsp.header), NEXT_RESPONSE, sizeof(rsp)); - if ( WriteData(rsp, nullptr) <= 0) { + if (WriteData(rsp, nullptr) <= 0) { isNotified = false; } } @@ -612,7 +617,7 @@ int LogQuerier::RestorePersistJobs(HilogBuffer& _buffer) } JobLauncher(info.msg, _buffer, true, info.index + 1); std::cout << "Recovery Info:" << std::endl << - "jobId=" << (unsigned)(info.msg.jobId) << std::endl << + "jobId=" << (unsigned)(info.msg.jobId) << std::endl << "filePath=" << (info.msg.filePath) << std::endl; } } diff --git a/services/hilogd/log_reader.cpp b/services/hilogd/log_reader.cpp index aa801c650d700e819474cac355545b7cd7144798..a34e34e6f1beb2274969c37f71462cb05f3e3e7b 100644 --- a/services/hilogd/log_reader.cpp +++ b/services/hilogd/log_reader.cpp @@ -33,6 +33,11 @@ LogReader::LogReader() isNotified = false; } +LogReader::~LogReader() +{ + cout << "Log Reader destruct" << endl; +} + void LogReader::NotifyReload() { isReload = true; diff --git a/services/hilogd/main.cpp b/services/hilogd/main.cpp index 14df61850314605f8be135643c21b28460cb2322..df060f299a81f276d8ff1ad2b9bf4a7e5b0a7b65 100644 --- a/services/hilogd/main.cpp +++ b/services/hilogd/main.cpp @@ -55,7 +55,7 @@ int HilogdEntry(int argc, char* argv[]) HilogBuffer hilogBuffer; #ifdef DEBUG - int fd = open(HLIOG_FILE_DIR"hilogd.txt", O_WRONLY | O_APPEND); + int fd = open(HILOG_FILE_DIR"hilogd.txt", O_WRONLY | O_APPEND); if (fd > 0) { g_fd = dup2(fd, fileno(stdout)); } else { @@ -82,7 +82,7 @@ int HilogdEntry(int argc, char* argv[]) #endif server.RunServingThread(); } - + std::thread startupCheckThread([&hilogBuffer]() { std::shared_ptr logQuerier = std::make_shared(nullptr, &hilogBuffer); logQuerier->RestorePersistJobs(hilogBuffer); diff --git a/services/hilogtool/include/hilogtool.h b/services/hilogtool/include/hilogtool.h index aea36bbaf70db75348dbdc8bf302ccf2f05b156f..61a6f64e34f25ae1e3041b8e927c7b8e3fe9678c 100644 --- a/services/hilogtool/include/hilogtool.h +++ b/services/hilogtool/include/hilogtool.h @@ -17,8 +17,10 @@ namespace OHOS { namespace HiviewDFX { + #define DOMAIN_NUMBER_BASE (16) #define DOMAIN_MAX_SCOPE 0xDFFFFFF + typedef struct { uint16_t noBlockMode; uint8_t nPid; diff --git a/services/hilogtool/include/log_controller.h b/services/hilogtool/include/log_controller.h index e097aaef9f405bb28a49d9b861ce408aff6aaff1..2030eac95e9073b91117bcaf9622ecb625694a62 100644 --- a/services/hilogtool/include/log_controller.h +++ b/services/hilogtool/include/log_controller.h @@ -27,6 +27,7 @@ namespace OHOS { namespace HiviewDFX { constexpr int RECV_BUF_LEN = MAX_LOG_LEN * 2; + void SetMsgHead(MessageHeader* msgHeader, const uint8_t msgCmd, const uint16_t msgLen); int MultiQuerySplit(const std::string& src, const char& delim, std::vector& vec); inline void PrintBuffer(void* pBuff, unsigned int nLen); diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 1da81edd8a04f0456bfdaed2682946987fe7c4c4..190bc46e88a05bd85e01e8aab49bea75fb62b04b 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -178,12 +178,9 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte std::istringstream(context->domains[i]) >> std::hex >> logQueryRequest.domains[i]; } for (int i = 0; i < context->nTag; i++) { - if (context->tags[i].length() >= MAX_TAG_LEN) { - strncpy_s(logQueryRequest.tags[i], MAX_TAG_LEN, - context->tags[i].c_str(), MAX_TAG_LEN - 1); - } else { - strncpy_s(logQueryRequest.tags[i], context->tags[i].length() + 1, - context->tags[i].c_str(), context->tags[i].length()); + if (strncpy_s(logQueryRequest.tags[i], MAX_TAG_LEN, + context->tags[i].c_str(), context->tags[i].length()) { + continue; } } logQueryRequest.noLevels = context->noLevels; @@ -198,12 +195,9 @@ void LogQueryRequestOp(SeqPacketSocketClient& controller, const HilogArgs* conte std::istringstream(context->noDomains[i]) >> std::hex >> logQueryRequest.noDomains[i]; } for (int i = 0; i < context->nNoTag; i++) { - if (context->noTags[i].length() >= MAX_TAG_LEN) { - strncpy_s(logQueryRequest.noTags[i], MAX_TAG_LEN, - context->noTags[i].c_str(), MAX_TAG_LEN - 1); - } else { - strncpy_s(logQueryRequest.noTags[i], context->noTags[i].length() + 1, - context->noTags[i].c_str(), context->noTags[i].length()); + if (strncpy_s(logQueryRequest.noTags[i], MAX_TAG_LEN, + context->noTags[i].c_str(), context->noTags[i].length()) { + continue; } } SetMsgHead(&logQueryRequest.header, LOG_QUERY_REQUEST, sizeof(LogQueryRequest)-sizeof(MessageHeader)); @@ -333,7 +327,7 @@ int32_t StatisticInfoOp(SeqPacketSocketClient& controller, uint8_t msgCmd, switch (msgCmd) { case MC_REQ_STATISTIC_INFO_QUERY: StatisticInfoQueryRequest staInfoQueryReq; - memset_s (&staInfoQueryReq, sizeof(StatisticInfoQueryRequest), 0, sizeof(StatisticInfoQueryRequest)); + memset_s(&staInfoQueryReq, sizeof(StatisticInfoQueryRequest), 0, sizeof(StatisticInfoQueryRequest)); staInfoQueryReq.logType = logType; staInfoQueryReq.domain = domain; SetMsgHead(&staInfoQueryReq.msgHeader, msgCmd, sizeof(StatisticInfoQueryRequest) - sizeof(MessageHeader)); @@ -341,7 +335,7 @@ int32_t StatisticInfoOp(SeqPacketSocketClient& controller, uint8_t msgCmd, break; case MC_REQ_STATISTIC_INFO_CLEAR: StatisticInfoClearRequest staInfoClearReq; - memset_s (&staInfoClearReq, sizeof(StatisticInfoClearRequest), 0, sizeof(StatisticInfoClearRequest)); + memset_s(&staInfoClearReq, sizeof(StatisticInfoClearRequest), 0, sizeof(StatisticInfoClearRequest)); staInfoClearReq.logType = logType; staInfoClearReq.domain = domain; SetMsgHead(&staInfoClearReq.msgHeader, msgCmd, sizeof(StatisticInfoClearRequest) - sizeof(MessageHeader)); @@ -440,7 +434,8 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi SetMsgHead(&pLogPersistStartReq->msgHeader, msgCmd, sizeof(LogPersistStartRequest)); controller.WriteAll(msgToSend, sizeof(LogPersistStartRequest)); break; - } + } + case MC_REQ_LOG_PERSIST_STOP: { LogPersistStopRequest* pLogPersistStopReq = reinterpret_cast(msgToSend); @@ -520,6 +515,7 @@ int32_t SetPropertiesOp(SeqPacketSocketClient& controller, uint8_t operationType return RET_FAIL; } break; + case OT_LOG_LEVEL: if (propertyParm->tagStr != "" && propertyParm->domainStr != "") { return RET_FAIL; @@ -552,6 +548,7 @@ int32_t SetPropertiesOp(SeqPacketSocketClient& controller, uint8_t operationType cout << "global log level is set to " << propertyParm->logLevelStr << endl; } break; + case OT_FLOW_SWITCH: if (propertyParm->flowSwitchStr == "pidon") { key = GetPropertyName(PROP_PROCESS_FLOWCTRL); @@ -574,6 +571,7 @@ int32_t SetPropertiesOp(SeqPacketSocketClient& controller, uint8_t operationType return RET_FAIL; } break; + default: break; } diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index d48b96afed88be96b15ec00d8d92441f91f993c7..77809840b0f036338abe278c14a06d87abe0b62b 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -42,14 +42,14 @@ unordered_map errorMsg {ERR_QUERY_TYPE_INVALID, "Query condition on both types and excluded types is undefined"}, {ERR_QUERY_LEVEL_INVALID, "Query condition on both levels and excluded levels is undefined"}, {ERR_QUERY_DOMAIN_INVALID, "Invalid domain format, a hexadecimal number is needed"}, - {ERR_QUERY_TAG_INVALID, "Query condition on both tags and excluded tags is undefined"}, + {ERR_QUERY_TAG_INVALID, "Query condition on both tags and excluded tags is undefined"}, {ERR_QUERY_PID_INVALID, "Query condition on both pid and excluded pid is undefined"}, {ERR_BUFF_SIZE_INVALID, "Invalid buffer size, buffer size should be more than 0 and less than " + to_string(MAX_BUFFER_SIZE)}, {ERR_BUFF_SIZE_EXP, "Buffer resize exception"}, {ERR_LOG_PERSIST_FILE_SIZE_INVALID, "Invalid log persist file size, file size should be not less than " + to_string(MAX_PERSISTER_BUFFER_SIZE)}, - {ERR_LOG_PERSIST_FILE_NAME_INVALID, "Invalid log persist file name, file name should notĀ containĀ [\\/:*?\"<>|]"}, + {ERR_LOG_PERSIST_FILE_NAME_INVALID, "Invalid log persist file name, file name should not contain [\\/:*?\"<>|]"}, {ERR_LOG_PERSIST_COMPRESS_BUFFER_EXP, "Invalid Log persist compression buffer"}, {ERR_LOG_PERSIST_FILE_PATH_INVALID, "Invalid persister file path"}, {ERR_LOG_PERSIST_COMPRESS_INIT_FAIL, "Log persist compression initialization failed"}, @@ -67,13 +67,13 @@ unordered_map errorMsg {ERR_LOG_CONTENT_NULL, "Log content NULL"}, {ERR_COMMAND_NOT_FOUND, "Command not found"}, {ERR_FORMAT_INVALID, "Invalid format parameter"} -}; +}; string ParseErrorCode(ErrorCode errorCode) { if (errorMsg.count(errorCode) == 0) { cout << "ERR_CODE not exist" << endl; - } + } string errorMsgStr = "[ERR_CODE:" + to_string(errorCode) + "], " + errorMsg[errorCode]; return errorMsgStr; } @@ -128,7 +128,6 @@ string GetOrigType(uint16_t shiftType) return logType; } - string GetPressAlgStr(uint16_t pressAlg) { string pressAlgStr; @@ -440,6 +439,7 @@ void HilogShowLog(HilogShowFormat showFormat, HilogDataMessage* data, HilogArgs* if (data->sendId == SENDIDN) { return; } + if (data->length == 0) { std::cout << ParseErrorCode(ERR_LOG_CONTENT_NULL) << endl; return; @@ -460,6 +460,7 @@ void HilogShowLog(HilogShowFormat showFormat, HilogDataMessage* data, HilogArgs* return; } } + char buffer[MAX_LOG_LEN * 2]; showBuffer.level = data->level; showBuffer.pid = data->pid; @@ -468,7 +469,6 @@ void HilogShowLog(HilogShowFormat showFormat, HilogDataMessage* data, HilogArgs* showBuffer.tag_len = data->tag_len; showBuffer.tv_sec = data->tv_sec; showBuffer.tv_nsec = data->tv_nsec; - int offset = data->tag_len; char *dataBegin = data->data + offset; char *dataPos = data->data + offset; diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 1bf7d2c2d472f8f8b8b10b6c69d02d961e897d2b..5830b2aa169deeb943c3bae32a9a7566da288f35 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -261,7 +261,7 @@ int HilogEntry(int argc, char* argv[]) } } if (context.types != 0 && context.noTypes != 0) { - cout << ParseErrorCode(ERR_QUERY_TYPE_INVALID) << endl; + cout << ParseErrorCode(ERR_QUERY_TYPE_INVALID) << endl; exit(RET_FAIL); } break; @@ -404,7 +404,6 @@ int HilogEntry(int argc, char* argv[]) } if (context.nTag != 0 && context.nNoTag != 0) { cout << ParseErrorCode(ERR_QUERY_TAG_INVALID) << endl; - exit(RET_FAIL); } break; @@ -587,6 +586,7 @@ int HilogEntry(int argc, char* argv[]) LogQueryResponseOp(controller, recvBuffer, RECV_BUF_LEN, &context, showFormat); break; } + default: cout << "Invalid response from hilogd! response: " << msgHeader->msgType << endl; break;