From 57afdc6612623192dab0650e095e659929f7051d Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 1 Dec 2024 14:51:12 +0800 Subject: [PATCH] fix: compile problem of log rotate on windows --- cmake/cmake.options | 4 ++++ include/util/tlog.h | 2 +- source/common/src/tglobal.c | 26 +++++++++++++++++++++++- source/dnode/mgmt/exe/dmMain.c | 1 - source/util/src/tlog.c | 34 ++++++-------------------------- tools/shell/src/shellArguments.c | 2 -- 6 files changed, 36 insertions(+), 33 deletions(-) diff --git a/cmake/cmake.options b/cmake/cmake.options index e3b5782d85..323132ea76 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -166,6 +166,10 @@ IF(${BUILD_WITH_ANALYSIS}) set(BUILD_WITH_S3 ON) ENDIF() +IF(${BUILD_TEST}) +add_definitions(-DBUILD_TEST) +ENDIF() + IF(${BUILD_S3}) IF(${BUILD_WITH_S3}) diff --git a/include/util/tlog.h b/include/util/tlog.h index 9827331258..78ca6ffe15 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -41,6 +41,7 @@ extern bool tsAsyncLog; extern bool tsAssert; extern int32_t tsNumOfLogLines; extern int32_t tsLogKeepDays; +extern char *tsLogOutput; extern LogFp tsLogFp; extern int64_t tsNumOfErrorLogs; extern int64_t tsNumOfInfoLogs; @@ -72,7 +73,6 @@ extern int32_t simDebugFlag; extern int32_t tqClientDebugFlag; int32_t taosInitLogOutput(const char **ppLogName); -int32_t taosSetLogOutput(); int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc); void taosCloseLog(); void taosResetLog(); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 20b3056af9..c1a3026394 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1011,7 +1011,31 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { TAOS_RETURN(TSDB_CODE_SUCCESS); } -extern char *tsLogOutput; +static int32_t taosSetLogOutput(SConfig *pCfg) { + if (tsLogOutput) { + char *pLog = tsLogOutput; + char *pEnd = NULL; + if (strcasecmp(pLog, "stdout") && strcasecmp(pLog, "stderr") && strcasecmp(pLog, "/dev/null")) { + if ((pEnd = strrchr(pLog, '/')) || (pEnd = strrchr(pLog, '\\'))) { + int32_t pathLen = POINTER_DISTANCE(pEnd, pLog) + 1; + if (*pLog == '/' || *pLog == '\\') { + if (pathLen >= PATH_MAX) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); + tstrncpy(tsLogDir, pLog, pathLen); + } else { + int32_t len = strlen(tsLogDir); + if (tsLogDir[len - 1] != '/' && tsLogDir[len - 1] != '\\') { + tsLogDir[len++] = TD_DIRSEP_CHAR; + } + int32_t remain = PATH_MAX - len - 1; + if (remain < pathLen) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); + tstrncpy(tsLogDir + len, pLog, pathLen); + } + TAOS_CHECK_RETURN(cfgSetItem(pCfg, "logDir", tsLogDir, CFG_STYPE_DEFAULT, true)); + } + } + } + return 0; +} static int32_t taosSetClientLogCfg(SConfig *pCfg) { SConfigItem *pItem = NULL; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 1ca2756708..e15e946d5a 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -186,7 +186,6 @@ static void dmSetSignalHandle() { } extern bool generateNewMeta; -extern char *tsLogOutput; static int32_t dmParseArgs(int32_t argc, char const *argv[]) { global.startTime = taosGetTimestampMs(); diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 09835d7978..9678802a01 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -105,7 +105,6 @@ bool tsAssert = true; #endif int32_t tsNumOfLogLines = 10000000; int32_t tsLogKeepDays = 0; - char *tsLogOutput = NULL; LogFp tsLogFp = NULL; int64_t tsNumOfErrorLogs = 0; @@ -297,30 +296,6 @@ int32_t taosInitLogOutput(const char **ppLogName) { return 0; } -int32_t taosSetLogOutput(SConfig *pCfg) { - if (tsLogOutput && (tsLogObj.outputType == LOG_OUTPUT_FILE)) { - char *pLog = tsLogOutput; - char *pEnd = NULL; - if ((pEnd = strrchr(pLog, '/')) || (pEnd = strrchr(pLog, '\\'))) { - int32_t pathLen = POINTER_DISTANCE(pEnd, pLog) + 1; - if (*pLog == '/' || *pLog == '\\') { - if (pathLen >= PATH_MAX) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); - tstrncpy(tsLogDir, pLog, pathLen); - } else { - int32_t len = strlen(tsLogDir); - if (tsLogDir[len - 1] != '/' && tsLogDir[len - 1] != '\\') { - tsLogDir[len++] = TD_DIRSEP_CHAR; - } - int32_t remain = PATH_MAX - len - 1; - if (remain < pathLen) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); - tstrncpy(tsLogDir + len, pLog, pathLen); - } - TAOS_CHECK_RETURN(cfgSetItem(pCfg, "logDir", tsLogDir, CFG_STYPE_DEFAULT, true)); - } - } - return 0; -} - int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) { if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0; int32_t code = osUpdate(); @@ -1102,10 +1077,13 @@ static void taosWriteLog(SLogBuff *pLogBuf) { pLogBuf->writeInterval = 0; } -#define LOG_ROTATE_INTERVAL 1800 // seconds -#ifndef LOG_ROTATE_BOOT -#define LOG_ROTATE_BOOT 180 // seconds +#define LOG_ROTATE_INTERVAL 1800 +#ifdef BUILD_TEST +#define LOG_ROTATE_BOOT 5 +#else +#define LOG_ROTATE_BOOT 180 #endif + static void *taosLogRotateFunc(void *param) { setThreadName("logRotate"); int32_t code = 0; diff --git a/tools/shell/src/shellArguments.c b/tools/shell/src/shellArguments.c index 390ee14ed3..44686cc5f9 100644 --- a/tools/shell/src/shellArguments.c +++ b/tools/shell/src/shellArguments.c @@ -159,8 +159,6 @@ static void shellParseArgsUseArgp(int argc, char *argv[]) { #define ARGP_ERR_UNKNOWN E2BIG #endif -extern char* tsLogOutput; - static int32_t shellParseSingleOpt(int32_t key, char *arg) { SShellArgs *pArgs = &shell.args;