From c0c98ddedffdc3785e9101a1c6a9fa15ee8df347 Mon Sep 17 00:00:00 2001 From: youyouyuai Date: Wed, 11 Aug 2021 03:25:24 +0000 Subject: [PATCH 1/2] cmd fix Signed-off-by: youyouyuai --- services/hilogtool/main.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 1daf778..0a99406 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -175,6 +175,7 @@ int HilogEntry(int argc, char* argv[]) context.noBlockMode = 0; int32_t ret = 0; HilogShowFormat showFormat = OFF_SHOWFORMAT; + int controlCount = 0; for (int argsCount = 0; argsCount < argc; argsCount++) { args.push_back(argv[argsCount]); } @@ -301,14 +302,17 @@ int HilogEntry(int argc, char* argv[]) case 'g': context.buffSizeArgs = "query"; noLogOption = true; + controlCount++; break; case 'G': context.buffSizeArgs = optarg; noLogOption = true; + controlCount++; break; case 'w': context.logFileCtrlArgs = optarg; noLogOption = true; + controlCount++; break; case 'l': context.fileSizeArgs = optarg; @@ -325,10 +329,12 @@ int HilogEntry(int argc, char* argv[]) case 'p': context.personalArgs = optarg; noLogOption = true; + controlCount++; break; case 'r': context.logClearArgs = "clear"; noLogOption = true; + controlCount++; break; case 'D': indexDomain = optind - 1; @@ -361,10 +367,12 @@ int HilogEntry(int argc, char* argv[]) case 's': context.statisticArgs = "query"; noLogOption = true; + controlCount++; break; case 'S': context.statisticArgs = "clear"; noLogOption = true; + controlCount++; break; case 'T': indexTag = optind - 1; @@ -402,10 +410,12 @@ int HilogEntry(int argc, char* argv[]) case 'b': context.logLevelArgs = optarg; noLogOption = true; + controlCount++; break; case 'Q': context.flowSwitchArgs = optarg; noLogOption = true; + controlCount++; break; case 'P': indexPid = optind - 1; @@ -464,6 +474,9 @@ int HilogEntry(int argc, char* argv[]) context.levels = DEFAULT_LOG_LEVEL; } if (noLogOption) { + if (controlCount != 1) { + exit(-1); + } if (context.buffSizeArgs != "") { if (context.buffSizeArgs == "query") { ret = BufferSizeOp(controller, MC_REQ_BUFFER_SIZE, context.logTypeArgs, ""); @@ -484,12 +497,12 @@ int HilogEntry(int argc, char* argv[]) logPersistParam.jobIdStr = context.jobIdArgs; if (context.logFileCtrlArgs == "start") { ret = LogPersistOp(controller, MC_REQ_LOG_PERSIST_START, &logPersistParam); - } - if (context.logFileCtrlArgs == "stop") { + } else if (context.logFileCtrlArgs == "stop") { ret = LogPersistOp(controller, MC_REQ_LOG_PERSIST_STOP, &logPersistParam); - } - if (context.logFileCtrlArgs == "query") { + } else if (context.logFileCtrlArgs == "query") { ret = LogPersistOp(controller, MC_REQ_LOG_PERSIST_QUERY, &logPersistParam); + } else { + exit(-1); } if (ret == RET_FAIL) { cout << "log file task operation error!" << endl; @@ -543,6 +556,8 @@ int HilogEntry(int argc, char* argv[]) exit(-1); } exit(0); + } else { + exit(-1); } } else { LogQueryRequestOp(controller, &context); -- Gitee From 7c8b8428e64b4f88c14a43f341cb45ce153eab1a Mon Sep 17 00:00:00 2001 From: youyouyuai Date: Tue, 24 Aug 2021 08:46:51 +0000 Subject: [PATCH 2/2] fix cmd Signed-off-by: youyouyuai --- frameworks/native/include/hilog_common.h | 2 +- services/hilogtool/log_controller.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index e87596b..e920f5a 100644 --- a/frameworks/native/include/hilog_common.h +++ b/frameworks/native/include/hilog_common.h @@ -99,7 +99,6 @@ typedef enum { ERR_QUERY_TAG_INVALID = -6, ERR_QUERY_PID_INVALID = -7, ERR_QUERY_TYPE_INVALID = -8, - ERR_BUFF_SIZE_INVALID = -8, ERR_BUFF_SIZE_EXP = -9, ERR_LOG_CONTENT_NULL = -10, ERR_LOG_PERSIST_FILE_SIZE_INVALID = -11, @@ -121,5 +120,6 @@ typedef enum { ERR_FLOWCONTROL_CONF_OPEN_FAIL = -27, ERR_LOG_PERSIST_JOBID_INVALID = -28, ERR_FLOWCTRL_SWITCH_VALUE_INVALID = -29, + ERR_BUFF_SIZE_INVALID = -30, } ErrorCode; #endif /* HILOG_COMMON_H */ diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 1da81ed..a93be40 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "hilog/log.h" #include "hilog_common.h" @@ -92,6 +93,10 @@ uint64_t GetBuffSize(const string& buffSizeStr) { uint64_t index = buffSizeStr.size() - 1; uint64_t buffSize; + std::regex reg_buff_size("[0-9]+[bBkKmMgGtT]?"); + if (!std::regex_match(buffSizeStr, reg_buff_size)) { + return 0; + } if (buffSizeStr[index] == 'b' || buffSizeStr[index] == 'B') { buffSize = stol(buffSizeStr.substr(0, index)); } else if (buffSizeStr[index] == 'k' || buffSizeStr[index] == 'K') { -- Gitee