fix: add function return code validation
This commit is contained in:
parent
7718d5e042
commit
9e8d94a69a
|
@ -54,7 +54,7 @@ extern SDiskSpace tsDataSpace;
|
|||
extern SDiskSpace tsLogSpace;
|
||||
extern SDiskSpace tsTempSpace;
|
||||
|
||||
void osDefaultInit();
|
||||
int32_t osDefaultInit();
|
||||
void osUpdate();
|
||||
void osCleanup();
|
||||
|
||||
|
@ -66,7 +66,7 @@ bool osLogSpaceSufficient();
|
|||
bool osDataSpaceSufficient();
|
||||
bool osTempSpaceSufficient();
|
||||
|
||||
void osSetTimezone(const char *timezone);
|
||||
int32_t osSetTimezone(const char *timezone);
|
||||
void osSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
void osSetProcPath(int32_t argc, char **argv);
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ enum TdTimezone {
|
|||
};
|
||||
|
||||
void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone);
|
||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
|
||||
int32_t taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -801,9 +801,8 @@ int32_t monitorInit() {
|
|||
}
|
||||
|
||||
if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr());
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (tsem2_init(&monitorSem, 0, 0) != 0) {
|
||||
|
|
|
@ -1306,7 +1306,6 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
taosSetAllDebugFlag(pCfg, cfgGetItem(pCfg, "debugFlag")->i32);
|
||||
|
||||
if (taosMulModeMkDir(tsLogDir, 0777, true) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
printf("failed to create dir:%s since %s", tsLogDir, terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
|
|
|
@ -244,7 +244,6 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
pWrapper = &pDnode->wrappers[ntype];
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
dmReleaseWrapper(pWrapper);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -314,7 +313,6 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
pWrapper = &pDnode->wrappers[ntype];
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
|||
SDnode *pDnode = pWrapper->pDnode;
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -328,7 +328,6 @@ int32_t dmUpdateEncryptKey(char *key, bool toLogFile) {
|
|||
terrno = 0;
|
||||
|
||||
if (taosMkDir(folder) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to create dir:%s since %s", folder, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
|
|
@ -454,7 +454,6 @@ static int32_t mndCreateDir(SMnode *pMnode, const char *path) {
|
|||
}
|
||||
|
||||
if (taosMkDir(pMnode->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i
|
|||
|
||||
ret = taosMulModeMkDir(dbname, 0755, false);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
#ifdef USE_MAINDB
|
||||
|
|
|
@ -103,7 +103,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
|
|||
|
||||
tstrncpy(pWal->path, path, sizeof(pWal->path));
|
||||
if (taosMkDir(pWal->path) != 0) {
|
||||
wError("vgId:%d, path:%s, failed to create directory since %s", pWal->cfg.vgId, pWal->path, strerror(errno));
|
||||
wError("vgId:%d, path:%s, failed to create directory since %s", pWal->cfg.vgId, pWal->path, tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ void taosRemoveDir(const char *dirname) {
|
|||
}
|
||||
}
|
||||
|
||||
taosCloseDir(&pDir);
|
||||
(void)taosCloseDir(&pDir);
|
||||
(void)rmdir(dirname);
|
||||
|
||||
// printf("dir:%s is removed\n", dirname);
|
||||
|
@ -127,8 +127,13 @@ int32_t taosMkDir(const char *dirname) {
|
|||
#else
|
||||
int32_t code = mkdir(dirname, 0755);
|
||||
#endif
|
||||
if (code < 0 && errno == EEXIST) {
|
||||
return 0;
|
||||
if (-1 == code) {
|
||||
if (errno == EEXIST) {
|
||||
return 0;
|
||||
} else {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = terrno;
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -143,7 +148,7 @@ int32_t taosMulMkDir(const char *dirname) {
|
|||
taosRealPath(dirname, temp, sizeof(temp));
|
||||
if (temp[1] == ':') pos += 3;
|
||||
#else
|
||||
strcpy(temp, dirname);
|
||||
(void)strcpy(temp, dirname);
|
||||
#endif
|
||||
|
||||
if (taosDirExist(temp)) return code;
|
||||
|
@ -165,7 +170,7 @@ int32_t taosMulMkDir(const char *dirname) {
|
|||
code = mkdir(temp, 0755);
|
||||
#endif
|
||||
if (code < 0 && errno != EEXIST) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
*pos = TD_DIRSEP[0];
|
||||
|
@ -181,7 +186,7 @@ int32_t taosMulMkDir(const char *dirname) {
|
|||
code = mkdir(temp, 0755);
|
||||
#endif
|
||||
if (code < 0 && errno != EEXIST) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +199,10 @@ int32_t taosMulMkDir(const char *dirname) {
|
|||
}
|
||||
|
||||
int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
||||
if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1;
|
||||
if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
char temp[TDDIRMAXLEN];
|
||||
char *pos = temp;
|
||||
int32_t code = 0;
|
||||
|
@ -202,14 +210,18 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
|||
taosRealPath(dirname, temp, sizeof(temp));
|
||||
if (temp[1] == ':') pos += 3;
|
||||
#else
|
||||
strcpy(temp, dirname);
|
||||
(void)strcpy(temp, dirname);
|
||||
#endif
|
||||
|
||||
if (taosDirExist(temp)) {
|
||||
if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||
return 0;
|
||||
}
|
||||
return chmod(temp, mode);
|
||||
code = chmod(temp, mode);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
if (strncmp(temp, TD_DIRSEP, 1) == 0) {
|
||||
|
@ -229,8 +241,8 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
|||
code = mkdir(temp, mode);
|
||||
#endif
|
||||
if (code < 0 && errno != EEXIST) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
*pos = TD_DIRSEP[0];
|
||||
}
|
||||
|
@ -245,8 +257,8 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
|||
code = mkdir(temp, mode);
|
||||
#endif
|
||||
if (code < 0 && errno != EEXIST) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,10 +266,14 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
|||
if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||
return 0;
|
||||
}
|
||||
return chmod(temp, mode);
|
||||
}
|
||||
|
||||
return chmod(temp, mode);
|
||||
code = chmod(temp, mode);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
|
||||
|
@ -271,7 +287,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
|
|||
if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue;
|
||||
|
||||
char filename[1024];
|
||||
snprintf(filename, sizeof(filename), "%s/%s", dirname, taosGetDirEntryName(de));
|
||||
(void)snprintf(filename, sizeof(filename), "%s/%s", dirname, taosGetDirEntryName(de));
|
||||
if (taosDirEntryIsDir(de)) {
|
||||
continue;
|
||||
} else {
|
||||
|
@ -299,34 +315,25 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
|
|||
}
|
||||
}
|
||||
|
||||
taosCloseDir(&pDir);
|
||||
rmdir(dirname);
|
||||
(void)taosCloseDir(&pDir);
|
||||
(void)rmdir(dirname);
|
||||
}
|
||||
|
||||
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
|
||||
wordexp_t full_path;
|
||||
switch (wordexp(dirname, &full_path, 0)) {
|
||||
int32_t code = wordexp(dirname, &full_path, 0);
|
||||
switch (code) {
|
||||
case 0:
|
||||
break;
|
||||
case WRDE_NOSPACE:
|
||||
wordfree(&full_path);
|
||||
// printf("failed to expand path:%s since Out of memory\n", dirname);
|
||||
return -1;
|
||||
case WRDE_BADCHAR:
|
||||
// printf("failed to expand path:%s since illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }\n",
|
||||
// dirname);
|
||||
return -1;
|
||||
case WRDE_SYNTAX:
|
||||
// printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched
|
||||
// quotes\n", dirname);
|
||||
return -1;
|
||||
// FALL THROUGH
|
||||
default:
|
||||
// printf("failed to expand path:%s since %s\n", dirname, strerror(errno));
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
|
||||
strncpy(outname, full_path.we_wordv[0], maxlen);
|
||||
(void)strncpy(outname, full_path.we_wordv[0], maxlen);
|
||||
}
|
||||
|
||||
wordfree(&full_path);
|
||||
|
@ -343,21 +350,23 @@ int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
|
|||
#endif
|
||||
if (strlen(tmp) < maxlen) {
|
||||
if (realPath == NULL) {
|
||||
strncpy(dirname, tmp, maxlen);
|
||||
(void)strncpy(dirname, tmp, maxlen);
|
||||
} else {
|
||||
strncpy(realPath, tmp, maxlen);
|
||||
(void)strncpy(realPath, tmp, maxlen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
||||
return terrno;
|
||||
}
|
||||
|
||||
bool taosIsDir(const char *dirname) {
|
||||
TdDirPtr pDir = taosOpenDir(dirname);
|
||||
if (pDir != NULL) {
|
||||
taosCloseDir(&pDir);
|
||||
(void)taosCloseDir(&pDir);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -410,6 +419,7 @@ char *taosDirEntryBaseName(char *name) {
|
|||
|
||||
TdDirPtr taosOpenDir(const char *dirname) {
|
||||
if (dirname == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -436,12 +446,17 @@ TdDirPtr taosOpenDir(const char *dirname) {
|
|||
dirPtr->pDir = pDir;
|
||||
return dirPtr;
|
||||
#else
|
||||
return (TdDirPtr)opendir(dirname);
|
||||
TdDirPtr ptr = (TdDirPtr)opendir(dirname);
|
||||
if (NULL == ptr) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return ptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
|
||||
if (pDir == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
|
@ -456,7 +471,13 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
|
|||
return NULL;
|
||||
}
|
||||
#else
|
||||
return (TdDirEntryPtr)readdir((DIR *)pDir);
|
||||
errno = 0;
|
||||
terrno = 0;
|
||||
TdDirEntryPtr p = (TdDirEntryPtr)readdir((DIR *)pDir);
|
||||
if (NULL == p && errno) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -484,7 +505,8 @@ char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
|
|||
|
||||
int32_t taosCloseDir(TdDirPtr *ppDir) {
|
||||
if (ppDir == NULL || *ppDir == NULL) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
FindClose((*ppDir)->hFind);
|
||||
|
@ -497,8 +519,12 @@ int32_t taosCloseDir(TdDirPtr *ppDir) {
|
|||
*ppDir = NULL;
|
||||
return 0;
|
||||
#else
|
||||
closedir((DIR *)*ppDir);
|
||||
int32_t code = closedir((DIR *)*ppDir);
|
||||
*ppDir = NULL;
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -45,11 +45,16 @@ char tsAVX2Supported = 0;
|
|||
char tsFMASupported = 0;
|
||||
char tsAVX512Supported = 0;
|
||||
|
||||
void osDefaultInit() {
|
||||
int32_t osDefaultInit() {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
taosSeedRand(taosSafeRand());
|
||||
taosGetSystemLocale(tsLocale, tsCharset);
|
||||
taosGetSystemTimezone(tsTimezoneStr, &tsTimezone);
|
||||
taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone);
|
||||
code = taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
taosGetSystemInfo();
|
||||
|
||||
// deadlock in query
|
||||
|
@ -65,33 +70,35 @@ void osDefaultInit() {
|
|||
tmpDir = getenv("temp");
|
||||
}
|
||||
if (tmpDir != NULL) {
|
||||
strcpy(tsTempDir, tmpDir);
|
||||
(void)strcpy(tsTempDir, tmpDir);
|
||||
}
|
||||
strcpy(tsOsName, "Windows");
|
||||
(void)strcpy(tsOsName, "Windows");
|
||||
#elif defined(_TD_DARWIN_64)
|
||||
strcpy(tsOsName, "Darwin");
|
||||
(void)strcpy(tsOsName, "Darwin");
|
||||
#else
|
||||
strcpy(tsOsName, "Linux");
|
||||
(void)strcpy(tsOsName, "Linux");
|
||||
#endif
|
||||
if (configDir[0] == 0) {
|
||||
strcpy(configDir, TD_CFG_DIR_PATH);
|
||||
(void)strcpy(configDir, TD_CFG_DIR_PATH);
|
||||
}
|
||||
strcpy(tsDataDir, TD_DATA_DIR_PATH);
|
||||
strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
||||
(void)strcpy(tsDataDir, TD_DATA_DIR_PATH);
|
||||
(void)strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
||||
if(strlen(tsTempDir) == 0){
|
||||
strcpy(tsTempDir, TD_TMP_DIR_PATH);
|
||||
(void)strcpy(tsTempDir, TD_TMP_DIR_PATH);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void osUpdate() {
|
||||
if (tsLogDir[0] != 0) {
|
||||
taosGetDiskSize(tsLogDir, &tsLogSpace.size);
|
||||
(void)taosGetDiskSize(tsLogDir, &tsLogSpace.size);
|
||||
}
|
||||
if (tsDataDir[0] != 0) {
|
||||
taosGetDiskSize(tsDataDir, &tsDataSpace.size);
|
||||
(void)taosGetDiskSize(tsDataDir, &tsDataSpace.size);
|
||||
}
|
||||
if (tsTempDir[0] != 0) {
|
||||
taosGetDiskSize(tsTempDir, &tsTempSpace.size);
|
||||
(void)taosGetDiskSize(tsTempDir, &tsTempSpace.size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,11 +116,11 @@ bool osDataSpaceSufficient() { return tsDataSpace.size.avail > tsDataSpace.reser
|
|||
|
||||
bool osTempSpaceSufficient() { return tsTempSpace.size.avail > tsTempSpace.reserved; }
|
||||
|
||||
void osSetTimezone(const char *tz) { taosSetSystemTimezone(tz, tsTimezoneStr, &tsDaylight, &tsTimezone); }
|
||||
int32_t osSetTimezone(const char *tz) { return taosSetSystemTimezone(tz, tsTimezoneStr, &tsDaylight, &tsTimezone); }
|
||||
|
||||
void osSetSystemLocale(const char *inLocale, const char *inCharSet) {
|
||||
memcpy(tsLocale, inLocale, strlen(inLocale) + 1);
|
||||
memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1);
|
||||
(void)memcpy(tsLocale, inLocale, strlen(inLocale) + 1);
|
||||
(void)memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1);
|
||||
}
|
||||
|
||||
void osSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; }
|
||||
|
|
|
@ -90,24 +90,24 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha
|
|||
|
||||
char tmpPath[PATH_MAX];
|
||||
int32_t len = strlen(inputTmpDir);
|
||||
memcpy(tmpPath, inputTmpDir, len);
|
||||
(void)memcpy(tmpPath, inputTmpDir, len);
|
||||
static uint64_t seqId = 0;
|
||||
|
||||
if (tmpPath[len - 1] != '/') {
|
||||
tmpPath[len++] = '/';
|
||||
}
|
||||
|
||||
strcpy(tmpPath + len, TD_TMP_FILE_PREFIX);
|
||||
(void)strcpy(tmpPath + len, TD_TMP_FILE_PREFIX);
|
||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
||||
strcat(tmpPath, fileNamePrefix);
|
||||
strcat(tmpPath, "-%d-%s");
|
||||
(void)strcat(tmpPath, fileNamePrefix);
|
||||
(void)strcat(tmpPath, "-%d-%s");
|
||||
}
|
||||
|
||||
char rand[32] = {0};
|
||||
|
||||
sprintf(rand, "%" PRIu64, atomic_add_fetch_64(&seqId, 1));
|
||||
(void)sprintf(rand, "%" PRIu64, atomic_add_fetch_64(&seqId, 1));
|
||||
|
||||
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
|
||||
(void)snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -123,6 +123,7 @@ int64_t taosCopyFile(const char *from, const char *to) {
|
|||
char buffer[4096];
|
||||
int64_t size = 0;
|
||||
int64_t bytes;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
// fidfrom = open(from, O_RDONLY);
|
||||
TdFilePtr pFileFrom = taosOpenFile(from, TD_FILE_READ);
|
||||
|
@ -143,7 +144,7 @@ int64_t taosCopyFile(const char *from, const char *to) {
|
|||
if (bytes < sizeof(buffer)) break;
|
||||
}
|
||||
|
||||
int code = taosFsyncFile(pFileTo);
|
||||
code = taosFsyncFile(pFileTo);
|
||||
|
||||
taosCloseFile(&pFileFrom);
|
||||
taosCloseFile(&pFileTo);
|
||||
|
@ -154,10 +155,12 @@ int64_t taosCopyFile(const char *from, const char *to) {
|
|||
return size;
|
||||
|
||||
_err:
|
||||
|
||||
if (pFileFrom != NULL) taosCloseFile(&pFileFrom);
|
||||
if (pFileTo != NULL) taosCloseFile(&pFileTo);
|
||||
/* coverity[+retval] */
|
||||
taosRemoveFile(to);
|
||||
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
@ -301,11 +304,15 @@ FILE *taosOpenFileForStream(const char *path, int32_t tdFileOptions) {
|
|||
} else {
|
||||
mode = (tdFileOptions & TD_FILE_TEXT) ? "rt+" : "rb+";
|
||||
}
|
||||
ASSERT(!(tdFileOptions & TD_FILE_EXCL));
|
||||
if (tdFileOptions & TD_FILE_EXCL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
return fopen(path, mode);
|
||||
FILE* f = fopen(path, mode);
|
||||
if (NULL == f) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -653,6 +660,9 @@ int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) {
|
|||
access |= (tdFileOptions & TD_FILE_CLOEXEC) ? O_CLOEXEC : 0;
|
||||
|
||||
int fd = open(path, access, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (-1 == fd) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -1060,14 +1070,14 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
|
|||
#ifdef WINDOWS
|
||||
if (hFile != NULL) CloseHandle(hFile);
|
||||
#else
|
||||
if (fd >= 0) close(fd);
|
||||
if (fd >= 0) (void)close(fd);
|
||||
#endif
|
||||
if (fp != NULL) fclose(fp);
|
||||
if (fp != NULL) (void)fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockInit(&(pFile->rwlock), NULL);
|
||||
(void)taosThreadRwlockInit(&(pFile->rwlock), NULL);
|
||||
#endif
|
||||
pFile->fp = fp;
|
||||
pFile->refId = 0;
|
||||
|
@ -1082,9 +1092,15 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
|
|||
// Remove it instantly, so when the program exits normally/abnormally, the file
|
||||
// will be automatically remove by OS.
|
||||
if (tdFileOptions & TD_FILE_AUTO_DEL) {
|
||||
unlink(path);
|
||||
if (-1 == unlink(path)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
(void)close(fd);
|
||||
taosMemoryFree(pFile);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return pFile;
|
||||
}
|
||||
|
||||
|
@ -1094,11 +1110,11 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
|
|||
return 0;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockWrlock(&((*ppFile)->rwlock));
|
||||
(void)taosThreadRwlockWrlock(&((*ppFile)->rwlock));
|
||||
#endif
|
||||
if ((*ppFile)->fp != NULL) {
|
||||
fflush((*ppFile)->fp);
|
||||
fclose((*ppFile)->fp);
|
||||
(void)fflush((*ppFile)->fp);
|
||||
(void)fclose((*ppFile)->fp);
|
||||
(*ppFile)->fp = NULL;
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
|
@ -1113,16 +1129,20 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
|
|||
// warning: never fsync silently in base lib
|
||||
/*fsync((*ppFile)->fd);*/
|
||||
code = close((*ppFile)->fd);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
(*ppFile)->fd = -1;
|
||||
#endif
|
||||
}
|
||||
(*ppFile)->refId = 0;
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&((*ppFile)->rwlock));
|
||||
taosThreadRwlockDestroy(&((*ppFile)->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&((*ppFile)->rwlock));
|
||||
(void)taosThreadRwlockDestroy(&((*ppFile)->rwlock));
|
||||
#endif
|
||||
taosMemoryFree(*ppFile);
|
||||
*ppFile = NULL;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1155,20 +1175,28 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
|||
}
|
||||
#else
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
#endif
|
||||
ASSERT(pFile->fd >= 0); // Please check if you have closed the file.
|
||||
if (pFile->fd < 0) {
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
}
|
||||
int32_t code = 0;
|
||||
int64_t ret = pread(pFile->fd, buf, count, offset);
|
||||
if (-1 == ret) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
#endif
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
|
||||
terrno = code;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,9 @@ void taosSsleep(int32_t s) {
|
|||
#ifdef WINDOWS
|
||||
Sleep(1000 * s);
|
||||
#else
|
||||
sleep(s);
|
||||
while (s > 0) {
|
||||
s = sleep(s);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -35,7 +37,7 @@ void taosMsleep(int32_t ms) {
|
|||
#ifdef WINDOWS
|
||||
Sleep(ms);
|
||||
#else
|
||||
usleep(ms * 1000);
|
||||
(void)usleep(ms * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -51,6 +53,6 @@ void taosUsleep(int32_t us) {
|
|||
WaitForSingleObject(timer, INFINITE);
|
||||
CloseHandle(timer);
|
||||
#else
|
||||
usleep(us);
|
||||
(void)usleep(us);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ void taos_block_sigalrm(void) {
|
|||
|
||||
static void taosDeleteTimer(void *tharg) {
|
||||
timer_t *pTimer = tharg;
|
||||
timer_delete(*pTimer);
|
||||
(void)timer_delete(*pTimer);
|
||||
}
|
||||
|
||||
static TdThread timerThread;
|
||||
|
@ -90,9 +90,9 @@ static volatile bool stopTimer = false;
|
|||
static void *taosProcessAlarmSignal(void *tharg) {
|
||||
// Block the signal
|
||||
sigset_t sigset;
|
||||
sigemptyset(&sigset);
|
||||
sigaddset(&sigset, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &sigset, NULL);
|
||||
(void)sigemptyset(&sigset);
|
||||
(void)sigaddset(&sigset, SIGALRM);
|
||||
(void)sigprocmask(SIG_BLOCK, &sigset, NULL);
|
||||
void (*callback)(int) = tharg;
|
||||
|
||||
struct sigevent sevent = {{0}};
|
||||
|
@ -110,7 +110,8 @@ static void *taosProcessAlarmSignal(void *tharg) {
|
|||
sevent.sigev_signo = SIGALRM;
|
||||
|
||||
if (timer_create(CLOCK_REALTIME, &sevent, &timerId) == -1) {
|
||||
// printf("Failed to create timer");
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosThreadCleanupPush(taosDeleteTimer, &timerId);
|
||||
|
@ -122,15 +123,17 @@ static void *taosProcessAlarmSignal(void *tharg) {
|
|||
ts.it_interval.tv_sec = 0;
|
||||
ts.it_interval.tv_nsec = 1000000 * MSECONDS_PER_TICK;
|
||||
|
||||
if (timer_settime(timerId, 0, &ts, NULL)) {
|
||||
// printf("Failed to init timer");
|
||||
if (-1 == timer_settime(timerId, 0, &ts, NULL)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
break;
|
||||
}
|
||||
|
||||
int signo;
|
||||
int32_t code = 0;
|
||||
while (!stopTimer) {
|
||||
if (sigwait(&sigset, &signo)) {
|
||||
// printf("Failed to wait signal: number %d", signo);
|
||||
code = sigwait(&sigset, &signo);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
continue;
|
||||
}
|
||||
/* //printf("Signal handling: number %d ......\n", signo); */
|
||||
|
@ -178,14 +181,12 @@ int taosInitTimer(void (*callback)(int), int ms) {
|
|||
#else
|
||||
stopTimer = false;
|
||||
TdThreadAttr tattr;
|
||||
taosThreadAttrInit(&tattr);
|
||||
(void)taosThreadAttrInit(&tattr);
|
||||
int code = taosThreadCreate(&timerThread, &tattr, taosProcessAlarmSignal, callback);
|
||||
taosThreadAttrDestroy(&tattr);
|
||||
(void)taosThreadAttrDestroy(&tattr);
|
||||
if (code != 0) {
|
||||
// printf("failed to create timer thread");
|
||||
return -1;
|
||||
} else {
|
||||
// printf("timer thread:0x%08" PRIx64 " is created", taosGetPthreadId(timerThread));
|
||||
return TAOS_SYSTEM_ERROR(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -210,7 +211,7 @@ void taosUninitTimer() {
|
|||
stopTimer = true;
|
||||
|
||||
// printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread));
|
||||
taosThreadJoin(timerThread, NULL);
|
||||
(void)taosThreadJoin(timerThread, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -742,12 +742,20 @@ char *tz_win[554][2] = {{"Asia/Shanghai", "China Standard Time"},
|
|||
|
||||
static int isdst_now = 0;
|
||||
|
||||
void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight,
|
||||
int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight,
|
||||
enum TdTimezone *tsTimezone) {
|
||||
if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) return;
|
||||
if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
size_t len = strlen(inTimezoneStr);
|
||||
char *buf = taosMemoryCalloc(len + 1, 1);
|
||||
if (len >= TD_TIMEZONE_LEN) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
char buf[TD_TIMEZONE_LEN] = {0};
|
||||
for (int32_t i = 0; i < len; i++) {
|
||||
if (inTimezoneStr[i] == ' ' || inTimezoneStr[i] == '(') {
|
||||
buf[i] = 0;
|
||||
|
@ -813,17 +821,22 @@ void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8
|
|||
*outDaylight = isdst_now;
|
||||
|
||||
#else
|
||||
setenv("TZ", buf, 1);
|
||||
code = setenv("TZ", buf, 1);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
tzset();
|
||||
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
||||
*tsTimezone = tz;
|
||||
tz += isdst_now;
|
||||
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[isdst_now], tz >= 0 ? "+" : "-", abs(tz));
|
||||
(void)sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[isdst_now], tz >= 0 ? "+" : "-", abs(tz));
|
||||
*outDaylight = isdst_now;
|
||||
|
||||
#endif
|
||||
|
||||
taosMemoryFree(buf);
|
||||
return code;
|
||||
}
|
||||
|
||||
void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
||||
|
@ -914,7 +927,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
{
|
||||
int n = readlink("/etc/localtime", buf, sizeof(buf)-1);
|
||||
if (n < 0) {
|
||||
printf("read /etc/localtime error, reason:%s", strerror(errno));
|
||||
(void)printf("read /etc/localtime error, reason:%s", strerror(errno));
|
||||
|
||||
if (taosCheckExistFile("/etc/timezone")) {
|
||||
/*
|
||||
|
@ -924,7 +937,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
*/
|
||||
time_t tx1 = taosGetTimestampSec();
|
||||
struct tm tm1;
|
||||
taosLocalTime(&tx1, &tm1, NULL);
|
||||
(void)taosLocalTime(&tx1, &tm1, NULL);
|
||||
/* load time zone string from /etc/timezone */
|
||||
// FILE *f = fopen("/etc/timezone", "r");
|
||||
errno = 0;
|
||||
|
@ -933,12 +946,12 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
if (pFile != NULL) {
|
||||
int len = taosReadFile(pFile, buf, 64);
|
||||
if (len < 64 && taosGetErrorFile(pFile)) {
|
||||
taosCloseFile(&pFile);
|
||||
printf("read /etc/timezone error, reason:%s", strerror(errno));
|
||||
(void)taosCloseFile(&pFile);
|
||||
(void)printf("read /etc/timezone error, reason:%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
char *lineEnd = strstr(buf, "\n");
|
||||
|
@ -948,7 +961,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
|
||||
// for CentOS system, /etc/timezone does not exist. Ignore the TZ environment variables
|
||||
if (strlen(buf) > 0) {
|
||||
setenv("TZ", buf, 1);
|
||||
(void)setenv("TZ", buf, 1);
|
||||
}
|
||||
}
|
||||
// get and set default timezone
|
||||
|
@ -970,10 +983,10 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
* Asia/Shanghai (CST, +0800)
|
||||
* Europe/London (BST, +0100)
|
||||
*/
|
||||
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-",
|
||||
(void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-",
|
||||
abs(tz));
|
||||
} else {
|
||||
printf("There is not /etc/timezone.\n");
|
||||
(void)printf("There is not /etc/timezone.\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -981,7 +994,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
|
||||
char *zi = strstr(buf, "zoneinfo");
|
||||
if (!zi) {
|
||||
printf("parsing /etc/localtime failed");
|
||||
(void)printf("parsing /etc/localtime failed");
|
||||
return;
|
||||
}
|
||||
tz = zi + strlen("zoneinfo") + 1;
|
||||
|
@ -1000,7 +1013,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
// return;
|
||||
// }
|
||||
|
||||
setenv("TZ", tz, 1);
|
||||
(void)setenv("TZ", tz, 1);
|
||||
tzset();
|
||||
}
|
||||
|
||||
|
@ -1011,7 +1024,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
*/
|
||||
time_t tx1 = taosGetTimestampSec();
|
||||
struct tm tm1;
|
||||
taosLocalTime(&tx1, &tm1, NULL);
|
||||
(void)taosLocalTime(&tx1, &tm1, NULL);
|
||||
isdst_now = tm1.tm_isdst;
|
||||
|
||||
/*
|
||||
|
@ -1020,7 +1033,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
* Asia/Shanghai (CST, +0800)
|
||||
* Europe/London (BST, +0100)
|
||||
*/
|
||||
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
|
||||
(void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
|
||||
-timezone / 3600);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -136,8 +136,7 @@ static int32_t cfgCheckAndSetConf(SConfigItem *pItem, const char *conf) {
|
|||
static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
|
||||
char fullDir[PATH_MAX] = {0};
|
||||
if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to expand dir:%s since %s", inputDir, terrstr());
|
||||
uError("failed to expand dir:%s", inputDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue