diff --git a/include/os/os.h b/include/os/os.h index 9e5e9221e4..e3808065dd 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -129,6 +129,14 @@ extern int64_t tsRandErrDivisor; extern int64_t tsRandErrScope; extern threadlocal bool tsEnableRandErr; +#define TAOS_UNUSED(expr) (void)(expr) +#define TAOS_SKIP_ERROR(expr) \ + { \ + int32_t _code = terrno; \ + (void)(expr); \ + terrno = _code; \ + } + #ifdef __cplusplus } #endif diff --git a/include/os/osEnv.h b/include/os/osEnv.h index 5f7cdf44dc..f235d3f235 100644 --- a/include/os/osEnv.h +++ b/include/os/osEnv.h @@ -55,7 +55,7 @@ extern SDiskSpace tsLogSpace; extern SDiskSpace tsTempSpace; int32_t osDefaultInit(); -void osUpdate(); +int32_t osUpdate(); void osCleanup(); bool osLogSpaceAvailable(); diff --git a/include/os/osSemaphore.h b/include/os/osSemaphore.h index 5b46706790..d893f42740 100644 --- a/include/os/osSemaphore.h +++ b/include/os/osSemaphore.h @@ -27,11 +27,11 @@ extern "C" { // typedef struct tsem_s *tsem_t; typedef dispatch_semaphore_t tsem_t; -int tsem_init(tsem_t *sem, int pshared, unsigned int value); -int tsem_wait(tsem_t *sem); -int tsem_timewait(tsem_t *sim, int64_t milis); -int tsem_post(tsem_t *sem); -int tsem_destroy(tsem_t *sem); +int32_t tsem_init(tsem_t *sem, int pshared, unsigned int value); +int32_t tsem_wait(tsem_t *sem); +int32_t tsem_timewait(tsem_t *sim, int64_t milis); +int32_t tsem_post(tsem_t *sem); +int32_t tsem_destroy(tsem_t *sem); #define tsem2_t tsem_t #define tsem2_init tsem_init @@ -45,11 +45,11 @@ int tsem_destroy(tsem_t *sem); #define tsem_t HANDLE -int tsem_init(tsem_t *sem, int pshared, unsigned int value); -int tsem_wait(tsem_t *sem); -int tsem_timewait(tsem_t *sim, int64_t milis); -int tsem_post(tsem_t *sem); -int tsem_destroy(tsem_t *sem); +int32_t tsem_init(tsem_t *sem, int pshared, unsigned int value); +int32_t tsem_wait(tsem_t *sem); +int32_t tsem_timewait(tsem_t *sim, int64_t milis); +int32_t tsem_post(tsem_t *sem); +int32_t tsem_destroy(tsem_t *sem); #define tsem2_t tsem_t #define tsem2_init tsem_init @@ -61,11 +61,11 @@ int tsem_destroy(tsem_t *sem); #else #define tsem_t sem_t -#define tsem_init sem_init -int tsem_wait(tsem_t *sem); -int tsem_timewait(tsem_t *sim, int64_t milis); -#define tsem_post sem_post -#define tsem_destroy sem_destroy +int32_t tsem_init(tsem_t *sem, int pshared, unsigned int value); +int32_t tsem_wait(tsem_t *sem); +int32_t tsem_timewait(tsem_t *sim, int64_t milis); +int32_t tsem_post(tsem_t *sem); +int32_t tsem_destroy(tsem_t *sem); typedef struct tsem2_t { TdThreadMutex mutex; diff --git a/include/os/osString.h b/include/os/osString.h index 80755de031..a64fb34f1e 100644 --- a/include/os/osString.h +++ b/include/os/osString.h @@ -65,7 +65,10 @@ typedef enum { M2C = 0, C2M } ConvType; char *tstrdup(const char *src); int32_t taosUcs4len(TdUcs4 *ucs4); -int64_t taosStr2int64(const char *str); +int32_t taosStr2int64(const char *str, int64_t *val); +int32_t taosStr2int16(const char *str, int16_t *val); +int32_t taosStr2int32(const char *str, int32_t *val); +int32_t taosStr2int8(const char *str, int8_t *val); int32_t taosConvInit(void); void taosConvDestroy(); diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 5a76be1d1e..a6d8a6502f 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -39,15 +39,17 @@ int64_t taosGetOsUptime(); int32_t taosGetEmail(char *email, int32_t maxLen); int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen); int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores); -void taosGetCpuCores(float *numOfCores, bool physical); -void taosGetCpuUsage(double *cpu_system, double *cpu_engine); +int32_t taosGetCpuCores(float *numOfCores, bool physical); +int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine); int32_t taosGetCpuInstructions(char* sse42, char* avx, char* avx2, char* fma, char* avx512); int32_t taosGetTotalMemory(int64_t *totalKB); int32_t taosGetProcMemory(int64_t *usedKB); int32_t taosGetSysMemory(int64_t *usedKB); int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize); -void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes); -void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes); +int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes); +void taosSetDefaultProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes); +int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes); +void taosSetDefaultCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes); void taosKillSystem(); int32_t taosGetSystemUUID(char *uid, int32_t uidlen); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 4e909b0a1c..eb329192a2 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -156,6 +156,7 @@ int32_t taosGetErrSize(); #define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137) #define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138) #define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139) +#define TSDB_CODE_UNSUPPORT_OS TAOS_DEF_ERROR_CODE(0, 0x013A) //client #define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 484d9bb7e5..9b0a9299bf 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -2868,7 +2868,6 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly, int8_t s } int32_t code = tsem_init(¶m->sem, 0, 0); if (TSDB_CODE_SUCCESS != code) { - terrno = code; taosMemoryFree(param); return NULL; } @@ -2876,7 +2875,6 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly, int8_t s taosAsyncQueryImpl(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, source); code = tsem_wait(¶m->sem); if (TSDB_CODE_SUCCESS != code) { - terrno = code; taosMemoryFree(param); return NULL; } @@ -2907,7 +2905,6 @@ TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly, } int32_t code = tsem_init(¶m->sem, 0, 0); if (TSDB_CODE_SUCCESS != code) { - terrno = code; taosMemoryFree(param); return NULL; } @@ -2915,7 +2912,6 @@ TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly, taosAsyncQueryImplWithReqid(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, reqid); code = tsem_wait(¶m->sem); if (TSDB_CODE_SUCCESS != code) { - terrno = code; taosMemoryFree(param); return NULL; } diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index aee7299313..83af01a646 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -34,19 +34,19 @@ static void processFileInTheEnd(TdFilePtr pFile, char* path) { return; } if (taosFtruncateFile(pFile, 0) != 0) { - tscError("failed to truncate file:%s, errno:%d", path, terrno); + tscError("failed to truncate file:%s, terrno:%d", path, terrno); return; } if (taosUnLockFile(pFile) != 0) { - tscError("failed to unlock file:%s, errno:%d", path, terrno); + tscError("failed to unlock file:%s, terrno:%d", path, terrno); return; } if (taosCloseFile(&(pFile)) != 0) { - tscError("failed to close file:%s, errno:%d", path, errno); + tscError("failed to close file:%s, terrno:%d", path, terrno); return; } if (taosRemoveFile(path) != 0) { - tscError("failed to remove file:%s, errno:%d", path, errno); + tscError("failed to remove file:%s, terrno:%d", path, terrno); return; } } diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index cd443f88e5..0cc38a3a12 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -298,6 +298,7 @@ void tmq_conf_destroy(tmq_conf_t* conf) { } tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value) { + int32_t code = 0; if (conf == NULL || key == NULL || value == NULL) { return TMQ_CONF_INVALID; } @@ -324,8 +325,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "auto.commit.interval.ms") == 0) { - int64_t tmp = taosStr2int64(value); - if (tmp < 0 || EINVAL == errno || ERANGE == errno) { + int64_t tmp; + code = taosStr2int64(value, &tmp); + if (tmp < 0 || code != 0) { return TMQ_CONF_INVALID; } conf->autoCommitInterval = (tmp > INT32_MAX ? INT32_MAX : tmp); @@ -333,8 +335,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "session.timeout.ms") == 0) { - int64_t tmp = taosStr2int64(value); - if (tmp < 6000 || tmp > 1800000) { + int64_t tmp; + code = taosStr2int64(value, &tmp); + if (tmp < 6000 || tmp > 1800000 || code != 0) { return TMQ_CONF_INVALID; } conf->sessionTimeoutMs = tmp; @@ -342,8 +345,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "heartbeat.interval.ms") == 0) { - int64_t tmp = taosStr2int64(value); - if (tmp < 1000 || tmp >= conf->sessionTimeoutMs) { + int64_t tmp; + code = taosStr2int64(value, &tmp); + if (tmp < 1000 || tmp >= conf->sessionTimeoutMs || code != 0) { return TMQ_CONF_INVALID; } conf->heartBeatIntervalMs = tmp; @@ -351,8 +355,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "max.poll.interval.ms") == 0) { - int64_t tmp = taosStr2int64(value); - if (tmp < 1000 || tmp > INT32_MAX) { + int32_t tmp; + code = taosStr2int32(value, &tmp); + if (tmp < 1000 || code != 0) { return TMQ_CONF_INVALID; } conf->maxPollIntervalMs = tmp; @@ -414,8 +419,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "td.connect.port") == 0) { - int64_t tmp = taosStr2int64(value); - if (tmp <= 0 || tmp > 65535) { + int64_t tmp; + code = taosStr2int64(value, &tmp); + if (tmp <= 0 || tmp > 65535 || code != 0) { return TMQ_CONF_INVALID; } @@ -435,7 +441,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } } if (strcasecmp(key, "msg.consume.excluded") == 0) { - conf->sourceExcluded = (taosStr2int64(value) != 0) ? TD_REQ_FROM_TAOX : 0; + int64_t tmp; + code = taosStr2int64(value, &tmp); + conf->sourceExcluded = (0 == code && tmp != 0) ? TD_REQ_FROM_TAOX : 0; return TMQ_CONF_OK; } @@ -444,7 +452,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "msg.enable.batchmeta") == 0) { - conf->enableBatchMeta = (taosStr2int64(value) != 0) ? true : false; + int64_t tmp; + code = taosStr2int64(value, &tmp); + conf->enableBatchMeta = (0 == code && tmp != 0) ? true : false; return TMQ_CONF_OK; } diff --git a/source/common/src/cos.c b/source/common/src/cos.c index d3b3f1f87d..88f97a498d 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -1412,7 +1412,7 @@ static int32_t s3GetObjectToFileByEp(const char *object_name, const char *fileNa TdFilePtr pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - uError("[s3] open file error, errno:%d, fileName:%s", terrno, fileName); + uError("[s3] open file error, terrno:%d, fileName:%s", terrno, fileName); TAOS_RETURN(terrno); } @@ -1871,7 +1871,6 @@ void s3EvictCache(const char *path, long object_size) { taosDirName(dir_name); if (taosGetDiskSize((char *)dir_name, &disk_size) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); vError("failed to get disk:%s size since %s", path, terrstr()); return; } diff --git a/source/common/src/tmisce.c b/source/common/src/tmisce.c index f3f4b29617..e40db7b4cf 100644 --- a/source/common/src/tmisce.c +++ b/source/common/src/tmisce.c @@ -197,7 +197,6 @@ int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t code = taosGetAppName(tmp, NULL); if (code != 0) { - code = TAOS_SYSTEM_ERROR(errno); TAOS_CHECK_GOTO(code, NULL, _exit); } TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "appName", tmp), NULL, _exit); diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index 620aed709f..f48ca35330 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -89,9 +89,13 @@ static bool dmDataSpaceAvailable() { } static int32_t dmCheckDiskSpace() { - osUpdate(); // availability int32_t code = 0; + code = osUpdate(); + if(code != 0) { + code = 0; // ignore the error, just log it + dError("failed to update os info since %s", tstrerror(code)); + } if (!dmDataSpaceAvailable()) { code = TSDB_CODE_NO_DISKSPACE; return code; diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c index 38bd9f6b92..f67901d6d5 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c +++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c @@ -159,7 +159,9 @@ int32_t dmRunDnode(SDnode *pDnode) { } if (count == 10) { - osUpdate(); + if(osUpdate() != 0) { + dError("failed to update os info"); + } count = 0; } else { count++; diff --git a/source/dnode/mgmt/node_util/src/dmUtil.c b/source/dnode/mgmt/node_util/src/dmUtil.c index 68f4c9d0ff..f73f041f4a 100644 --- a/source/dnode/mgmt/node_util/src/dmUtil.c +++ b/source/dnode/mgmt/node_util/src/dmUtil.c @@ -55,14 +55,36 @@ void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool need } void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) { - taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine); - taosGetCpuCores(&pInfo->cpu_cores, false); - (void)taosGetProcMemory(&pInfo->mem_engine); - (void)taosGetSysMemory(&pInfo->mem_system); + int32_t code = 0; + code = taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine); + if (code != 0) { + dError("failed to get cpu usage since %s", tstrerror(code)); + } + code = taosGetCpuCores(&pInfo->cpu_cores, false); + if (code != 0) { + dError("failed to get cpu cores since %s", tstrerror(code)); + } + code = taosGetProcMemory(&pInfo->mem_engine); + if (code != 0) { + dError("failed to get proc memory since %s", tstrerror(code)); + } + code = taosGetSysMemory(&pInfo->mem_system); + if (code != 0) { + dError("failed to get sys memory since %s", tstrerror(code)); + } pInfo->mem_total = tsTotalMemoryKB; pInfo->disk_engine = 0; pInfo->disk_used = tsDataSpace.size.used; pInfo->disk_total = tsDataSpace.size.total; - taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); - taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); + code = taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); + if (code != 0) { + dError("failed to get card info since %s", tstrerror(code)); + taosSetDefaultCardInfoDelta(&pInfo->net_in, &pInfo->net_out); + } + code = taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); + if (code != 0) { + dError("failed to get proc io delta since %s", tstrerror(code)); + taosSetDefaultProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); + } + return; } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 656af563e4..b568b03c2c 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -232,7 +232,7 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche } int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE); if (len < 0) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(len, NULL, _exception); } memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE); type = TSDB_DATA_TYPE_VARCHAR; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 43c12f8164..dff607f464 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -853,7 +853,7 @@ int32_t catalogInit(SCatalogCfg* cfg) { } if (tsem_init(&gCtgMgmt.queue.reqSem, 0, 0)) { - qError("tsem_init failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); + qError("tsem_init failed, terror:%s", tstrerror(terrno)); CTG_ERR_RET(TSDB_CODE_CTG_SYS_ERROR); } diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 457aa8ff2b..5352ea37ae 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -565,7 +565,6 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { pSourceDataInfo->status = EX_SOURCE_DATA_READY; code = tsem_post(&pExchangeInfo->ready); if (code != TSDB_CODE_SUCCESS) { - code = TAOS_SYSTEM_ERROR(code); qError("failed to invoke post when fetch rsp is ready, code:%s, %p", tstrerror(code), pExchangeInfo); return code; } diff --git a/source/libs/index/inc/indexComm.h b/source/libs/index/inc/indexComm.h index 09fd2f3555..173443dfc5 100644 --- a/source/libs/index/inc/indexComm.h +++ b/source/libs/index/inc/indexComm.h @@ -30,7 +30,7 @@ char* idxPackJsonData(SIndexTerm* itm); char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip); char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip); -typedef enum { MATCH, CONTINUE, BREAK } TExeCond; +typedef enum { MATCH, CONTINUE, BREAK, FAILED } TExeCond; typedef TExeCond (*_cache_range_compare)(void* a, void* b, int8_t type); diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index 1b31c1e50b..828a3e2e9e 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -153,9 +153,8 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt* break; } CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node); - terrno = TSDB_CODE_SUCCESS; TExeCond cond = cmpFn(c->colVal, pCt->colVal, pCt->colType); - if (terrno != TSDB_CODE_SUCCESS) { + if (cond == FAILED) { code = terrno; goto _return; } @@ -335,10 +334,9 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR goto _return; } memcpy(p, c->colVal, strlen(c->colVal)); - terrno = TSDB_CODE_SUCCESS; cond = cmpFn(p + skip, term->colVal, dType); taosMemoryFree(p); - if (terrno != TSDB_CODE_SUCCESS) { + if (cond == FAILED) { code = terrno; goto _return; } diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index 2c681a1df3..0fab194044 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -118,6 +118,14 @@ static FORCE_INLINE TExeCond tCompareContains(void* a, void* b, int8_t type) { } return tCompare(func, QUERY_TERM, a, b, type); } + +#define CHECKCOMERROR(expr) \ + do { \ + if ((expr) != 0) { \ + return FAILED; \ + } \ + } while (0) + static FORCE_INLINE TExeCond tCompareEqual(void* a, void* b, int8_t type) { __compar_fn_t func = idxGetCompar(type); if (func == NULL) { @@ -132,36 +140,52 @@ TExeCond tCompare(__compar_fn_t func, int8_t cmptype, void* a, void* b, int8_t d } #if 1 if (dtype == TSDB_DATA_TYPE_TIMESTAMP) { - int64_t va = taosStr2int64(a); - int64_t vb = taosStr2int64(b); + int64_t va; + CHECKCOMERROR(taosStr2int64(a, &va)); + int64_t vb; + CHECKCOMERROR(taosStr2int64(b, &vb)); return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_BOOL || dtype == TSDB_DATA_TYPE_UTINYINT) { - uint8_t va = taosStr2int64(a); - uint8_t vb = taosStr2int64(b); + uint8_t va; + CHECKCOMERROR(taosStr2int8(a, &va)); + uint8_t vb; + CHECKCOMERROR(taosStr2int8(b, &vb)); return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_TINYINT) { - int8_t va = taosStr2int64(a); - int8_t vb = taosStr2int64(b); + int8_t va; + CHECKCOMERROR(taosStr2int8(a, &va)); + int8_t vb; + CHECKCOMERROR(taosStr2int8(b, &vb)); return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_SMALLINT) { - int16_t va = taosStr2int64(a); - int16_t vb = taosStr2int64(b); + int16_t va; + CHECKCOMERROR(taosStr2int16(a, &va)); + int16_t vb; + CHECKCOMERROR(taosStr2int16(b, &vb)); return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_USMALLINT) { - uint16_t va = taosStr2int64(a); - uint16_t vb = taosStr2int64(b); + uint16_t va; + CHECKCOMERROR(taosStr2int16(a, &va)); + uint16_t vb; + CHECKCOMERROR(taosStr2int16(b, &vb)); return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_INT) { - int32_t va = taosStr2int64(a); - int32_t vb = taosStr2int64(b); + int32_t va; + CHECKCOMERROR(taosStr2int32(a, &va)); + int32_t vb; + CHECKCOMERROR(taosStr2int32(b, &vb)); return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_UINT) { - uint32_t va = taosStr2int64(a); - uint32_t vb = taosStr2int64(b); + uint32_t va; + CHECKCOMERROR(taosStr2int32(a, &va)); + uint32_t vb; + CHECKCOMERROR(taosStr2int32(b, &vb)); return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_BIGINT) { - int64_t va = taosStr2int64(a); - int64_t vb = taosStr2int64(b); + int64_t va; + CHECKCOMERROR(taosStr2int64(a, &va)); + int64_t vb; + CHECKCOMERROR(taosStr2int64(b, &vb)); return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_UBIGINT) { uint64_t va, vb; diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 7037242b65..eb00cc7990 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -367,9 +367,8 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr, FstSlice* s = &rt->data; char* ch = (char*)fstSliceData(s, NULL); - terrno = TSDB_CODE_SUCCESS; TExeCond cond = cmpFn(ch, p, tem->colType); - if (TSDB_CODE_SUCCESS != terrno) { + if (FAILED == cond) { swsResultDestroy(rt); code = terrno; goto _return; @@ -520,10 +519,9 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt goto _return; } memcpy(tBuf, ch, sz); - terrno = TSDB_CODE_SUCCESS; cond = cmpFn(tBuf + skip, tem->colVal, IDX_TYPE_GET_TYPE(tem->colType)); taosMemoryFree(tBuf); - if (TSDB_CODE_SUCCESS != terrno) { + if (FAILED == cond) { swsResultDestroy(rt); code = terrno; goto _return; diff --git a/source/libs/index/test/utilUT.cc b/source/libs/index/test/utilUT.cc index 323a6b4afa..299b62b6fb 100644 --- a/source/libs/index/test/utilUT.cc +++ b/source/libs/index/test/utilUT.cc @@ -328,13 +328,17 @@ TEST_F(UtilEnv, testFill) { int64_t val = i; char buf[65] = {0}; idxInt2str(val, buf, 1); - EXPECT_EQ(val, taosStr2int64(buf)); + int64_t ret = 0; + taosStr2int64(buf, &ret); + EXPECT_EQ(val, ret); } for (int i = 0; i < 1000000; i++) { int64_t val = 0 - i; char buf[65] = {0}; idxInt2str(val, buf, -1); - EXPECT_EQ(val, taosStr2int64(buf)); + int64_t ret = 0; + taosStr2int64(buf, &ret); + EXPECT_EQ(val, ret); } } TEST_F(UtilEnv, TempResult) { diff --git a/source/libs/parser/src/parInsertSml.c b/source/libs/parser/src/parInsertSml.c index 23025dcab9..929ec01f6a 100644 --- a/source/libs/parser/src/parInsertSml.c +++ b/source/libs/parser/src/parInsertSml.c @@ -143,13 +143,13 @@ static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchem goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)(p), kv->length * TSDB_NCHAR_SIZE, &output)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { taosMemoryFree(p); code = generateSyntaxErrMsg(msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name); goto end; } char buf[512] = {0}; - (void)snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno)); + (void)snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno)); taosMemoryFree(p); code = buildSyntaxErrMsg(msg, buf, kv->value); goto end; @@ -257,7 +257,7 @@ int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32 goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, size, &len)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { taosMemoryFree(pUcs4); ret = TSDB_CODE_PAR_VALUE_TOO_LONG; goto end; @@ -404,14 +404,14 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { uError("sml bind taosMbsToUcs4 error, kv length:%d, bytes:%d, kv->value:%s", (int)kv->length, pColSchema->bytes, kv->value); (void)buildInvalidOperationMsg(&pBuf, "value too long"); ret = TSDB_CODE_PAR_VALUE_TOO_LONG; goto end; } - ret = buildInvalidOperationMsg(&pBuf, strerror(errno)); + ret = buildInvalidOperationMsg(&pBuf, strerror(terrno)); goto end; } pVal->value.pData = pUcs4; diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 662e24a679..d15d305c95 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -682,12 +682,12 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema, return TSDB_CODE_OUT_OF_MEMORY; } if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), realLen, &output)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { taosMemoryFree(p); return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } char buf[512] = {0}; - snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno)); + snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno)); taosMemoryFree(p); return buildSyntaxErrMsg(pMsgBuf, buf, pToken->z); } @@ -1616,11 +1616,11 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, } if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, realLen, &len)) { taosMemoryFree(pUcs4); - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } char buf[512] = {0}; - snprintf(buf, tListLen(buf), "%s", strerror(errno)); + snprintf(buf, tListLen(buf), "%s", strerror(terrno)); return buildSyntaxErrMsg(&pCxt->msg, buf, pToken->z); } pVal->value.pData = pUcs4; diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index b67b7fc583..ff701e7fa2 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -194,13 +194,13 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch goto end; } if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { taosMemoryFree(p); code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name); goto end; } char buf[512] = {0}; - snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno)); + snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno)); taosMemoryFree(p); code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer); goto end; @@ -274,11 +274,11 @@ int32_t convertStmtNcharCol(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_MULTI_BIND* if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i], (TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } char buf[512] = {0}; - snprintf(buf, tListLen(buf), "%s", strerror(errno)); + snprintf(buf, tListLen(buf), "%s", strerror(terrno)); return buildSyntaxErrMsg(pMsgBuf, buf, NULL); } @@ -534,13 +534,13 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c goto end; } if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { taosMemoryFree(p); code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name); goto end; } char buf[512] = {0}; - snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno)); + snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno)); taosMemoryFree(p); code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer); goto end; @@ -610,11 +610,11 @@ static int32_t convertStmtStbNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_ } if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } char buf[512] = {0}; - snprintf(buf, tListLen(buf), "%s", strerror(errno)); + snprintf(buf, tListLen(buf), "%s", strerror(terrno)); return buildSyntaxErrMsg(pMsgBuf, buf, NULL); } @@ -740,11 +740,11 @@ static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STM /*if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i], (TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {*/ if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) { - if (errno == E2BIG) { + if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } char buf[512] = {0}; - snprintf(buf, tListLen(buf), "%s", strerror(errno)); + snprintf(buf, tListLen(buf), "%s", strerror(terrno)); return buildSyntaxErrMsg(pMsgBuf, buf, NULL); } diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 5c4ced7004..94bd53ea68 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -469,7 +469,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi val.type = TSDB_DATA_TYPE_NCHAR; if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)tmp, (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) { uError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, - strerror(errno)); + strerror(terrno)); retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue); taosMemoryFree(tmp); goto end; diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 35e626872e..2de61ab669 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -198,7 +198,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { int32_t output = 0; if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes, &output)) { - return errno; + return terrno; } varDataSetLen(pVal->datum.p, output); pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE; @@ -486,7 +486,7 @@ static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam) { int32_t output = 0; if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes, &output)) { - return errno; + return terrno; } varDataSetLen(pVal->datum.p, output); pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE; diff --git a/source/libs/tfs/src/tfsDisk.c b/source/libs/tfs/src/tfsDisk.c index dfdf1262c9..6041f68f6f 100644 --- a/source/libs/tfs/src/tfsDisk.c +++ b/source/libs/tfs/src/tfsDisk.c @@ -33,7 +33,7 @@ int32_t tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *path, pDisk->id = id; pDisk->disable = disable; if (taosGetDiskSize(pDisk->path, &pDisk->size) < 0) { - code = TAOS_SYSTEM_ERROR(errno); // TODO: refactor this line + code = terrno; TAOS_CHECK_GOTO(code, &lino, _exit); } _exit: @@ -57,7 +57,7 @@ STfsDisk *tfsFreeDisk(STfsDisk *pDisk) { int32_t tfsUpdateDiskSize(STfsDisk *pDisk) { if (taosGetDiskSize(pDisk->path, &pDisk->size) < 0) { - int32_t code = TAOS_SYSTEM_ERROR(errno); // TODO: refactor this line + int32_t code = terrno; fError("failed to get disk:%s size, level:%d id:%d since %s", pDisk->path, pDisk->level, pDisk->id, tstrerror(code)); TAOS_RETURN(code); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3f064636df..a8f1d26f15 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3061,7 +3061,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra code = tsem_init(sem, 0, 0); if (code != 0) { taosMemoryFree(sem); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _RETURN1); + TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } if (pReq->info.traceId.msgId == 0) TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); @@ -3224,9 +3224,8 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, } code = tsem2_timewait(pSyncMsg->pSem, timeoutMs); - if (code < 0) { - pRsp->code = TSDB_CODE_TIMEOUT_ERROR; - code = TSDB_CODE_TIMEOUT_ERROR; + if (code != 0) { + pRsp->code = code; } else { memcpy(pRsp, pSyncMsg->pRsp, sizeof(STransMsg)); pSyncMsg->pRsp->pCont = NULL; @@ -3234,7 +3233,6 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, epsetAssign(pEpSet, &pSyncMsg->epSet); *epUpdated = 1; } - code = 0; } _RETURN: (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index dcce5543b2..e06c1a6aac 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -104,7 +104,7 @@ void taosRemoveDir(const char *dirname) { if (taosDirEntryIsDir(de)) { taosRemoveDir(filename); } else { - (void)taosRemoveFile(filename); + TAOS_UNUSED(taosRemoveFile(filename)); // printf("file:%s is removed\n", filename); } } @@ -315,7 +315,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { if (fileSec <= 100) continue; int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1); if (days > keepDays) { - (void)taosRemoveFile(filename); + TAOS_UNUSED(taosRemoveFile(filename)); uInfo("file:%s is removed, days:%d keepDays:%d, sed:%"PRId64, filename, days, keepDays, fileSec); } else { // printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays); @@ -323,8 +323,8 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { } } - (void)taosCloseDir(&pDir); - (void)rmdir(dirname); + TAOS_UNUSED(taosCloseDir(&pDir)); + TAOS_UNUSED(rmdir(dirname)); } int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index 8334d609b1..c0273e4a6f 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -94,16 +94,18 @@ int32_t osDefaultInit() { return code; } -void osUpdate() { +int32_t osUpdate() { + int code = 0; if (tsLogDir[0] != 0) { - (void)taosGetDiskSize(tsLogDir, &tsLogSpace.size); + code = taosGetDiskSize(tsLogDir, &tsLogSpace.size); } if (tsDataDir[0] != 0) { - (void)taosGetDiskSize(tsDataDir, &tsDataSpace.size); + code = taosGetDiskSize(tsDataDir, &tsDataSpace.size); } if (tsTempDir[0] != 0) { - (void)taosGetDiskSize(tsTempDir, &tsTempSpace.size); + code = taosGetDiskSize(tsTempDir, &tsTempSpace.size); } + return code; } void osCleanup() {} diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 94ead5c129..0e5b6b71a1 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -174,9 +174,12 @@ int64_t taosCopyFile(const char *from, const char *to) { } code = taosFsyncFile(pFileTo); + if (code != 0) { + goto _err; + } - (void)taosCloseFile(&pFileFrom); - (void)taosCloseFile(&pFileTo); + TAOS_UNUSED(taosCloseFile(&pFileFrom)); + TAOS_UNUSED(taosCloseFile(&pFileTo)); if (code != 0) { terrno = code; @@ -187,10 +190,10 @@ int64_t taosCopyFile(const char *from, const char *to) { _err: - if (pFileFrom != NULL) (void)taosCloseFile(&pFileFrom); - if (pFileTo != NULL) (void)taosCloseFile(&pFileTo); + if (pFileFrom != NULL) TAOS_SKIP_ERROR(taosCloseFile(&pFileFrom)); + if (pFileTo != NULL) TAOS_SKIP_ERROR(taosCloseFile(&pFileTo)); /* coverity[+retval] */ - (void)taosRemoveFile(to); + TAOS_SKIP_ERROR(taosRemoveFile(to)); terrno = code; return -1; @@ -1120,8 +1123,8 @@ int32_t taosCloseFile(TdFilePtr *ppFile) { (void)taosThreadRwlockWrlock(&((*ppFile)->rwlock)); #endif if ((*ppFile)->fp != NULL) { - (void)fflush((*ppFile)->fp); - (void)fclose((*ppFile)->fp); + TAOS_UNUSED(fflush((*ppFile)->fp)); + TAOS_UNUSED(fclose((*ppFile)->fp)); (*ppFile)->fp = NULL; } #ifdef WINDOWS @@ -1471,21 +1474,25 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { while (!feof(pSrcFile->fp)) { len = (int32_t)fread(data, 1, compressSize, pSrcFile->fp); if (len > 0) { - (void)gzwrite(dstFp, data, len); + if(gzwrite(dstFp, data, len) == 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + ret = terrno; + goto cmp_end; + } } } cmp_end: if (fd >= 0) { - (void)close(fd); + TAOS_SKIP_ERROR(close(fd)); } if (pSrcFile) { - (void)taosCloseFile(&pSrcFile); + TAOS_SKIP_ERROR(taosCloseFile(&pSrcFile)); } if (dstFp) { - (void)gzclose(dstFp); + TAOS_SKIP_ERROR(gzclose(dstFp)); } taosMemoryFree(data); diff --git a/source/os/src/osLocale.c b/source/os/src/osLocale.c index 2f835a7a27..d7fbb05a5d 100644 --- a/source/os/src/osLocale.c +++ b/source/os/src/osLocale.c @@ -135,9 +135,14 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) { str++; char *revisedCharset = taosCharsetReplace(str); - tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN); - taosMemoryFree(revisedCharset); + if (NULL == revisedCharset) { + (void)strcpy(outCharset, "UTF-8"); + } else { + tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN); + + taosMemoryFree(revisedCharset); + } // printf("charset not configured, set to system default:%s", outCharset); } else { strcpy(outCharset, "UTF-8"); diff --git a/source/os/src/osSemaphore.c b/source/os/src/osSemaphore.c index e959174f11..f6d339c89e 100644 --- a/source/os/src/osSemaphore.c +++ b/source/os/src/osSemaphore.c @@ -48,7 +48,10 @@ int32_t taosGetPId() { return GetCurrentProcessId(); } int32_t taosGetAppName(char* name, int32_t* len) { char filepath[1024] = {0}; - GetModuleFileName(NULL, filepath, MAX_PATH); + if (GetModuleFileName(NULL, filepath, MAX_PATH) == 0) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); + return terrno; + } char* sub = strrchr(filepath, '.'); if (sub != NULL) { *sub = '\0'; @@ -70,7 +73,12 @@ int32_t taosGetAppName(char* name, int32_t* len) { } int32_t tsem_wait(tsem_t* sem) { - return WaitForSingleObject(*sem, INFINITE); + DWORD ret = WaitForSingleObject(*sem, INFINITE); + if(ret == WAIT_OBJECT_0) { + return 0; + } else { + return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); + } } int32_t tsem_timewait(tsem_t* sem, int64_t timeout_ms) { @@ -78,61 +86,65 @@ int32_t tsem_timewait(tsem_t* sem, int64_t timeout_ms) { if (result == WAIT_OBJECT_0) { return 0; // Semaphore acquired } else if (result == WAIT_TIMEOUT) { - return -1; // Timeout reached + return TSDB_CODE_TIMEOUT_ERROR; // Timeout reached } else { - return result; + return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } } // Inter-process sharing is not currently supported. The pshared parameter is invalid. -int tsem_init(tsem_t* sem, int pshared, unsigned int value) { +int32_t tsem_init(tsem_t* sem, int pshared, unsigned int value) { *sem = CreateSemaphore(NULL, value, LONG_MAX, NULL); - return (*sem != NULL) ? 0 : -1; + return (*sem != NULL) ? 0 : TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } -int tsem_post(tsem_t* sem) { +int32_t tsem_post(tsem_t* sem) { if (ReleaseSemaphore(*sem, 1, NULL)) return 0; - return -1; + return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } -int tsem_destroy(tsem_t* sem) { +int32_t tsem_destroy(tsem_t* sem) { if (CloseHandle(*sem)) return 0; - return -1; + return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } #elif defined(_TD_DARWIN_64) #include -int tsem_init(tsem_t *psem, int flags, unsigned int count) { +int32_t tsem_init(tsem_t *psem, int flags, unsigned int count) { *psem = dispatch_semaphore_create(count); - if (*psem == NULL) return -1; + if (*psem == NULL) return TAOS_SYSTEM_ERROR(errno); return 0; } -int tsem_destroy(tsem_t *psem) { - if (psem == NULL || *psem == NULL) return -1; +int32_t tsem_destroy(tsem_t *psem) { + // if (psem == NULL || *psem == NULL) return -1; // dispatch_release(*psem); // *psem = NULL; return 0; } -int tsem_post(tsem_t *psem) { +int32_t tsem_post(tsem_t *psem) { if (psem == NULL || *psem == NULL) return -1; - dispatch_semaphore_signal(*psem); + (void)dispatch_semaphore_signal(*psem); return 0; } -int tsem_wait(tsem_t *psem) { +int32_t tsem_wait(tsem_t *psem) { if (psem == NULL || *psem == NULL) return -1; dispatch_semaphore_wait(*psem, DISPATCH_TIME_FOREVER); return 0; } -int tsem_timewait(tsem_t *psem, int64_t milis) { +int32_t tsem_timewait(tsem_t *psem, int64_t milis) { if (psem == NULL || *psem == NULL) return -1; dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC)); - return dispatch_semaphore_wait(*psem, time); + if(dispatch_semaphore_wait(*psem, time) == 0) { + return 0; + } else { + return TSDB_CODE_TIMEOUT_ERROR; + } } bool taosCheckPthreadValid(TdThread thread) { return thread != 0; } @@ -216,6 +228,14 @@ int32_t taosGetAppName(char* name, int32_t* len) { return 0; } +int32_t tsem_init(tsem_t *psem, int flags, unsigned int count) { + if(sem_init(psem, flags, count) == 0) { + return 0; + } else { + return TAOS_SYSTEM_ERROR(errno); + } +} + int32_t tsem_timewait(tsem_t* sem, int64_t ms) { int ret = 0; @@ -230,16 +250,18 @@ int32_t tsem_timewait(tsem_t* sem, int64_t ms) { ts.tv_sec += ts.tv_nsec / 1000000000; ts.tv_nsec %= 1000000000; - while ((ret = sem_timedwait(sem, &ts)) == -1 && errno == EINTR) { - continue; + while ((ret = sem_timedwait(sem, &ts)) == -1) { + if(errno == EINTR) { + continue; + } else if(errno == ETIMEDOUT) { + return TSDB_CODE_TIMEOUT_ERROR; + } else { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } } - if (-1 == ret) { - terrno = TAOS_SYSTEM_ERROR(errno); - return terrno; - } - - return ret; + return 0; } int32_t tsem_wait(tsem_t* sem) { @@ -285,6 +307,22 @@ int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { return 0; } +int32_t tsem_post(tsem_t* psem) { + if (sem_post(psem) == 0) { + return 0; + } else { + return TAOS_SYSTEM_ERROR(errno); + } +} + +int32_t tsem_destroy(tsem_t *sem) { + if (sem_destroy(sem) == 0) { + return 0; + } else { + return TAOS_SYSTEM_ERROR(errno); + } +} + int tsem2_post(tsem2_t *sem) { int32_t code = taosThreadMutexLock(&sem->mutex); if (code) { @@ -364,7 +402,11 @@ int32_t tsem2_timewait(tsem2_t* sem, int64_t ms) { ret = taosThreadCondTimedWait(&sem->cond, &sem->mutex, &ts); if (ret != 0) { (void)taosThreadMutexUnlock(&sem->mutex); - return ret; + if (errno == ETIMEDOUT) { + return TSDB_CODE_TIMEOUT_ERROR; + } else { + return TAOS_SYSTEM_ERROR(errno); + } } } } diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 1c99355e34..ffc64f3493 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -38,6 +38,8 @@ char *tstrdup(const char *str) { } #ifdef WINDOWS + +// No errors are expected to occur char *strsep(char **stringp, const char *delim) { char *s; const char *spanp; @@ -84,9 +86,59 @@ char *stpncpy(char *dest, const char *src, int n) { } #endif -int64_t taosStr2int64(const char *str) { - char *endptr = NULL; - return strtoll(str, &endptr, 10); +int32_t taosStr2int64(const char *str, int64_t *val) { + if (str == NULL || val == NULL) { + return TSDB_CODE_INVALID_PARA; + } + char *endptr = NULL; + int64_t ret = strtoll(str, &endptr, 10); + if (errno == ERANGE && (ret == LLONG_MAX || ret == LLONG_MIN)) { + return TAOS_SYSTEM_ERROR(errno); + } else if (errno == EINVAL && ret == 0) { + return TSDB_CODE_INVALID_PARA; + } else { + *val = ret; + return 0; + } +} + +int32_t taosStr2int16(const char *str, int16_t *val) { + int64_t tmp = 0; + int32_t code = taosStr2int64(str, &tmp); + if (code) { + return code; + } else if (tmp > INT16_MAX || tmp < INT16_MIN) { + return TAOS_SYSTEM_ERROR(ERANGE); + } else { + *val = (int16_t)tmp; + return 0; + } +} + +int32_t taosStr2int32(const char *str, int32_t *val) { + int64_t tmp = 0; + int32_t code = taosStr2int64(str, &tmp); + if (code) { + return code; + } else if (tmp > INT32_MAX || tmp < INT32_MIN) { + return TAOS_SYSTEM_ERROR(ERANGE); + } else { + *val = (int32_t)tmp; + return 0; + } +} + +int32_t taosStr2int8(const char *str, int8_t *val) { + int64_t tmp = 0; + int32_t code = taosStr2int64(str, &tmp); + if (code) { + return code; + } else if (tmp > INT8_MAX || tmp < INT8_MIN) { + return TAOS_SYSTEM_ERROR(ERANGE); + } else { + *val = (int8_t)tmp; + return 0; + } } int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) { @@ -253,12 +305,12 @@ void taosReleaseConv(int32_t idx, iconv_t conv, ConvType type) { bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len) { #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); - return -1; + terrno = TSDB_CODE_APP_ERROR; + return false; #else (void)memset(ucs4, 0, ucs4_max_len); int32_t idx = -1; - int32_t code = 0; iconv_t conv = taosAcquireConv(&idx, M2C); if ((iconv_t)-1 == conv || (iconv_t)0 == conv) { return false; @@ -267,9 +319,8 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4 size_t ucs4_input_len = mbsLength; size_t outLeft = ucs4_max_len; if (iconv(conv, (char **)&mbs, &ucs4_input_len, (char **)&ucs4, &outLeft) == -1) { - code = TAOS_SYSTEM_ERROR(errno); + terrno = TAOS_SYSTEM_ERROR(errno); taosReleaseConv(idx, conv, M2C); - terrno = code; return false; } @@ -277,6 +328,8 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4 if (len != NULL) { *len = (int32_t)(ucs4_max_len - outLeft); if (*len < 0) { + // can not happen + terrno = TSDB_CODE_APP_ERROR; return false; } } @@ -285,17 +338,20 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4 #endif } +// if success, return the number of bytes written to mbs ( >= 0) +// otherwise return error code ( < 0) int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) { #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); - return -1; + terrno = TSDB_CODE_APP_ERROR; + return terrno; #else int32_t idx = -1; int32_t code = 0; iconv_t conv = taosAcquireConv(&idx, C2M); if ((iconv_t)-1 == conv || (iconv_t)0 == conv) { - return false; + return TSDB_CODE_APP_ERROR; } size_t ucs4_input_len = ucs4_max_len; @@ -313,10 +369,13 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) { #endif } +// if success, return the number of bytes written to mbs ( >= 0) +// otherwise return error code ( < 0) int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv) { #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); - return -1; + terrno = TSDB_CODE_APP_ERROR; + return terrno; #else size_t ucs4_input_len = ucs4_max_len; @@ -333,7 +392,8 @@ int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t c bool taosValidateEncodec(const char *encodec) { #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); - return true; + terrno = TSDB_CODE_APP_ERROR; + return false; #else iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC); if (cd == (iconv_t)(-1)) { diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 137bb8f0db..36b1d7b60d 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -179,10 +179,8 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { char line[1024]; ssize_t bytes = taosGetsFile(pFile, sizeof(line), line); if (bytes < 0) { - code = terrno; - (void)taosCloseFile(&pFile); - terrno = code; - return code; + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); + return terrno; } char cpu[10] = {0}; @@ -230,9 +228,7 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { char line[1024] = {0}; ssize_t bytes = taosGetsFile(pFile, sizeof(line), line); if (bytes < 0) { - code = terrno; - (void)taosCloseFile(&pFile); - terrno = code; + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); return code; } @@ -250,7 +246,7 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { } } - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); #endif return 0; @@ -427,7 +423,7 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t if (++cnt >= 3) break; } - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); return code; #endif } @@ -497,13 +493,13 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { if (strncmp(line, "processor", 9) == 0) coreCount += 1; } - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); if (code != 0 && (done & 1) == 0) { TdFilePtr pFile1 = taosOpenFile("/proc/device-tree/model", TD_FILE_READ | TD_FILE_STREAM); if (pFile1 != NULL) { ssize_t bytes = taosGetsFile(pFile1, maxLen, cpuModel); - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); if (bytes > 0) { code = 0; done |= 1; @@ -535,9 +531,9 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { // Returns the container's CPU quota if successful, otherwise returns the physical CPU cores static int32_t taosCntrGetCpuCores(float *numOfCores) { #ifdef WINDOWS - return -1; + return TSDB_CODE_UNSUPPORT_OS; #elif defined(_TD_DARWIN_64) - return -1; + return TSDB_CODE_UNSUPPORT_OS; #else TdFilePtr pFile = NULL; if (!(pFile = taosOpenFile(tsCpuQuotaFile, TD_FILE_READ | TD_FILE_STREAM))) { @@ -545,11 +541,11 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) { } char qline[32] = {0}; if (taosGetsFile(pFile, sizeof(qline), qline) <= 0) { - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); goto _sys; } - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); float quota = taosStr2Float(qline, NULL); if (quota < 0) { goto _sys; @@ -561,11 +557,11 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) { char pline[32] = {0}; if (taosGetsFile(pFile, sizeof(pline), pline) <= 0) { - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); goto _sys; } - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); float period = taosStr2Float(pline, NULL); float quotaCores = quota / period; @@ -575,10 +571,16 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) { } else { *numOfCores = sysCores; } + if(*numOfCores <= 0) { + return TAOS_SYSTEM_ERROR(errno); + } goto _end; _sys: *numOfCores = sysconf(_SC_NPROCESSORS_ONLN); + if(*numOfCores <= 0) { + return TAOS_SYSTEM_ERROR(errno); + } _end: return 0; @@ -586,26 +588,35 @@ _end: #endif } -void taosGetCpuCores(float *numOfCores, bool physical) { +int32_t taosGetCpuCores(float *numOfCores, bool physical) { #ifdef WINDOWS SYSTEM_INFO info; GetSystemInfo(&info); *numOfCores = info.dwNumberOfProcessors; - return; + return 0; #elif defined(_TD_DARWIN_64) *numOfCores = sysconf(_SC_NPROCESSORS_ONLN); - return; + if(*numOfCores <= 0) { + return TAOS_SYSTEM_ERROR(errno); + } + return 0; #else if (physical) { *numOfCores = sysconf(_SC_NPROCESSORS_ONLN); + if(*numOfCores <= 0) { + return TAOS_SYSTEM_ERROR(errno); + } } else { - (void)taosCntrGetCpuCores(numOfCores); + int code= taosCntrGetCpuCores(numOfCores); + if(code != 0) { + return code; + } } - return; + return 0; #endif } -void taosGetCpuUsage(double *cpu_system, double *cpu_engine) { +int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) { static int64_t lastSysUsed = -1; static int64_t lastSysTotal = -1; static int64_t lastProcTotal = -1; @@ -639,6 +650,7 @@ void taosGetCpuUsage(double *cpu_system, double *cpu_engine) { lastSysTotal = curSysTotal; lastProcTotal = curProcTotal; } + return 0; } #define __cpuid_fix(level, a, b, c, d) \ @@ -779,15 +791,15 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { return 0; } else { // printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); - // terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); + return terrno; } #elif defined(_TD_DARWIN_64) struct statvfs info; if (statvfs(dataDir, &info)) { // printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); - // terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; } else { diskSize->total = info.f_blocks * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize; @@ -860,7 +872,7 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int if (readIndex >= 4) break; } - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); if (readIndex < 4) { return -1; @@ -870,7 +882,7 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int #endif } -void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { +int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { static int64_t last_rchars = -1; static int64_t last_wchars = -1; static int64_t last_read_bytes = -1; @@ -879,7 +891,8 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i static int64_t cur_wchars = 0; static int64_t cur_read_bytes = 0; static int64_t cur_write_bytes = 0; - if (taosGetProcIO(&cur_rchars, &cur_wchars, &cur_read_bytes, &cur_write_bytes) == 0) { + int32_t code = taosGetProcIO(&cur_rchars, &cur_wchars, &cur_read_bytes, &cur_write_bytes); + if (code == 0) { if(last_rchars >=0 && last_wchars >=0 && last_read_bytes >=0 && last_write_bytes >= 0){ *rchars = cur_rchars - last_rchars; *wchars = cur_wchars - last_wchars; @@ -897,11 +910,15 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i last_read_bytes = cur_read_bytes; last_write_bytes = cur_write_bytes; } else { - *rchars = 0; - *wchars = 0; - *read_bytes = 0; - *write_bytes = 0; + return code; } + return 0; +} +void taosSetDefaultProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { + *rchars = 0; + *wchars = 0; + *read_bytes = 0; + *write_bytes = 0; } int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { @@ -953,18 +970,19 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { *transmit_bytes += o_tbytes; } - (void)taosCloseFile(&pFile); + TAOS_SKIP_ERROR(taosCloseFile(&pFile)); return 0; #endif } -void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { +int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { static int64_t last_receive_bytes = -1; static int64_t last_transmit_bytes = -1; int64_t cur_receive_bytes = 0; int64_t cur_transmit_bytes = 0; - if (taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes) == 0) { + int32_t code = taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes); + if (code == 0) { if(last_receive_bytes >= 0 && last_transmit_bytes >= 0){ *receive_bytes = cur_receive_bytes - last_receive_bytes; *transmit_bytes = cur_transmit_bytes - last_transmit_bytes; @@ -977,9 +995,13 @@ void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { last_receive_bytes = cur_receive_bytes; last_transmit_bytes = cur_transmit_bytes; } else { - *receive_bytes = 0; - *transmit_bytes = 0; + return code; } + return 0; +} +void taosSetDefaultCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { + *receive_bytes = 0; + *transmit_bytes = 0; } void taosKillSystem() { diff --git a/source/os/test/osSemaphoreTests.cpp b/source/os/test/osSemaphoreTests.cpp index 9347254b10..1576d2845d 100644 --- a/source/os/test/osSemaphoreTests.cpp +++ b/source/os/test/osSemaphoreTests.cpp @@ -59,18 +59,26 @@ TEST(osSemaphoreTests, Destroy) { TEST(osSemaphoreTests, WaitTime0) { tsem_t sem; (void)tsem_init(&sem, 0, 0); - EXPECT_NE(tsem_timewait(&sem, 1000), 0); + EXPECT_EQ(tsem_timewait(&sem, 1000), TSDB_CODE_TIMEOUT_ERROR); (void)tsem_destroy(&sem); } TEST(osSemaphoreTests, WaitTime1) { tsem_t sem; (void)tsem_init(&sem, 0, 1); - EXPECT_EQ(tsem_timewait(&sem, 1000), 0); - EXPECT_NE(tsem_timewait(&sem, 1000), 0); + EXPECT_EQ(tsem_timewait(&sem, 10000), 0); + EXPECT_EQ(tsem_timewait(&sem, 1000), TSDB_CODE_TIMEOUT_ERROR); (void)tsem_destroy(&sem); } +TEST(osSemaphoreTests, WaitTime2) { + tsem2_t sem; + (void)tsem2_init(&sem, 0, 1); + EXPECT_EQ(tsem2_timewait(&sem, 10000), 0); + EXPECT_EQ(tsem2_timewait(&sem, 1000), TSDB_CODE_TIMEOUT_ERROR); + (void)tsem2_destroy(&sem); +} + TEST(osSemaphoreTests, WaitAndPost) { tsem_t sem; int result = tsem_init(&sem, 0, 0); @@ -217,7 +225,7 @@ TEST(osSemaphoreTests, Performance4_1) { (void)tsem_post(&sem); }).detach(); - (void)tsem_timewait(&sem, 1000); + EXPECT_EQ(tsem_timewait(&sem, 1000),0); (void)tsem_destroy(&sem); } diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index bde3d48a6d..bd22a4e42b 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -215,7 +215,7 @@ int32_t taosInitSlowLog() { int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) { if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0; - osUpdate(); + TAOS_CHECK_RETURN(osUpdate()); TAOS_CHECK_RETURN(taosInitNormalLog(logName, maxFiles)); if (tsc){ @@ -908,7 +908,7 @@ static void *taosAsyncOutputLog(void *param) { updateCron++; taosMsleep(writeInterval); if (count > 1000) { - osUpdate(); + TAOS_UNUSED(osUpdate()); count = 0; } diff --git a/source/util/src/tsched.c b/source/util/src/tsched.c index 34c74660fc..1686b41038 100644 --- a/source/util/src/tsched.c +++ b/source/util/src/tsched.c @@ -150,7 +150,7 @@ void *taosProcessSchedQueue(void *scheduler) { while (1) { if ((ret = tsem_wait(&pSched->fullSem)) != 0) { - uFatal("wait %s fullSem failed(%s)", pSched->label, strerror(errno)); + uFatal("wait %s fullSem failed(%s)", pSched->label, strerror(terrno)); } if (atomic_load_8(&pSched->stop)) { break; @@ -169,7 +169,7 @@ void *taosProcessSchedQueue(void *scheduler) { } if ((ret = tsem_post(&pSched->emptySem)) != 0) { - uFatal("post %s emptySem failed(%s)", pSched->label, strerror(errno)); + uFatal("post %s emptySem failed(%s)", pSched->label, strerror(terrno)); } if (msg.fp) @@ -197,7 +197,7 @@ int taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) { } if ((ret = tsem_wait(&pSched->emptySem)) != 0) { - uFatal("wait %s emptySem failed(%s)", pSched->label, strerror(errno)); + uFatal("wait %s emptySem failed(%s)", pSched->label, strerror(terrno)); } if ((ret = taosThreadMutexLock(&pSched->queueMutex)) != 0) { @@ -212,7 +212,7 @@ int taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) { } if ((ret = tsem_post(&pSched->fullSem)) != 0) { - uFatal("post %s fullSem failed(%s)", pSched->label, strerror(errno)); + uFatal("post %s fullSem failed(%s)", pSched->label, strerror(terrno)); } return ret; }