From 5ba4e74872421edeb1e76e704e508d7b6a8ef2a2 Mon Sep 17 00:00:00 2001 From: yaomanhai Date: Fri, 27 Aug 2021 04:16:44 +0000 Subject: [PATCH] Fix codecheck Signed-off-by: yaomanhai --- services/hilogd/log_querier.cpp | 39 ++++++++++++------------------ services/hilogtool/log_display.cpp | 1 + 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 200893a..e1785fa 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -138,38 +138,29 @@ void HandlePersistStartRequest(char* reqMsg, std::shared_ptr logReade = reinterpret_cast(msgToSend); LogPersistStartResult* pLogPersistStartRst = reinterpret_cast(&pLogPersistStartRsp->logPersistStartRst); + + string logPersisterPath; if (pLogPersistStartRst == nullptr) { return; - } - if (pLogPersistStartMsg->jobId <= 0) { + } else if (pLogPersistStartMsg->jobId <= 0) { pLogPersistStartRst->result = ERR_LOG_PERSIST_JOBID_INVALID; - SetMsgHead(&pLogPersistStartRsp->msgHeader, MC_RSP_LOG_PERSIST_START, sendMsgLen); - logReader->hilogtoolConnectSocket->Write(msgToSend, sendMsgLen + sizeof(MessageHeader)); - return; - } - if (pLogPersistStartMsg->fileSize < MAX_PERSISTER_BUFFER_SIZE) { - std::cout << "Persist log file size less than min size" << std::endl; - pLogPersistStartRst->jobId = pLogPersistStartMsg->jobId; + } else if (pLogPersistStartMsg->fileSize < MAX_PERSISTER_BUFFER_SIZE) { + cout << "Persist log file size less than min size" << std::endl; pLogPersistStartRst->result = ERR_LOG_PERSIST_FILE_SIZE_INVALID; - SetMsgHead(&pLogPersistStartRsp->msgHeader, MC_RSP_LOG_PERSIST_START, sendMsgLen); - logReader->hilogtoolConnectSocket->Write(msgToSend, sendMsgLen + sizeof(MessageHeader)); - return; - } - string logPersisterPath; - if (IsValidFileName(string(pLogPersistStartMsg->filePath)) == true) { - logPersisterPath = (strlen(pLogPersistStartMsg->filePath) == 0) ? (g_logPersisterDir + "hilog") - : (g_logPersisterDir + string(pLogPersistStartMsg->filePath)); - } else { + } else if (IsValidFileName(string(pLogPersistStartMsg->filePath)) == false){ cout << "FileName is not valid!" << endl; - pLogPersistStartRst->jobId = pLogPersistStartMsg->jobId; pLogPersistStartRst->result = ERR_LOG_PERSIST_FILE_NAME_INVALID; - SetMsgHead(&pLogPersistStartRsp->msgHeader, MC_RSP_LOG_PERSIST_START, sendMsgLen); - logReader->hilogtoolConnectSocket->Write(msgToSend, sendMsgLen + sizeof(MessageHeader)); - return; + } else { + logPersisterPath = (strlen(pLogPersistStartMsg->filePath) == 0) ? (g_logPersisterDir + "hilog") + : (g_logPersisterDir + string(pLogPersistStartMsg->filePath)); + if (strcpy_s(pLogPersistStartMsg->filePath, FILE_PATH_MAX_LEN, logPersisterPath.c_str()) != 0) { + pLogPersistStartRst->result = RET_FAIL; + } else { + pLogPersistStartRst->result = JobLauncher(*pLogPersistStartMsg, buffer); + } } - strcpy_s(pLogPersistStartMsg->filePath, FILE_PATH_MAX_LEN, logPersisterPath.c_str()); + pLogPersistStartRst->jobId = pLogPersistStartMsg->jobId; - pLogPersistStartRst->result = JobLauncher(*pLogPersistStartMsg, buffer); SetMsgHead(&pLogPersistStartRsp->msgHeader, MC_RSP_LOG_PERSIST_START, sendMsgLen); logReader->hilogtoolConnectSocket->Write(msgToSend, sendMsgLen + sizeof(MessageHeader)); } diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index 7780984..26ea477 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -37,6 +37,7 @@ constexpr hash_t BASIS = 0xCBF29CE484222325ull; unordered_map errorMsg { + {RET_FAIL, "Unexpected error"}, {ERR_LOG_LEVEL_INVALID, "Invalid log level, the valid log levels include D/I/W/E/F"}, {ERR_LOG_TYPE_INVALID, "Invalid log type, the valid log types include app/core/init"}, {ERR_QUERY_TYPE_INVALID, "Query condition on both types and excluded types is undefined"}, -- Gitee