diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 9ed6512352..6a0a09f9bd 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -821,9 +821,10 @@ int32_t monitorInit() { return code; } - if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) { + code = taosMulModeMkDir(tmpSlowLogPath, 0777, true); + if (code != 0) { tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr()); - return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); + return code; } if (tsem2_init(&monitorSem, 0, 0) != 0) { diff --git a/source/common/src/cos.c b/source/common/src/cos.c index f02130d468..064e06eb43 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -1881,7 +1881,6 @@ void s3EvictCache(const char *path, long object_size) { // 1, list data files' atime under dir(path) tdbDirPtr pDir = taosOpenDir(dir_name); if (pDir == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); vError("failed to open %s since %s", dir_name, terrstr()); } SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile)); diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 55a9bb06d9..8e1c4a2d2f 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -1125,7 +1125,7 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) { TdDirPtr pDir = taosOpenDir(path); if (NULL == pDir) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } TdDirEntryPtr pDirEntry; while ((pDirEntry = taosReadDir(pDir)) != NULL) { diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 4793a8951a..465968dc50 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -599,7 +599,7 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) { // copy file to dst TdDirPtr pDir = taosOpenDir(src); if (pDir == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _ERROR; } @@ -1428,7 +1428,7 @@ int32_t chkpPreBuildDir(char* path, int64_t chkpId, char** chkpDir, char** chkpI code = taosMulModeMkDir(pChkpDir, 0755, true); if (code != 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to prepare checkpoint dir, path:%s, reason:%s", path, tstrerror(code)); goto _EXIT; } @@ -4633,7 +4633,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { TdDirPtr pDir = taosOpenDir(p->buf); if (pDir == NULL) { (void)taosThreadRwlockUnlock(&p->rwLock); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } TdDirEntryPtr de = NULL; diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index 916aee4e6e..05dcab3aae 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -1224,7 +1224,7 @@ static int32_t uploadCheckpointToS3(const char* id, const char* path) { TdDirPtr pDir = taosOpenDir(path); if (pDir == NULL) { - return TAOS_SYSTEM_ERROR(errno); + return terrno; } TdDirEntryPtr de = NULL; diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index 0390422623..eb222efce6 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -271,7 +271,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) { int32_t code = 0; TdDirPtr pDir = taosOpenDir(pSnapFile->path); if (NULL == pDir) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("%s failed to open %s, reason:%s", STREAM_STATE_TRANSFER, pSnapFile->path, tstrerror(code)); return code; } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index b0f32136a3..4a5ad9d663 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -1136,7 +1136,7 @@ int tdbPagerRestoreJournals(SPager *pPager) { tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName); if (pDir == NULL) { tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno)); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } SArray *pTxnList = taosArrayInit(16, sizeof(int64_t)); @@ -1182,7 +1182,7 @@ int tdbPagerRollback(SPager *pPager) { tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName); if (pDir == NULL) { tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno)); - return terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; } while ((pDirEntry = tdbReadDir(pDir)) != NULL) { diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 0eb011113a..fb30dd3376 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -403,7 +403,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { regfree(&logRegPattern); regfree(&idxRegPattern); wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno)); - TAOS_RETURN(TSDB_CODE_FAILED); + return terrno; } SArray* actualLog = taosArrayInit(8, sizeof(SWalFileInfo)); @@ -422,7 +422,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { regfree(&idxRegPattern); (void)taosCloseDir(&pDir); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + return terrno; } } } diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 9f3908183e..d233a4fe0e 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -145,7 +145,10 @@ int32_t taosMulMkDir(const char *dirname) { char *pos = temp; int32_t code = 0; #ifdef WINDOWS - taosRealPath(dirname, temp, sizeof(temp)); + code = taosRealPath(dirname, temp, sizeof(temp)); + if(code != 0) { + return code; + } if (temp[1] == ':') pos += 3; #else (void)strcpy(temp, dirname); @@ -207,7 +210,10 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { char *pos = temp; int32_t code = 0; #ifdef WINDOWS - taosRealPath(dirname, temp, sizeof(temp)); + code = taosRealPath(dirname, temp, sizeof(temp)); + if(code != 0) { + return code; + } if (temp[1] == ':') pos += 3; #else (void)strcpy(temp, dirname); @@ -430,6 +436,9 @@ TdDirPtr taosOpenDir(const char *dirname) { HANDLE hFind; TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir)); + if(pDir == NULL) { + return NULL; + } strcpy(szFind, dirname); strcat(szFind, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录 @@ -437,6 +446,8 @@ TdDirPtr taosOpenDir(const char *dirname) { pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData)); if (INVALID_HANDLE_VALUE == pDir->hFind) { taosMemoryFree(pDir); + DWORD errorCode = GetLastError(); + terrno = TAOS_SYSTEM_ERROR(errorCode); return NULL; } return pDir; @@ -444,6 +455,11 @@ TdDirPtr taosOpenDir(const char *dirname) { DIR *pDir = opendir(dirname); if (pDir == NULL) return NULL; TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir)); + if (dirPtr == NULL) { + (void)closedir(pDir); + terrno = TAOS_SYSTEM_ERROR(errno); + return NULL; + } dirPtr->dirEntryPtr = (TdDirEntryPtr) & (dirPtr->dirEntry1); dirPtr->pDir = pDir; return dirPtr; @@ -506,22 +522,30 @@ char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) { } int32_t taosCloseDir(TdDirPtr *ppDir) { + int32_t code = 0; if (ppDir == NULL || *ppDir == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } #ifdef WINDOWS - FindClose((*ppDir)->hFind); + if(!FindClose((*ppDir)->hFind)) { + terrno = TAOS_SYSTEM_ERROR(GetLastError()); + return terrno; + } taosMemoryFree(*ppDir); *ppDir = NULL; return 0; #elif defined(DARWIN) - closedir((*ppDir)->pDir); + code = closedir((*ppDir)->pDir); + if (-1 == code) { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } taosMemoryFree(*ppDir); *ppDir = NULL; return 0; #else - int32_t code = closedir((DIR *)*ppDir); + code = closedir((DIR *)*ppDir); *ppDir = NULL; if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index afa048f0ac..b1f4ed0ed3 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -1227,8 +1227,8 @@ static void checkRegexCache(void* param, void* tmrId) { if(sRegexCache.exit) { goto _exit; } - bool ret = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId); - if (!ret) { + bool stopped = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId); + if (stopped) { uError("failed to reset regex cache timer"); goto _exit; }