diff --git a/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index e87596b1c31cc2098ec02a03bcc62f04628318e4..e920f5aafd44f02d16c70b4a3439402e2c3e7e86 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 1da81edd8a04f0456bfdaed2682946987fe7c4c4..a93be40dcfaa81c585b7ebdc0d5e6568d6355679 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') { diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 1bf7d2c2d472f8f8b8b10b6c69d02d961e897d2b..ec13ac0bb1386926a2ac796c2abc6aaedc3c6523 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]); } @@ -299,14 +300,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; @@ -323,10 +327,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; @@ -370,10 +376,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; @@ -411,10 +419,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; @@ -472,6 +482,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, ""); @@ -492,12 +505,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; @@ -551,6 +564,8 @@ int HilogEntry(int argc, char* argv[]) exit(-1); } exit(0); + } else { + exit(-1); } } else { LogQueryRequestOp(controller, &context);