fix: compile problem of log rotate on windows

This commit is contained in:
kailixu 2024-12-01 14:51:12 +08:00
parent 76aea0ddb9
commit 57afdc6612
6 changed files with 36 additions and 33 deletions

View File

@ -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})

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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;

View File

@ -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;