From ea697804057b7e57727fb47af96fbe70b6c3d81a Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Tue, 23 Jun 2020 06:16:49 +0000 Subject: [PATCH] remove coverity scan bugs --- src/common/src/tglobal.c | 4 +--- src/rpc/src/rpcMain.c | 5 +++++ src/util/inc/tutil.h | 1 + src/util/src/tutil.c | 6 ++++++ src/wal/src/walMain.c | 46 +++++++++++++++++++++------------------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 2ed6ef3ab7..a80885e24d 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -1232,9 +1232,7 @@ bool taosCheckGlobalCfg() { taosGetFqdn(tsLocalFqdn); } - strcpy(tsLocalEp, tsLocalFqdn); - - snprintf(tsLocalEp + strlen(tsLocalEp), sizeof(tsLocalEp), ":%d", tsServerPort); + snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%d", tsLocalFqdn, tsServerPort); uPrint("localEp is: %s", tsLocalEp); if (tsFirst[0] == 0) { diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index f62df56771..1a81f32cf2 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -434,6 +434,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) { pConn->rspMsgLen = msgLen; if (pMsg->code == TSDB_CODE_RPC_ACTION_IN_PROGRESS) pConn->inTranId--; + // stop the progress timer taosTmrStopA(&pConn->pTimer); // set the idle timer to monitor the activity @@ -1021,7 +1022,11 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) { if ( rpcIsReq(pHead->msgType) ) { rpcMsg.handle = pConn; rpcAddRef(pRpc); // add the refCount for requests + + // start the progress timer to monitor the response from server app pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl); + + // notify the server app (*(pRpc->cfp))(&rpcMsg, NULL); } else { // it's a response diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index a314f0e31d..f25ee034de 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -181,6 +181,7 @@ char *taosIpStr(uint32_t ipInt); uint32_t ip2uint(const char *const ip_addr); void taosRemoveDir(char *rootDir); +int tmkdir(const char *pathname, mode_t mode); #define TAOS_ALLOC_MODE_DEFAULT 0 #define TAOS_ALLOC_MODE_RANDOM_FAIL 1 diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index aa5bfe322a..399992aa55 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -772,3 +772,9 @@ void taosRemoveDir(char *rootDir) { uPrint("dir:%s is removed", rootDir); } + +int tmkdir(const char *path, mode_t mode) { + int code = mkdir(path, 0755); + if (code < 0 && errno == EEXIST) code = 0; + return code; +} diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index b05b0db4c9..41669fc691 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -71,14 +71,12 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { tstrncpy(pWal->path, path, sizeof(pWal->path)); pthread_mutex_init(&pWal->mutex, NULL); - if (access(path, F_OK) != 0) { - if (mkdir(path, 0755) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - wError("wal:%s, failed to create directory(%s)", path, strerror(errno)); - pthread_mutex_destroy(&pWal->mutex); - free(pWal); - pWal = NULL; - } + if (tmkdir(path, 0755) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + wError("wal:%s, failed to create directory(%s)", path, strerror(errno)); + pthread_mutex_destroy(&pWal->mutex); + free(pWal); + pWal = NULL; } if (pCfg->keep == 1) return pWal; @@ -86,16 +84,15 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { if (walHandleExistingFiles(path) == 0) walRenew(pWal); - if (pWal->fd <0) { + if (pWal && pWal->fd <0) { terrno = TAOS_SYSTEM_ERROR(errno); wError("wal:%s, failed to open(%s)", path, strerror(errno)); pthread_mutex_destroy(&pWal->mutex); free(pWal); pWal = NULL; - } else { - wTrace("wal:%s, it is open, level:%d", path, pWal->level); - } + } + if (pWal) wTrace("wal:%s, it is open, level:%d", path, pWal->level); return pWal; } @@ -218,10 +215,13 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int)) if ( pWal->keep == 0) strcpy(opath+slen, "/old"); - // is there old directory? - if (access(opath, F_OK)) return 0; - DIR *dir = opendir(opath); + if (dir == NULL && errno == ENOENT) return 0; + if (dir == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } + while ((ent = readdir(dir))!= NULL) { if ( strncmp(ent->d_name, walPrefix, plen) == 0) { index = atol(ent->d_name + plen); @@ -379,12 +379,10 @@ int walHandleExistingFiles(const char *path) { if ( strncmp(ent->d_name, walPrefix, plen) == 0) { snprintf(oname, sizeof(oname), "%s/%s", path, ent->d_name); snprintf(nname, sizeof(nname), "%s/old/%s", path, ent->d_name); - if (access(opath, F_OK) != 0) { - if (mkdir(opath, 0755) != 0) { - wError("wal:%s, failed to create directory:%s(%s)", oname, opath, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - break; - } + if (tmkdir(opath, 0755) != 0) { + wError("wal:%s, failed to create directory:%s(%s)", oname, opath, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + break; } if (rename(oname, nname) < 0) { @@ -409,10 +407,14 @@ static int walRemoveWalFiles(const char *path) { char name[TSDB_FILENAME_LEN * 3]; terrno = 0; - if (access(path, F_OK) != 0) return 0; struct dirent *ent; DIR *dir = opendir(path); + if (dir == NULL && errno == ENOENT) return 0; + if (dir == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } while ((ent = readdir(dir))!= NULL) { if ( strncmp(ent->d_name, walPrefix, plen) == 0) { -- GitLab