Merge pull request #2230 from taosdata/hotfix/snprintf
use snprintf whenever possible
This commit is contained in:
commit
e6985f8e44
|
@ -425,6 +425,8 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
|
||||||
taosTmrReset(rpcProcessIdleTimer, pRpc->idleTime, pConn, pRpc->tmrCtrl, &pConn->pIdleTimer);
|
taosTmrReset(rpcProcessIdleTimer, pRpc->idleTime, pConn, pRpc->tmrCtrl, &pConn->pIdleTimer);
|
||||||
rpcSendMsgToPeer(pConn, msg, msgLen);
|
rpcSendMsgToPeer(pConn, msg, msgLen);
|
||||||
pConn->secured = 1; // connection shall be secured
|
pConn->secured = 1; // connection shall be secured
|
||||||
|
pConn->pReqMsg = NULL;
|
||||||
|
pConn->reqMsgLen = 0;
|
||||||
|
|
||||||
rpcUnlockConn(pConn);
|
rpcUnlockConn(pConn);
|
||||||
rpcDecRef(pRpc); // decrease the referene count
|
rpcDecRef(pRpc); // decrease the referene count
|
||||||
|
@ -542,7 +544,7 @@ static void rpcCloseConn(void *thandle) {
|
||||||
|
|
||||||
if ( pRpc->connType == TAOS_CONN_SERVER) {
|
if ( pRpc->connType == TAOS_CONN_SERVER) {
|
||||||
char hashstr[40] = {0};
|
char hashstr[40] = {0};
|
||||||
size_t size = sprintf(hashstr, "%x:%x:%x:%d", pConn->peerIp, pConn->linkUid, pConn->peerId, pConn->connType);
|
size_t size = snprintf(hashstr, sizeof(hashstr), "%x:%x:%x:%d", pConn->peerIp, pConn->linkUid, pConn->peerId, pConn->connType);
|
||||||
taosHashRemove(pRpc->hash, hashstr, size);
|
taosHashRemove(pRpc->hash, hashstr, size);
|
||||||
|
|
||||||
rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg
|
rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg
|
||||||
|
@ -592,7 +594,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
|
||||||
char hashstr[40] = {0};
|
char hashstr[40] = {0};
|
||||||
SRpcHead *pHead = (SRpcHead *)pRecv->msg;
|
SRpcHead *pHead = (SRpcHead *)pRecv->msg;
|
||||||
|
|
||||||
size_t size = sprintf(hashstr, "%x:%x:%x:%d", pRecv->ip, pHead->linkUid, pHead->sourceId, pRecv->connType);
|
size_t size = snprintf(hashstr, sizeof(hashstr), "%x:%x:%x:%d", pRecv->ip, pHead->linkUid, pHead->sourceId, pRecv->connType);
|
||||||
|
|
||||||
// check if it is already allocated
|
// check if it is already allocated
|
||||||
SRpcConn **ppConn = (SRpcConn **)(taosHashGet(pRpc->hash, hashstr, size));
|
SRpcConn **ppConn = (SRpcConn **)(taosHashGet(pRpc->hash, hashstr, size));
|
||||||
|
@ -682,7 +684,7 @@ static SRpcConn *rpcSetupConnToServer(SRpcReqContext *pContext) {
|
||||||
if (pConn) {
|
if (pConn) {
|
||||||
pConn->tretry = 0;
|
pConn->tretry = 0;
|
||||||
pConn->ahandle = pContext->ahandle;
|
pConn->ahandle = pContext->ahandle;
|
||||||
sprintf(pConn->info, "%s %p %p", pRpc->label, pConn, pConn->ahandle);
|
snprintf(pConn->info, sizeof(pConn->info), "%s %p %p", pRpc->label, pConn, pConn->ahandle);
|
||||||
pConn->tretry = 0;
|
pConn->tretry = 0;
|
||||||
} else {
|
} else {
|
||||||
tError("%s %p, failed to set up connection(%s)", pRpc->label, pContext->ahandle, tstrerror(terrno));
|
tError("%s %p, failed to set up connection(%s)", pRpc->label, pContext->ahandle, tstrerror(terrno));
|
||||||
|
@ -811,7 +813,7 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) {
|
||||||
|
|
||||||
if (rpcIsReq(pHead->msgType)) {
|
if (rpcIsReq(pHead->msgType)) {
|
||||||
pConn->ahandle = (void *)pHead->ahandle;
|
pConn->ahandle = (void *)pHead->ahandle;
|
||||||
sprintf(pConn->info, "%s %p %p", pRpc->label, pConn, pConn->ahandle);
|
snprintf(pConn->info, sizeof(pConn->info), "%s %p %p", pRpc->label, pConn, pConn->ahandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
sid = pConn->sid;
|
sid = pConn->sid;
|
||||||
|
|
|
@ -44,7 +44,7 @@ typedef struct {
|
||||||
uint32_t id; // increase continuously
|
uint32_t id; // increase continuously
|
||||||
int num; // number of wal files
|
int num; // number of wal files
|
||||||
char path[TSDB_FILENAME_LEN];
|
char path[TSDB_FILENAME_LEN];
|
||||||
char name[TSDB_FILENAME_LEN];
|
char name[TSDB_FILENAME_LEN+16];
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
} SWal;
|
} SWal;
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ void walClose(void *handle) {
|
||||||
if (pWal->keep == 0) {
|
if (pWal->keep == 0) {
|
||||||
// remove all files in the directory
|
// remove all files in the directory
|
||||||
for (int i=0; i<pWal->num; ++i) {
|
for (int i=0; i<pWal->num; ++i) {
|
||||||
sprintf(pWal->name, "%s/%s%d", pWal->path, walPrefix, pWal->id-i);
|
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%d", pWal->path, walPrefix, pWal->id-i);
|
||||||
if (remove(pWal->name) <0) {
|
if (remove(pWal->name) <0) {
|
||||||
wError("wal:%s, failed to remove", pWal->name);
|
wError("wal:%s, failed to remove", pWal->name);
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,7 +140,7 @@ int walRenew(void *handle) {
|
||||||
|
|
||||||
pWal->num++;
|
pWal->num++;
|
||||||
|
|
||||||
sprintf(pWal->name, "%s/%s%d", pWal->path, walPrefix, pWal->id);
|
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%d", pWal->path, walPrefix, pWal->id);
|
||||||
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
|
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
|
|
||||||
if (pWal->fd < 0) {
|
if (pWal->fd < 0) {
|
||||||
|
@ -152,7 +152,7 @@ int walRenew(void *handle) {
|
||||||
if (pWal->num > pWal->max) {
|
if (pWal->num > pWal->max) {
|
||||||
// remove the oldest wal file
|
// remove the oldest wal file
|
||||||
char name[TSDB_FILENAME_LEN * 3];
|
char name[TSDB_FILENAME_LEN * 3];
|
||||||
sprintf(name, "%s/%s%d", pWal->path, walPrefix, pWal->id - pWal->max);
|
snprintf(name, sizeof(name), "%s/%s%d", pWal->path, walPrefix, pWal->id - pWal->max);
|
||||||
if (remove(name) <0) {
|
if (remove(name) <0) {
|
||||||
wError("wal:%s, failed to remove(%s)", name, strerror(errno));
|
wError("wal:%s, failed to remove(%s)", name, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
|
@ -214,7 +214,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int))
|
||||||
int plen = strlen(walPrefix);
|
int plen = strlen(walPrefix);
|
||||||
char opath[TSDB_FILENAME_LEN+5];
|
char opath[TSDB_FILENAME_LEN+5];
|
||||||
|
|
||||||
int slen = sprintf(opath, "%s", pWal->path);
|
int slen = snprintf(opath, sizeof(opath), "%s", pWal->path);
|
||||||
if ( pWal->keep == 0)
|
if ( pWal->keep == 0)
|
||||||
strcpy(opath+slen, "/old");
|
strcpy(opath+slen, "/old");
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int))
|
||||||
wTrace("wal:%s, %d files will be restored", opath, count);
|
wTrace("wal:%s, %d files will be restored", opath, count);
|
||||||
|
|
||||||
for (index = minId; index<=maxId; ++index) {
|
for (index = minId; index<=maxId; ++index) {
|
||||||
sprintf(pWal->name, "%s/%s%d", opath, walPrefix, index);
|
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%d", opath, walPrefix, index);
|
||||||
terrno = walRestoreWalFile(pWal, pVnode, writeFp);
|
terrno = walRestoreWalFile(pWal, pVnode, writeFp);
|
||||||
if (terrno < 0) break;
|
if (terrno < 0) break;
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int))
|
||||||
// open the existing WAL file in append mode
|
// open the existing WAL file in append mode
|
||||||
pWal->num = count;
|
pWal->num = count;
|
||||||
pWal->id = maxId;
|
pWal->id = maxId;
|
||||||
sprintf(pWal->name, "%s/%s%d", opath, walPrefix, maxId);
|
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%d", opath, walPrefix, maxId);
|
||||||
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
|
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
if (pWal->fd < 0) {
|
if (pWal->fd < 0) {
|
||||||
wError("wal:%s, failed to open file(%s)", pWal->name, strerror(errno));
|
wError("wal:%s, failed to open file(%s)", pWal->name, strerror(errno));
|
||||||
|
@ -361,7 +361,7 @@ int walHandleExistingFiles(const char *path) {
|
||||||
char nname[TSDB_FILENAME_LEN * 3];
|
char nname[TSDB_FILENAME_LEN * 3];
|
||||||
char opath[TSDB_FILENAME_LEN];
|
char opath[TSDB_FILENAME_LEN];
|
||||||
|
|
||||||
sprintf(opath, "%s/old", path);
|
snprintf(opath, sizeof(opath), "%s/old", path);
|
||||||
|
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
|
@ -377,8 +377,8 @@ int walHandleExistingFiles(const char *path) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while ((ent = readdir(dir))!= NULL) {
|
while ((ent = readdir(dir))!= NULL) {
|
||||||
if ( strncmp(ent->d_name, walPrefix, plen) == 0) {
|
if ( strncmp(ent->d_name, walPrefix, plen) == 0) {
|
||||||
sprintf(oname, "%s/%s", path, ent->d_name);
|
snprintf(oname, sizeof(oname), "%s/%s", path, ent->d_name);
|
||||||
sprintf(nname, "%s/old/%s", path, ent->d_name);
|
snprintf(nname, sizeof(nname), "%s/old/%s", path, ent->d_name);
|
||||||
if (access(opath, F_OK) != 0) {
|
if (access(opath, F_OK) != 0) {
|
||||||
if (mkdir(opath, 0755) != 0) {
|
if (mkdir(opath, 0755) != 0) {
|
||||||
wError("wal:%s, failed to create directory:%s(%s)", oname, opath, strerror(errno));
|
wError("wal:%s, failed to create directory:%s(%s)", oname, opath, strerror(errno));
|
||||||
|
@ -416,7 +416,7 @@ static int walRemoveWalFiles(const char *path) {
|
||||||
|
|
||||||
while ((ent = readdir(dir))!= NULL) {
|
while ((ent = readdir(dir))!= NULL) {
|
||||||
if ( strncmp(ent->d_name, walPrefix, plen) == 0) {
|
if ( strncmp(ent->d_name, walPrefix, plen) == 0) {
|
||||||
sprintf(name, "%s/%s", path, ent->d_name);
|
snprintf(name, sizeof(name), "%s/%s", path, ent->d_name);
|
||||||
if (remove(name) <0) {
|
if (remove(name) <0) {
|
||||||
wError("wal:%s, failed to remove(%s)", name, strerror(errno));
|
wError("wal:%s, failed to remove(%s)", name, strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
|
Loading…
Reference in New Issue