fix: stat atime/mtime and check return of log output

This commit is contained in:
kailixu 2024-11-30 22:53:45 +08:00
parent 0303480f01
commit 9de36b0a19
2 changed files with 9 additions and 6 deletions

View File

@ -1027,15 +1027,18 @@ static int32_t taosSetClientLogCfg(SConfig *pCfg) {
if ((pEnd = strrchr(pLog, '/')) || (pEnd = strrchr(pLog, '\\'))) {
int32_t pathLen = POINTER_DISTANCE(pEnd, pLog) + 1;
if (*pLog == '/' || *pLog == '\\') {
tstrncpy(tsLogDir, pLog, TMIN(pathLen, PATH_MAX));
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;
}
tstrncpy(tsLogDir + len, pLog, TMIN(PATH_MAX - len - 1, pathLen));
int32_t remain = PATH_MAX - len - 1;
if (remain < pathLen) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
tstrncpy(tsLogDir + len, pLog, pathLen);
}
cfgSetItem(pCfg, "logDir", tsLogDir, CFG_STYPE_DEFAULT, true);
TAOS_CHECK_RETURN(cfgSetItem(pCfg, "logDir", tsLogDir, CFG_STYPE_DEFAULT, true));
}
}
}

View File

@ -292,11 +292,11 @@ int32_t taosStatFile(const char *path, int64_t *size, int64_t *mtime, int64_t *a
}
if (mtime != NULL) {
*mtime = fileStat.st_mtim.tv_sec;
*mtime = fileStat.st_mtime;
}
if (atime != NULL) {
*atime = fileStat.st_atim.tv_sec;
*atime = fileStat.st_atime;
}
return 0;
@ -960,7 +960,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int64_t *mtime) {
}
if (mtime != NULL) {
*mtime = fileStat.st_mtim.tv_sec;
*mtime = fileStat.st_mtime;
}
return 0;