Merge pull request #26776 from taosdata/fix/TD-31073.3
enh: os return code optimization
This commit is contained in:
commit
c068e58241
|
@ -65,7 +65,7 @@ typedef int (*__compar_fn_t)(const void *, const void *);
|
|||
#endif
|
||||
#define ssize_t int
|
||||
#define _SSIZE_T_
|
||||
#define bzero(ptr, size) memset((ptr), 0, (size))
|
||||
#define bzero(ptr, size) (void)memset((ptr), 0, (size))
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define wcsncasecmp _wcsnicmp
|
||||
|
|
|
@ -114,8 +114,6 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
|||
|
||||
bool taosValidFile(TdFilePtr pFile);
|
||||
|
||||
int32_t taosGetErrorFile(TdFilePtr pFile);
|
||||
|
||||
int32_t taosCompressFile(char *srcFileName, char *destFileName);
|
||||
|
||||
int32_t taosSetFileHandlesLimit();
|
||||
|
|
|
@ -30,7 +30,7 @@ extern "C" {
|
|||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
void taosGetSystemLocale(char *outLocale, char *outCharset);
|
||||
void taosSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
int32_t taosSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -49,11 +49,14 @@ typedef BOOL (*FSignalHandler)(DWORD fdwCtrlType);
|
|||
#else
|
||||
typedef void (*FSignalHandler)(int32_t signum, void *sigInfo, void *context);
|
||||
#endif
|
||||
void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||
void taosIgnSignal(int32_t signum);
|
||||
void taosDflSignal(int32_t signum);
|
||||
|
||||
void taosKillChildOnParentStopped();
|
||||
typedef void (*sighandler_t)(int);
|
||||
|
||||
int32_t taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||
int32_t taosIgnSignal(int32_t signum);
|
||||
int32_t taosDflSignal(int32_t signum);
|
||||
|
||||
int32_t taosKillChildOnParentStopped();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -159,13 +159,12 @@ TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, st
|
|||
|
||||
int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen);
|
||||
|
||||
void taosBlockSIGPIPE();
|
||||
uint32_t taosGetIpv4FromFqdn(const char *);
|
||||
int32_t taosBlockSIGPIPE();
|
||||
int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip);
|
||||
int32_t taosGetFqdn(char *);
|
||||
void tinet_ntoa(char *ipstr, uint32_t ip);
|
||||
uint32_t ip2uint(const char *const ip_addr);
|
||||
void taosIgnSIGPIPE();
|
||||
void taosSetMaskSIGPIPE();
|
||||
int32_t taosIgnSIGPIPE();
|
||||
uint32_t taosInetAddr(const char *ipAddr);
|
||||
const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len);
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs);
|
|||
int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv);
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len);
|
||||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
|
||||
TdUcs4 *tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
|
||||
int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len);
|
||||
int32_t taosHexDecode(const char *src, char *dst, int32_t len);
|
||||
|
|
|
@ -44,7 +44,7 @@ int64_t taosGetLineCmd(TdCmdPtr pCmd, char **__restrict ptrBuf);
|
|||
|
||||
int32_t taosEOFCmd(TdCmdPtr pCmd);
|
||||
|
||||
int64_t taosCloseCmd(TdCmdPtr *ppCmd);
|
||||
void taosCloseCmd(TdCmdPtr *ppCmd);
|
||||
|
||||
void *taosLoadDll(const char *filename);
|
||||
|
||||
|
@ -54,11 +54,11 @@ void taosCloseDll(void *handle);
|
|||
|
||||
int32_t taosSetConsoleEcho(bool on);
|
||||
|
||||
void taosSetTerminalMode();
|
||||
int32_t taosSetTerminalMode();
|
||||
|
||||
int32_t taosGetOldTerminalMode();
|
||||
|
||||
void taosResetTerminalMode();
|
||||
int32_t taosResetTerminalMode();
|
||||
|
||||
#define STACKSIZE 100
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
|
|||
char buf[TSDB_PASSWORD_LEN + 1];
|
||||
|
||||
buf[TSDB_PASSWORD_LEN] = 0;
|
||||
sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1],
|
||||
(void)sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1],
|
||||
context.digest[2], context.digest[3], context.digest[4], context.digest[5], context.digest[6],
|
||||
context.digest[7], context.digest[8], context.digest[9], context.digest[10], context.digest[11],
|
||||
context.digest[12], context.digest[13], context.digest[14], context.digest[15]);
|
||||
|
@ -108,10 +108,10 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
int32_t offset = 0;
|
||||
if (prefix < 0) {
|
||||
offset = -1 * prefix;
|
||||
strncpy(tbName, tbname, offset);
|
||||
(void)strncpy(tbName, tbname, offset);
|
||||
}
|
||||
if (suffix < 0) {
|
||||
strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
|
||||
(void)strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
|
||||
offset += -1 * suffix;
|
||||
}
|
||||
return MurmurHash3_32(tbName, offset);
|
||||
|
|
|
@ -1368,8 +1368,9 @@ int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSe
|
|||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return terrno;
|
||||
}
|
||||
uint32_t addr = taosGetIpv4FromFqdn(mgmtEpSet->eps[mgmtEpSet->numOfEps].fqdn);
|
||||
if (addr == 0xffffffff) {
|
||||
uint32_t addr = 0;
|
||||
code = taosGetIpv4FromFqdn(mgmtEpSet->eps[mgmtEpSet->numOfEps].fqdn, &addr);
|
||||
if (code) {
|
||||
tscError("failed to resolve firstEp fqdn: %s, code:%s", mgmtEpSet->eps[mgmtEpSet->numOfEps].fqdn,
|
||||
tstrerror(TSDB_CODE_TSC_INVALID_FQDN));
|
||||
memset(&(mgmtEpSet->eps[mgmtEpSet->numOfEps]), 0, sizeof(mgmtEpSet->eps[mgmtEpSet->numOfEps]));
|
||||
|
@ -1385,8 +1386,9 @@ int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSe
|
|||
}
|
||||
|
||||
taosGetFqdnPortFromEp(secondEp, &mgmtEpSet->eps[mgmtEpSet->numOfEps]);
|
||||
uint32_t addr = taosGetIpv4FromFqdn(mgmtEpSet->eps[mgmtEpSet->numOfEps].fqdn);
|
||||
if (addr == 0xffffffff) {
|
||||
uint32_t addr = 0;
|
||||
int32_t code = taosGetIpv4FromFqdn(mgmtEpSet->eps[mgmtEpSet->numOfEps].fqdn, &addr);
|
||||
if (code) {
|
||||
tscError("failed to resolve secondEp fqdn: %s, code:%s", mgmtEpSet->eps[mgmtEpSet->numOfEps].fqdn,
|
||||
tstrerror(TSDB_CODE_TSC_INVALID_FQDN));
|
||||
memset(&(mgmtEpSet->eps[mgmtEpSet->numOfEps]), 0, sizeof(mgmtEpSet->eps[mgmtEpSet->numOfEps]));
|
||||
|
|
|
@ -1354,8 +1354,9 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *
|
|||
}
|
||||
|
||||
static int32_t taosCheckGlobalCfg() {
|
||||
uint32_t ipv4 = taosGetIpv4FromFqdn(tsLocalFqdn);
|
||||
if (ipv4 == 0xffffffff) {
|
||||
uint32_t ipv4 = 0;
|
||||
int32_t code = taosGetIpv4FromFqdn(tsLocalFqdn, &ipv4);
|
||||
if (code) {
|
||||
terrno = TSDB_CODE_RPC_FQDN_ERROR;
|
||||
uError("failed to get ip from fqdn:%s since %s, dnode can not be initialized", tsLocalFqdn, terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -337,10 +337,13 @@ int64_t mndGetIpWhiteVer(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
int32_t mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8_t type, bool *pUpdate) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
bool update = false;
|
||||
SIpV4Range range = {.ip = taosGetIpv4FromFqdn(fqdn), .mask = 32};
|
||||
SIpV4Range range = {.ip = 0, .mask = 32};
|
||||
int32_t code = taosGetIpv4FromFqdn(fqdn, &range.ip);
|
||||
if (code) {
|
||||
//TODO
|
||||
}
|
||||
mDebug("ip-white-list may update for user: %s, fqdn: %s", user, fqdn);
|
||||
SIpWhiteList **ppList = taosHashGet(pIpWhiteTab, user, strlen(user));
|
||||
SIpWhiteList *pList = NULL;
|
||||
|
|
|
@ -48,8 +48,8 @@ bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId*
|
|||
"dnode:%d cluster:%" PRId64 " fqdn:%s port:%u ",
|
||||
vgId, tsResolveFQDNRetryTime, pInfo->nodeId, pInfo->clusterId, pInfo->nodeFqdn, pInfo->nodePort);
|
||||
for (int i = 0; i < tsResolveFQDNRetryTime; i++) {
|
||||
ipv4 = taosGetIpv4FromFqdn(pInfo->nodeFqdn);
|
||||
if (ipv4 == 0xFFFFFFFF || ipv4 == 1) {
|
||||
int32_t code = taosGetIpv4FromFqdn(pInfo->nodeFqdn, &ipv4);
|
||||
if (code) {
|
||||
sError("failed to resolve ipv4 addr, fqdn:%s, wait one second", pInfo->nodeFqdn);
|
||||
taosSsleep(1);
|
||||
} else {
|
||||
|
|
|
@ -525,8 +525,9 @@ void syncUtilU642Addr(uint64_t u64, char *host, int64_t len, uint16_t *port) {
|
|||
}
|
||||
|
||||
uint64_t syncUtilAddr2U64(const char *host, uint16_t port) {
|
||||
uint32_t hostU32 = taosGetIpv4FromFqdn(host);
|
||||
if (hostU32 == (uint32_t)-1) {
|
||||
uint32_t hostU32 = 0;
|
||||
int32_t code = taosGetIpv4FromFqdn(host, &hostU32);
|
||||
if (code) {
|
||||
sError("failed to resolve ipv4 addr, host:%s", host);
|
||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return -1;
|
||||
|
|
|
@ -190,8 +190,9 @@ _OVER:
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, struct sockaddr_in* dest) {
|
||||
uint32_t ip = taosGetIpv4FromFqdn(server);
|
||||
if (ip == 0xffffffff) {
|
||||
uint32_t ip = 0;
|
||||
int32_t code = taosGetIpv4FromFqdn(server, &ip);
|
||||
if (code) {
|
||||
tError("http-report failed to resolving domain names: %s", server);
|
||||
return TSDB_CODE_RPC_FQDN_ERROR;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ void (*taosUnRefHandle[])(void* handle) = {transUnrefSrvHandle, transUnrefCliHan
|
|||
int (*transReleaseHandle[])(void* handle) = {transReleaseSrvHandle, transReleaseCliHandle};
|
||||
|
||||
static int32_t transValidLocalFqdn(const char* localFqdn, uint32_t* ip) {
|
||||
*ip = taosGetIpv4FromFqdn(localFqdn);
|
||||
if (*ip == 0xFFFFFFFF) {
|
||||
int32_t code = taosGetIpv4FromFqdn(localFqdn, ip);
|
||||
if (code) {
|
||||
terrno = TSDB_CODE_RPC_FQDN_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ static FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr);
|
|||
|
||||
static FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* resp);
|
||||
|
||||
static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn);
|
||||
static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ip);
|
||||
static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn);
|
||||
|
||||
static FORCE_INLINE void cliMayUpdateFqdnCache(SHashObj* cache, char* dst);
|
||||
|
@ -1253,8 +1253,9 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) {
|
|||
conn->pBatch = pBatch;
|
||||
conn->dstAddr = taosStrdup(pList->dst);
|
||||
|
||||
uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, pList->ip);
|
||||
if (ipaddr == 0xffffffff) {
|
||||
uint32_t ipaddr = 0;
|
||||
int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, pList->ip, &ipaddr);
|
||||
if (code) {
|
||||
uv_timer_stop(conn->timer);
|
||||
conn->timer->data = NULL;
|
||||
taosArrayPush(pThrd->timerList, &conn->timer);
|
||||
|
@ -1561,28 +1562,28 @@ FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn) {
|
||||
uint32_t addr = 0;
|
||||
static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ip) {
|
||||
size_t len = strlen(fqdn);
|
||||
uint32_t* v = taosHashGet(cache, fqdn, len);
|
||||
if (v == NULL) {
|
||||
addr = taosGetIpv4FromFqdn(fqdn);
|
||||
if (addr == 0xffffffff) {
|
||||
terrno = TSDB_CODE_RPC_FQDN_ERROR;
|
||||
int32_t code = taosGetIpv4FromFqdn(fqdn, ip);
|
||||
if (code) {
|
||||
tError("failed to get ip from fqdn:%s since %s", fqdn, terrstr());
|
||||
return addr;
|
||||
return code;
|
||||
}
|
||||
|
||||
taosHashPut(cache, fqdn, len, &addr, sizeof(addr));
|
||||
taosHashPut(cache, fqdn, len, ip, sizeof(*ip));
|
||||
} else {
|
||||
addr = *v;
|
||||
*ip = *v;
|
||||
}
|
||||
return addr;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn) {
|
||||
// impl later
|
||||
uint32_t addr = taosGetIpv4FromFqdn(fqdn);
|
||||
if (addr != 0xffffffff) {
|
||||
uint32_t addr = 0;
|
||||
int32_t code = taosGetIpv4FromFqdn(fqdn, &addr);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
size_t len = strlen(fqdn);
|
||||
uint32_t* v = taosHashGet(cache, fqdn, len);
|
||||
if (addr != *v) {
|
||||
|
@ -1671,8 +1672,9 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
|
|||
|
||||
conn->dstAddr = taosStrdup(addr);
|
||||
|
||||
uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn);
|
||||
if (ipaddr == 0xffffffff) {
|
||||
uint32_t ipaddr = 0;
|
||||
int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn, &ipaddr);
|
||||
if (code) {
|
||||
uv_timer_stop(conn->timer);
|
||||
conn->timer->data = NULL;
|
||||
taosArrayPush(pThrd->timerList, &conn->timer);
|
||||
|
|
|
@ -695,18 +695,21 @@ int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) {
|
|||
|
||||
int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
||||
#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
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int64_t leftbytes = count;
|
||||
int64_t readbytes;
|
||||
char *tbuf = (char *)buf;
|
||||
int32_t code = 0;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
#ifdef WINDOWS
|
||||
|
@ -718,14 +721,16 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
|||
if (errno == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return -1;
|
||||
terrno = code;
|
||||
return terrno;
|
||||
}
|
||||
} else if (readbytes == 0) {
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return (int64_t)(count - leftbytes);
|
||||
}
|
||||
|
@ -735,28 +740,32 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
|||
}
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
||||
if (pFile == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return 0;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockWrlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockWrlock(&(pFile->rwlock));
|
||||
#endif
|
||||
if (pFile->fd < 0) {
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t nleft = count;
|
||||
int64_t nwritten = 0;
|
||||
char *tbuf = (char *)buf;
|
||||
int32_t code = 0;
|
||||
|
||||
while (nleft > 0) {
|
||||
nwritten = write(pFile->fd, (void *)tbuf, (uint32_t)nleft);
|
||||
|
@ -764,9 +773,11 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
|||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
terrno = code;
|
||||
return -1;
|
||||
}
|
||||
nleft -= nwritten;
|
||||
|
@ -774,25 +785,30 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
|||
}
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) {
|
||||
if (pFile == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockWrlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockWrlock(&(pFile->rwlock));
|
||||
#endif
|
||||
ASSERT(pFile->fd >= 0); // Please check if you have closed the file.
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
if (pFile->fd < 0) {
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
DWORD ret = 0;
|
||||
OVERLAPPED ol = {0};
|
||||
|
@ -808,39 +824,63 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t
|
|||
}
|
||||
#else
|
||||
int64_t ret = pwrite(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
|
||||
|
||||
if (code) {
|
||||
terrno = code;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
||||
if (pFile == NULL || pFile->fd < 0) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
#endif
|
||||
|
||||
int32_t code = 0;
|
||||
ASSERT(pFile->fd >= 0); // Please check if you have closed the file.
|
||||
|
||||
#ifdef WINDOWS
|
||||
int64_t ret = _lseeki64(pFile->fd, offset, whence);
|
||||
#else
|
||||
int64_t ret = lseek(pFile->fd, offset, whence);
|
||||
if (-1 == ret) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
||||
if (pFile == NULL) {
|
||||
return 0;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
ASSERT(pFile->fd >= 0); // Please check if you have closed the file.
|
||||
|
||||
if (pFile->fd < 0) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -850,7 +890,8 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
|||
struct stat fileStat;
|
||||
int32_t code = fstat(pFile->fd, &fileStat);
|
||||
#endif
|
||||
if (code < 0) {
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -866,10 +907,11 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
|||
}
|
||||
|
||||
int32_t taosLockFile(TdFilePtr pFile) {
|
||||
ASSERT(pFile->fd >= 0); // Please check if you have closed the file.
|
||||
if (pFile->fd < 0) {
|
||||
return -1;
|
||||
if (NULL == pFile || pFile->fd < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
BOOL fSuccess = FALSE;
|
||||
LARGE_INTEGER fileSize;
|
||||
|
@ -888,15 +930,21 @@ int32_t taosLockFile(TdFilePtr pFile) {
|
|||
}
|
||||
return 0;
|
||||
#else
|
||||
return (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB);
|
||||
int32_t code = (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t taosUnLockFile(TdFilePtr pFile) {
|
||||
ASSERT(pFile->fd >= 0);
|
||||
if (pFile->fd < 0) {
|
||||
return 0;
|
||||
if (NULL == pFile || pFile->fd < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
BOOL fSuccess = FALSE;
|
||||
OVERLAPPED overlapped = {0};
|
||||
|
@ -908,18 +956,21 @@ int32_t taosUnLockFile(TdFilePtr pFile) {
|
|||
}
|
||||
return 0;
|
||||
#else
|
||||
return (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB);
|
||||
int32_t code = (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||
if (pFile == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (pFile->fd < 0) {
|
||||
printf("Ftruncate file error, fd arg was negative\n");
|
||||
return -1;
|
||||
if (NULL == pFile || pFile->fd < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
||||
HANDLE h = (HANDLE)_get_osfhandle(pFile->fd);
|
||||
|
@ -965,17 +1016,23 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
|||
|
||||
return 0;
|
||||
#else
|
||||
return ftruncate(pFile->fd, l_size);
|
||||
int32_t code = ftruncate(pFile->fd, l_size);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) {
|
||||
if (pFileOut == NULL || pFileIn == NULL) {
|
||||
return 0;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
ASSERT(pFileIn->fd >= 0 && pFileOut->fd >= 0);
|
||||
if (pFileIn->fd < 0 || pFileOut->fd < 0) {
|
||||
return 0;
|
||||
if (pFileIn->fd < 0 || pFileOut->fd < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -1055,7 +1112,8 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
|||
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
} else if (sentbytes == 0) {
|
||||
return (int64_t)(size - leftbytes);
|
||||
|
@ -1068,7 +1126,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
|||
#endif
|
||||
}
|
||||
|
||||
bool lastErrorIsFileNotExist() { return errno == ENOENT; }
|
||||
bool lastErrorIsFileNotExist() { return terrno == TAOS_SYSTEM_ERROR(ENOENT); }
|
||||
|
||||
#endif // WINDOWS
|
||||
|
||||
|
@ -1175,22 +1233,26 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
|
|||
|
||||
int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) {
|
||||
if (pFile == NULL) {
|
||||
return 0;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
|
||||
#ifdef WINDOWS
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
#endif
|
||||
ASSERT(pFile->hFile != NULL); // Please check if you have closed the file.
|
||||
|
||||
if (pFile->hFile == NULL) {
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return -1;
|
||||
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
DWORD ret = 0;
|
||||
OVERLAPPED ol = {0};
|
||||
ol.OffsetHigh = (uint32_t)((offset & 0xFFFFFFFF00000000LL) >> 0x20);
|
||||
|
@ -1206,13 +1268,13 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
|||
#if FILE_WITH_LOCK
|
||||
(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
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
int64_t ret = pread(pFile->fd, buf, count, offset);
|
||||
if (-1 == ret) {
|
||||
|
@ -1223,7 +1285,10 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
|||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
|
||||
terrno = code;
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1243,7 +1308,7 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
return code;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -1272,7 +1337,7 @@ void taosFprintfFile(TdFilePtr pFile, const char *format, ...) {
|
|||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vfprintf(pFile->fp, format, ap);
|
||||
(void)vfprintf(pFile->fp, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
@ -1292,22 +1357,26 @@ int32_t taosUmaskFile(int32_t maskVal) {
|
|||
#endif
|
||||
}
|
||||
|
||||
int32_t taosGetErrorFile(TdFilePtr pFile) { return errno; }
|
||||
int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) {
|
||||
int64_t ret = -1;
|
||||
int32_t code = 0;
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
#endif
|
||||
if (pFile == NULL || ptrBuf == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
goto END;
|
||||
}
|
||||
if (*ptrBuf != NULL) {
|
||||
taosMemoryFreeClear(*ptrBuf);
|
||||
}
|
||||
ASSERT(pFile->fp != NULL);
|
||||
|
||||
if (pFile->fp == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
goto END;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
size_t bufferSize = 512;
|
||||
*ptrBuf = taosMemoryMalloc(bufferSize);
|
||||
|
@ -1344,35 +1413,55 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) {
|
|||
#else
|
||||
size_t len = 0;
|
||||
ret = getline(ptrBuf, &len, pFile->fp);
|
||||
if (-1 == ret) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
#endif
|
||||
|
||||
END:
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
|
||||
if (code) {
|
||||
terrno = code;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int64_t taosGetsFile(TdFilePtr pFile, int32_t maxSize, char *__restrict buf) {
|
||||
if (pFile == NULL || buf == NULL) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
ASSERT(pFile->fp != NULL);
|
||||
|
||||
if (pFile->fp == NULL) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (fgets(buf, maxSize, pFile->fp) == NULL) {
|
||||
return -1;
|
||||
if (feof(pFile->fp)) {
|
||||
return 0;
|
||||
} else {
|
||||
terrno = TAOS_SYSTEM_ERROR(ferror(pFile->fp));
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
return strlen(buf);
|
||||
}
|
||||
|
||||
int32_t taosEOFFile(TdFilePtr pFile) {
|
||||
if (pFile == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
}
|
||||
ASSERT(pFile->fp != NULL);
|
||||
if (pFile->fp == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1406,14 +1495,17 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
|||
int32_t compressSize = 163840;
|
||||
int32_t ret = 0;
|
||||
int32_t len = 0;
|
||||
char *data = taosMemoryMalloc(compressSize);
|
||||
gzFile dstFp = NULL;
|
||||
|
||||
TdFilePtr pSrcFile = NULL;
|
||||
|
||||
char *data = taosMemoryMalloc(compressSize);
|
||||
if (NULL == data) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pSrcFile = taosOpenFile(srcFileName, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pSrcFile == NULL) {
|
||||
ret = -1;
|
||||
ret = terrno;
|
||||
goto cmp_end;
|
||||
}
|
||||
|
||||
|
@ -1424,39 +1516,45 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
|||
int32_t pmode = S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
#endif
|
||||
int fd = open(destFileName, access, pmode);
|
||||
if (fd < 0) {
|
||||
ret = -2;
|
||||
if (-1 == fd) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
ret = terrno;
|
||||
goto cmp_end;
|
||||
}
|
||||
|
||||
// Both gzclose() and fclose() will close the associated fd, so they need to have different fds.
|
||||
FileFd gzFd = dup(fd);
|
||||
if (gzFd < 0) {
|
||||
ret = -4;
|
||||
if (-1 == gzFd) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
ret = terrno;
|
||||
goto cmp_end;
|
||||
}
|
||||
dstFp = gzdopen(gzFd, "wb6f");
|
||||
if (dstFp == NULL) {
|
||||
ret = -3;
|
||||
close(gzFd);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
ret = terrno;
|
||||
(void)close(gzFd);
|
||||
goto cmp_end;
|
||||
}
|
||||
|
||||
while (!feof(pSrcFile->fp)) {
|
||||
len = (int32_t)fread(data, 1, compressSize, pSrcFile->fp);
|
||||
(void)gzwrite(dstFp, data, len);
|
||||
if (len > 0) {
|
||||
(void)gzwrite(dstFp, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
cmp_end:
|
||||
|
||||
if (fd >= 0) {
|
||||
close(fd);
|
||||
(void)close(fd);
|
||||
}
|
||||
if (pSrcFile) {
|
||||
taosCloseFile(&pSrcFile);
|
||||
(void)taosCloseFile(&pSrcFile);
|
||||
}
|
||||
|
||||
if (dstFp) {
|
||||
gzclose(dstFp);
|
||||
(void)gzclose(dstFp);
|
||||
}
|
||||
|
||||
taosMemoryFree(data);
|
||||
|
@ -1475,23 +1573,31 @@ int32_t taosSetFileHandlesLimit() {
|
|||
|
||||
int32_t taosLinkFile(char *src, char *dst) {
|
||||
#ifndef WINDOWS
|
||||
if (link(src, dst) != 0) {
|
||||
if (errno == EXDEV || errno == ENOTSUP) {
|
||||
return -1;
|
||||
}
|
||||
return errno;
|
||||
if (-1 == link(src, dst)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *taosOpenCFile(const char *filename, const char *mode) { return fopen(filename, mode); }
|
||||
FILE *taosOpenCFile(const char *filename, const char *mode) {
|
||||
FILE* f = fopen(filename, mode);
|
||||
if (NULL == f) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
int taosSeekCFile(FILE *file, int64_t offset, int whence) {
|
||||
#ifdef WINDOWS
|
||||
return _fseeki64(file, offset, whence);
|
||||
#else
|
||||
return fseeko(file, offset, whence);
|
||||
int code = fseeko(file, offset, whence);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return terrno;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1509,6 +1615,10 @@ int taosSetAutoDelFile(char *path) {
|
|||
#ifdef WINDOWS
|
||||
return SetFileAttributes(path, FILE_ATTRIBUTE_TEMPORARY);
|
||||
#else
|
||||
return unlink(path);
|
||||
if (-1 == unlink(path)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -75,18 +75,18 @@ char *taosCharsetReplace(char *charsetstr) {
|
|||
*
|
||||
* In case that the setLocale failed to be executed, the right charset needs to be set.
|
||||
*/
|
||||
void taosSetSystemLocale(const char *inLocale, const char *inCharSet) {
|
||||
char *locale = setlocale(LC_CTYPE, inLocale);
|
||||
|
||||
// default locale or user specified locale is not valid, abort launch
|
||||
if (inLocale == NULL || strlen(inLocale) == 0) {
|
||||
// printf("Invalid locale:%s, please set the valid locale in config file\n", inLocale);
|
||||
}
|
||||
|
||||
int32_t taosSetSystemLocale(const char *inLocale, const char *inCharSet) {\
|
||||
if (!taosValidateEncodec(inCharSet)) {
|
||||
printf("Invalid charset:%s, please set the valid charset in config file\n", inCharSet);
|
||||
exit(-1);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
char *locale = setlocale(LC_CTYPE, inLocale);
|
||||
if (NULL == locale) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
||||
|
@ -168,7 +168,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
|||
locale = setlocale(LC_CTYPE, "");
|
||||
if (locale == NULL) {
|
||||
// printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno));
|
||||
strcpy(outLocale, "en_US.UTF-8");
|
||||
(void)strcpy(outLocale, "en_US.UTF-8");
|
||||
} else {
|
||||
tstrncpy(outLocale, locale, TD_LOCALE_LEN);
|
||||
//printf("locale not configured, set to system default:%s\n", outLocale);
|
||||
|
@ -180,12 +180,16 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
|||
str++;
|
||||
|
||||
char *revisedCharset = taosCharsetReplace(str);
|
||||
tstrncpy(outCharset, revisedCharset, TD_LOCALE_LEN);
|
||||
if (NULL == revisedCharset) {
|
||||
(void)strcpy(outCharset, "UTF-8");
|
||||
} else {
|
||||
tstrncpy(outCharset, revisedCharset, TD_LOCALE_LEN);
|
||||
|
||||
taosMemoryFree(revisedCharset);
|
||||
taosMemoryFree(revisedCharset);
|
||||
}
|
||||
// printf("charset not configured, set to system default:%s", outCharset);
|
||||
} else {
|
||||
strcpy(outCharset, "UTF-8");
|
||||
(void)strcpy(outCharset, "UTF-8");
|
||||
// printf("can't get locale and charset from system, set it to UTF-8");
|
||||
}
|
||||
|
||||
|
|
|
@ -342,12 +342,7 @@ char *taosStrdup(const char *ptr) {
|
|||
|
||||
return (char *)tmp + sizeof(TdMemoryInfo);
|
||||
#else
|
||||
char *p = tstrdup(ptr);
|
||||
if (ptr != NULL && NULL == p) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return p;
|
||||
|
||||
return tstrdup(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -194,18 +194,19 @@ int32_t taosGetAppName(char* name, int32_t* len) {
|
|||
const char* self = "/proc/self/exe";
|
||||
char path[PATH_MAX] = {0};
|
||||
|
||||
if (readlink(self, path, PATH_MAX) <= 0) {
|
||||
return -1;
|
||||
if (-1 == readlink(self, path, PATH_MAX)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
path[PATH_MAX - 1] = 0;
|
||||
char* end = strrchr(path, '/');
|
||||
if (end == NULL) {
|
||||
return -1;
|
||||
end = path;
|
||||
} else {
|
||||
++end;
|
||||
}
|
||||
|
||||
++end;
|
||||
|
||||
|
||||
tstrncpy(name, end, TSDB_APP_NAME_LEN);
|
||||
|
||||
if (len != NULL) {
|
||||
|
@ -221,14 +222,22 @@ int32_t tsem_timewait(tsem_t* sem, int64_t ms) {
|
|||
struct timespec ts = {0};
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
|
||||
return -1;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
ts.tv_nsec += ms * 1000000;
|
||||
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 && errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (-1 == ret) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -237,78 +246,113 @@ int32_t tsem_wait(tsem_t* sem) {
|
|||
int ret = 0;
|
||||
do {
|
||||
ret = sem_wait(sem);
|
||||
} while (ret != 0 && errno == EINTR);
|
||||
} while (-1 == ret && errno == EINTR);
|
||||
|
||||
if (-1 == ret) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) {
|
||||
int ret = taosThreadMutexInit(&sem->mutex, NULL);
|
||||
if (ret != 0) return ret;
|
||||
|
||||
ret = taosThreadCondAttrInit(&sem->attr);
|
||||
if (ret != 0)
|
||||
{
|
||||
taosThreadMutexDestroy(&sem->mutex);
|
||||
if (ret != 0) {
|
||||
(void)taosThreadMutexDestroy(&sem->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = taosThreadCondAttrSetclock(&sem->attr, CLOCK_MONOTONIC);
|
||||
if (ret != 0)
|
||||
{
|
||||
taosThreadMutexDestroy(&sem->mutex);
|
||||
taosThreadCondAttrDestroy(&sem->attr);
|
||||
if (ret != 0) {
|
||||
(void)taosThreadMutexDestroy(&sem->mutex);
|
||||
(void)taosThreadCondAttrDestroy(&sem->attr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = taosThreadCondInit(&sem->cond, &sem->attr);
|
||||
if (ret != 0)
|
||||
{
|
||||
taosThreadMutexDestroy(&sem->mutex);
|
||||
taosThreadCondAttrDestroy(&sem->attr);
|
||||
if (ret != 0) {
|
||||
(void)taosThreadMutexDestroy(&sem->mutex);
|
||||
(void)taosThreadCondAttrDestroy(&sem->attr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
sem->count = value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tsem2_post(tsem2_t *sem) {
|
||||
taosThreadMutexLock(&sem->mutex);
|
||||
int32_t code = taosThreadMutexLock(&sem->mutex);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
sem->count++;
|
||||
taosThreadCondSignal(&sem->cond);
|
||||
taosThreadMutexUnlock(&sem->mutex);
|
||||
code = taosThreadCondSignal(&sem->cond);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = taosThreadMutexUnlock(&sem->mutex);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tsem2_destroy(tsem2_t* sem) {
|
||||
taosThreadMutexDestroy(&sem->mutex);
|
||||
taosThreadCondDestroy(&sem->cond);
|
||||
taosThreadCondAttrDestroy(&sem->attr);
|
||||
(void)taosThreadMutexDestroy(&sem->mutex);
|
||||
(void)taosThreadCondDestroy(&sem->cond);
|
||||
(void)taosThreadCondAttrDestroy(&sem->attr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsem2_wait(tsem2_t* sem) {
|
||||
taosThreadMutexLock(&sem->mutex);
|
||||
int32_t code = taosThreadMutexLock(&sem->mutex);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
while (sem->count <= 0) {
|
||||
int ret = taosThreadCondWait(&sem->cond, &sem->mutex);
|
||||
if (0 == ret) {
|
||||
continue;
|
||||
} else {
|
||||
taosThreadMutexUnlock(&sem->mutex);
|
||||
(void)taosThreadMutexUnlock(&sem->mutex);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
sem->count--;
|
||||
taosThreadMutexUnlock(&sem->mutex);
|
||||
|
||||
code = taosThreadMutexUnlock(&sem->mutex);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsem2_timewait(tsem2_t* sem, int64_t ms) {
|
||||
int ret = 0;
|
||||
|
||||
taosThreadMutexLock(&sem->mutex);
|
||||
ret = taosThreadMutexLock(&sem->mutex);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (sem->count <= 0) {
|
||||
struct timespec ts = {0};
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
|
||||
taosThreadMutexUnlock(&sem->mutex);
|
||||
return -1;
|
||||
ret = TAOS_SYSTEM_ERROR(errno);
|
||||
(void)taosThreadMutexUnlock(&sem->mutex);
|
||||
terrno = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ts.tv_sec += ms / 1000;
|
||||
|
@ -319,14 +363,15 @@ int32_t tsem2_timewait(tsem2_t* sem, int64_t ms) {
|
|||
while (sem->count <= 0) {
|
||||
ret = taosThreadCondTimedWait(&sem->cond, &sem->mutex, &ts);
|
||||
if (ret != 0) {
|
||||
taosThreadMutexUnlock(&sem->mutex);
|
||||
(void)taosThreadMutexUnlock(&sem->mutex);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sem->count--;
|
||||
taosThreadMutexUnlock(&sem->mutex);
|
||||
|
||||
ret = taosThreadMutexUnlock(&sem->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
typedef void (*FWinSignalHandler)(int32_t signum);
|
||||
|
||||
void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
|
||||
if (signum == SIGUSR1) return;
|
||||
int32_t taosSetSignal(int32_t signum, FSignalHandler sigfp) {
|
||||
if (signum == SIGUSR1) return 0;
|
||||
|
||||
// SIGHUP doesn't exist in windows, we handle it in the way of ctrlhandler
|
||||
if (signum == SIGHUP) {
|
||||
|
@ -35,19 +35,26 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
|
|||
} else {
|
||||
signal(signum, (FWinSignalHandler)sigfp);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosIgnSignal(int32_t signum) {
|
||||
if (signum == SIGUSR1 || signum == SIGHUP) return;
|
||||
int32_t taosIgnSignal(int32_t signum) {
|
||||
if (signum == SIGUSR1 || signum == SIGHUP) return 0;
|
||||
signal(signum, SIG_IGN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosDflSignal(int32_t signum) {
|
||||
if (signum == SIGUSR1 || signum == SIGHUP) return;
|
||||
int32_t taosDflSignal(int32_t signum) {
|
||||
if (signum == SIGUSR1 || signum == SIGHUP) return 0;
|
||||
signal(signum, SIG_DFL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosKillChildOnParentStopped() {}
|
||||
int32_t taosKillChildOnParentStopped() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
@ -57,26 +64,55 @@ void taosKillChildOnParentStopped() {}
|
|||
|
||||
typedef void (*FLinuxSignalHandler)(int32_t signum, siginfo_t *sigInfo, void *context);
|
||||
|
||||
void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
|
||||
int32_t taosSetSignal(int32_t signum, FSignalHandler sigfp) {
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
(void)memset(&act, 0, sizeof(act));
|
||||
#if 1
|
||||
act.sa_flags = SA_SIGINFO | SA_RESTART;
|
||||
act.sa_sigaction = (FLinuxSignalHandler)sigfp;
|
||||
#else
|
||||
act.sa_handler = sigfp;
|
||||
#endif
|
||||
sigaction(signum, &act, NULL);
|
||||
int32_t code = sigaction(signum, &act, NULL);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); }
|
||||
int32_t taosIgnSignal(int32_t signum) {
|
||||
sighandler_t h = signal(signum, SIG_IGN);
|
||||
if (SIG_ERR == h) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
void taosDflSignal(int32_t signum) { signal(signum, SIG_DFL); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosKillChildOnParentStopped() {
|
||||
int32_t taosDflSignal(int32_t signum) {
|
||||
sighandler_t h = signal(signum, SIG_DFL);
|
||||
if (SIG_ERR == h) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosKillChildOnParentStopped() {
|
||||
#ifndef _TD_DARWIN_64
|
||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
int32_t code = prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return code;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -122,18 +122,25 @@ int32_t taosCloseSocketNoCheck1(SocketFd fd) {
|
|||
#ifdef WINDOWS
|
||||
return closesocket(fd);
|
||||
#else
|
||||
return close(fd);
|
||||
int32_t code = close(fd);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t taosCloseSocket(TdSocketPtr *ppSocket) {
|
||||
int32_t code;
|
||||
if (ppSocket == NULL || *ppSocket == NULL || (*ppSocket)->fd < 0) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
code = taosCloseSocketNoCheck1((*ppSocket)->fd);
|
||||
(*ppSocket)->fd = -1;
|
||||
taosMemoryFree(*ppSocket);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -259,8 +266,10 @@ int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) {
|
|||
|
||||
int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t optlen) {
|
||||
if (pSocket == NULL || pSocket->fd < 0) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
#ifdef TCP_KEEPCNT
|
||||
if (level == SOL_SOCKET && optname == TCP_KEEPCNT) {
|
||||
|
@ -288,7 +297,12 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void
|
|||
|
||||
return setsockopt(pSocket->fd, level, optname, optval, optlen);
|
||||
#else
|
||||
return setsockopt(pSocket->fd, level, optname, optval, (int)optlen);
|
||||
int32_t code = setsockopt(pSocket->fd, level, optname, optval, (int)optlen);
|
||||
if (-1 == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -321,7 +335,12 @@ uint32_t taosInetAddr(const char *ipAddr) {
|
|||
#endif
|
||||
}
|
||||
const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len) {
|
||||
return inet_ntop(AF_INET, &ipInt, dstStr, len);
|
||||
const char* r = inet_ntop(AF_INET, &ipInt, dstStr, len);
|
||||
if (NULL == r) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifndef SIGPIPE
|
||||
|
@ -733,6 +752,7 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
|
|||
struct sockaddr_in serverAdd;
|
||||
SocketFd fd;
|
||||
int32_t reuse;
|
||||
int32_t code = 0;
|
||||
|
||||
// printf("open tcp server socket:0x%x:%hu", ip, port);
|
||||
|
||||
|
@ -746,16 +766,17 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
|
|||
serverAdd.sin_port = (uint16_t)htons(port);
|
||||
|
||||
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (fd < 0) { // exception
|
||||
return false;
|
||||
} else if (fd <= 2) { // in, out, err
|
||||
taosCloseSocketNoCheck1(fd);
|
||||
if (-1 == fd) { // exception
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket));
|
||||
if (pSocket == NULL) {
|
||||
taosCloseSocketNoCheck1(fd);
|
||||
code = terrno;
|
||||
(void)taosCloseSocketNoCheck1(fd);
|
||||
terrno = code;
|
||||
|
||||
return false;
|
||||
}
|
||||
pSocket->refId = 0;
|
||||
|
@ -764,19 +785,24 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
|
|||
/* set REUSEADDR option, so the portnumber can be re-used */
|
||||
reuse = 1;
|
||||
if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) {
|
||||
// printf("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno));
|
||||
taosCloseSocket(&pSocket);
|
||||
code = terrno;
|
||||
(void)taosCloseSocket(&pSocket);
|
||||
terrno = code;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* bind socket to server address */
|
||||
if (bind(pSocket->fd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)) < 0) {
|
||||
// printf("bind tcp server socket failed, 0x%x:%hu(%s)", ip, port, strerror(errno));
|
||||
taosCloseSocket(&pSocket);
|
||||
if (-1 == bind(pSocket->fd, (struct sockaddr *)&serverAdd, sizeof(serverAdd))) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
(void)taosCloseSocket(&pSocket);
|
||||
terrno = code;
|
||||
return false;
|
||||
}
|
||||
taosCloseSocket(&pSocket);
|
||||
|
||||
(void)taosCloseSocket(&pSocket);
|
||||
|
||||
return true;
|
||||
// return 0 == taosValidIp(ip) ? true : false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -898,21 +924,24 @@ int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len
|
|||
|
||||
#endif // endif 0
|
||||
|
||||
void taosBlockSIGPIPE() {
|
||||
int32_t taosBlockSIGPIPE() {
|
||||
#ifdef WINDOWS
|
||||
// ASSERT(0);
|
||||
return 0;
|
||||
#else
|
||||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
sigaddset(&signal_mask, SIGPIPE);
|
||||
(void)sigemptyset(&signal_mask);
|
||||
(void)sigaddset(&signal_mask, SIGPIPE);
|
||||
int32_t rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
|
||||
if (rc != 0) {
|
||||
// printf("failed to block SIGPIPE");
|
||||
terrno = TAOS_SYSTEM_ERROR(rc);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t taosGetIpv4FromFqdn(const char *fqdn) {
|
||||
int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) {
|
||||
#ifdef WINDOWS
|
||||
// Initialize Winsock
|
||||
WSADATA wsaData;
|
||||
|
@ -923,6 +952,41 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) {
|
|||
return 0xFFFFFFFF;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LINUX)
|
||||
struct addrinfo hints = {0};
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
struct addrinfo *result = NULL;
|
||||
bool inRetry = false;
|
||||
|
||||
while (true) {
|
||||
int32_t ret = getaddrinfo(fqdn, NULL, &hints, &result);
|
||||
if (ret) {
|
||||
if (EAI_AGAIN == ret && !inRetry) {
|
||||
inRetry = true;
|
||||
continue;
|
||||
} else if (EAI_SYSTEM == ret) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
terrno = TAOS_SYSTEM_ERROR(ret);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
struct sockaddr *sa = result->ai_addr;
|
||||
struct sockaddr_in *si = (struct sockaddr_in *)sa;
|
||||
struct in_addr ia = si->sin_addr;
|
||||
|
||||
*ip = ia.s_addr;
|
||||
|
||||
freeaddrinfo(result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
struct addrinfo hints = {0};
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
@ -934,9 +998,9 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) {
|
|||
struct sockaddr *sa = result->ai_addr;
|
||||
struct sockaddr_in *si = (struct sockaddr_in *)sa;
|
||||
struct in_addr ia = si->sin_addr;
|
||||
uint32_t ip = ia.s_addr;
|
||||
*ip = ia.s_addr;
|
||||
freeaddrinfo(result);
|
||||
return ip;
|
||||
return 0;
|
||||
} else {
|
||||
#ifdef EAI_SYSTEM
|
||||
if (ret == EAI_SYSTEM) {
|
||||
|
@ -947,8 +1011,11 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) {
|
|||
#else
|
||||
// printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret));
|
||||
#endif
|
||||
|
||||
*ip = 0xFFFFFFFF;
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t taosGetFqdn(char *fqdn) {
|
||||
|
@ -964,14 +1031,9 @@ int32_t taosGetFqdn(char *fqdn) {
|
|||
#endif
|
||||
char hostname[1024];
|
||||
hostname[1023] = '\0';
|
||||
if (taosGetlocalhostname(hostname, 1023) == -1) {
|
||||
#ifdef WINDOWS
|
||||
printf("failed to get hostname, reason:%s\n", strerror(WSAGetLastError()));
|
||||
#else
|
||||
printf("failed to get hostname, reason:%s\n", strerror(errno));
|
||||
#endif
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
int32_t code = taosGetlocalhostname(hostname, 1023);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
@ -983,6 +1045,37 @@ int32_t taosGetFqdn(char *fqdn) {
|
|||
strcpy(fqdn, hostname);
|
||||
strcpy(fqdn + strlen(hostname), ".local");
|
||||
#else // linux
|
||||
|
||||
#endif // linux
|
||||
|
||||
#if defined(LINUX)
|
||||
|
||||
struct addrinfo hints = {0};
|
||||
struct addrinfo *result = NULL;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
|
||||
while (true) {
|
||||
int32_t ret = getaddrinfo(hostname, NULL, &hints, &result);
|
||||
if (ret) {
|
||||
if (EAI_AGAIN == ret) {
|
||||
continue;
|
||||
} else if (EAI_SYSTEM == ret) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
terrno = TAOS_SYSTEM_ERROR(ret);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
(void)strcpy(fqdn, result->ai_canonname);
|
||||
|
||||
freeaddrinfo(result);
|
||||
|
||||
#else
|
||||
struct addrinfo hints = {0};
|
||||
struct addrinfo *result = NULL;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
|
@ -994,24 +1087,36 @@ int32_t taosGetFqdn(char *fqdn) {
|
|||
}
|
||||
strcpy(fqdn, result->ai_canonname);
|
||||
freeaddrinfo(result);
|
||||
#endif // linux
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tinet_ntoa(char *ipstr, uint32_t ip) {
|
||||
sprintf(ipstr, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24);
|
||||
(void)sprintf(ipstr, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24);
|
||||
}
|
||||
|
||||
void taosIgnSIGPIPE() { signal(SIGPIPE, SIG_IGN); }
|
||||
int32_t taosIgnSIGPIPE() {
|
||||
sighandler_t h = signal(SIGPIPE, SIG_IGN);
|
||||
if (SIG_ERR == h) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
void taosSetMaskSIGPIPE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
int32_t taosSetMaskSIGPIPE() {
|
||||
#ifdef WINDOWS
|
||||
// ASSERT(0);
|
||||
#else
|
||||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
sigaddset(&signal_mask, SIGPIPE);
|
||||
(void)sigemptyset(&signal_mask);
|
||||
(void)sigaddset(&signal_mask, SIGPIPE);
|
||||
|
||||
int32_t rc = pthread_sigmask(SIG_SETMASK, &signal_mask, NULL);
|
||||
if (rc != 0) {
|
||||
// printf("failed to setmask SIGPIPE");
|
||||
|
@ -1019,7 +1124,6 @@ void taosSetMaskSIGPIPE() {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen) {
|
||||
if (pSocket == NULL || pSocket->fd < 0) {
|
||||
return -1;
|
||||
|
@ -1038,9 +1142,12 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) {
|
|||
#else
|
||||
int fd;
|
||||
#endif
|
||||
|
||||
if ((fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(WINDOWS)
|
||||
if (0 != setsockopt(fd, IPPROTO_TCP, TCP_MAXRT, (char *)&timeout, sizeof(timeout))) {
|
||||
taosCloseSocketNoCheck1(fd);
|
||||
|
@ -1055,8 +1162,10 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) {
|
|||
//}
|
||||
#else // Linux like systems
|
||||
uint32_t conn_timeout_ms = timeout;
|
||||
if (0 != setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *)&conn_timeout_ms, sizeof(conn_timeout_ms))) {
|
||||
taosCloseSocketNoCheck1(fd);
|
||||
if (-1 == setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *)&conn_timeout_ms, sizeof(conn_timeout_ms))) {
|
||||
int32_t code = TAOS_SYSTEM_ERROR(errno);
|
||||
(void)taosCloseSocketNoCheck1(fd);
|
||||
terrno = code;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -28,7 +28,12 @@ char *tstrdup(const char *str) {
|
|||
#ifdef WINDOWS
|
||||
return _strdup(str);
|
||||
#else
|
||||
return strdup(str);
|
||||
char* p = strdup(str);
|
||||
if (str != NULL && NULL == p) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return p;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -119,9 +124,15 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) {
|
|||
//#endif
|
||||
}
|
||||
|
||||
TdUcs4 *tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) {
|
||||
ASSERT(taosMemorySize(target_ucs4) >= len_ucs4 * sizeof(TdUcs4));
|
||||
return memcpy(target_ucs4, source_ucs4, len_ucs4 * sizeof(TdUcs4));
|
||||
int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) {
|
||||
if (taosMemorySize(target_ucs4) < len_ucs4 * sizeof(TdUcs4)) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
(void)memcpy(target_ucs4, source_ucs4, len_ucs4 * sizeof(TdUcs4));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@ -141,23 +152,28 @@ int32_t taosConvInit(void) {
|
|||
gConvMaxNum[1 - M2C] = 512;
|
||||
|
||||
gConv[M2C] = taosMemoryCalloc(gConvMaxNum[M2C], sizeof(SConv));
|
||||
if (gConv[M2C] == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
gConv[1 - M2C] = taosMemoryCalloc(gConvMaxNum[1 - M2C], sizeof(SConv));
|
||||
if (gConv[M2C] == NULL || gConv[1 - M2C] == NULL) {
|
||||
if (gConv[1 - M2C] == NULL) {
|
||||
taosMemoryFree(gConv[M2C]);
|
||||
taosMemoryFree(gConv[1 - M2C]);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < gConvMaxNum[M2C]; ++i) {
|
||||
gConv[M2C][i].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
if ((iconv_t)-1 == gConv[M2C][i].conv || (iconv_t)0 == gConv[M2C][i].conv) {
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < gConvMaxNum[1 - M2C]; ++i) {
|
||||
gConv[1 - M2C][i].conv = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
if ((iconv_t)-1 == gConv[1 - M2C][i].conv || (iconv_t)0 == gConv[1 - M2C][i].conv) {
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,10 +183,10 @@ int32_t taosConvInit(void) {
|
|||
void taosConvDestroy() {
|
||||
int8_t M2C = 0;
|
||||
for (int32_t i = 0; i < gConvMaxNum[M2C]; ++i) {
|
||||
iconv_close(gConv[M2C][i].conv);
|
||||
(void)iconv_close(gConv[M2C][i].conv);
|
||||
}
|
||||
for (int32_t i = 0; i < gConvMaxNum[1 - M2C]; ++i) {
|
||||
iconv_close(gConv[1 - M2C][i].conv);
|
||||
(void)iconv_close(gConv[1 - M2C][i].conv);
|
||||
}
|
||||
taosMemoryFreeClear(gConv[M2C]);
|
||||
taosMemoryFreeClear(gConv[1 - M2C]);
|
||||
|
@ -182,9 +198,17 @@ iconv_t taosAcquireConv(int32_t *idx, ConvType type) {
|
|||
if (gConvMaxNum[type] <= 0) {
|
||||
*idx = -1;
|
||||
if (type == M2C) {
|
||||
return iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
iconv_t c = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
if ((iconv_t)-1 == c || (iconv_t)0 == c) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return c;
|
||||
} else {
|
||||
return iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
iconv_t c = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
if ((iconv_t)-1 == c || (iconv_t)0 == c) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +216,7 @@ iconv_t taosAcquireConv(int32_t *idx, ConvType type) {
|
|||
int32_t used = atomic_add_fetch_32(&convUsed[type], 1);
|
||||
if (used > gConvMaxNum[type]) {
|
||||
used = atomic_sub_fetch_32(&convUsed[type], 1);
|
||||
sched_yield();
|
||||
(void)sched_yield();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -218,12 +242,12 @@ iconv_t taosAcquireConv(int32_t *idx, ConvType type) {
|
|||
|
||||
void taosReleaseConv(int32_t idx, iconv_t conv, ConvType type) {
|
||||
if (idx < 0) {
|
||||
iconv_close(conv);
|
||||
(void)iconv_close(conv);
|
||||
return;
|
||||
}
|
||||
|
||||
atomic_store_8(&gConv[type][idx].inUse, 0);
|
||||
atomic_sub_fetch_32(&convUsed[type], 1);
|
||||
(void)atomic_sub_fetch_32(&convUsed[type], 1);
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||
|
@ -231,14 +255,21 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4
|
|||
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n");
|
||||
return -1;
|
||||
#else
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
(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;
|
||||
}
|
||||
|
||||
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);
|
||||
taosReleaseConv(idx, conv, M2C);
|
||||
terrno = code;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -261,14 +292,23 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) {
|
|||
#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;
|
||||
}
|
||||
|
||||
size_t ucs4_input_len = ucs4_max_len;
|
||||
size_t outLen = ucs4_max_len;
|
||||
if (iconv(conv, (char **)&ucs4, &ucs4_input_len, &mbs, &outLen) == -1) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
taosReleaseConv(idx, conv, C2M);
|
||||
return -1;
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
taosReleaseConv(idx, conv, C2M);
|
||||
|
||||
return (int32_t)(ucs4_max_len - outLen);
|
||||
#endif
|
||||
}
|
||||
|
@ -282,8 +322,10 @@ int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t c
|
|||
size_t ucs4_input_len = ucs4_max_len;
|
||||
size_t outLen = ucs4_max_len;
|
||||
if (iconv(conv, (char **)&ucs4, &ucs4_input_len, &mbs, &outLen) == -1) {
|
||||
return -1;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return (int32_t)(ucs4_max_len - outLen);
|
||||
#endif
|
||||
}
|
||||
|
@ -295,10 +337,11 @@ bool taosValidateEncodec(const char *encodec) {
|
|||
#else
|
||||
iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC);
|
||||
if (cd == (iconv_t)(-1)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
(void)iconv_close(cd);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
@ -323,11 +366,12 @@ int32_t taosUcs4len(TdUcs4 *ucs4) {
|
|||
// dst buffer size should be at least 2*len + 1
|
||||
int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len) {
|
||||
if (!dst) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < len; ++i) {
|
||||
sprintf(dst + i * 2, "%02x", src[i]);
|
||||
(void)sprintf(dst + i * 2, "%02x", src[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -335,7 +379,8 @@ int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len) {
|
|||
|
||||
int32_t taosHexDecode(const char *src, char *dst, int32_t len) {
|
||||
if (!dst) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
uint8_t hn, ln, out;
|
||||
|
@ -344,7 +389,7 @@ int32_t taosHexDecode(const char *src, char *dst, int32_t len) {
|
|||
ln = src[i + 1] > '9' ? src[i + 1] - 'a' + 10 : src[i + 1] - '0';
|
||||
|
||||
out = (hn << 4) | ln;
|
||||
memcpy(dst + j, &out, 1);
|
||||
(void)memcpy(dst + j, &out, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -518,11 +563,17 @@ int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size) {
|
|||
z += HEX_PREFIX_LEN;
|
||||
*size = n / HEX_PREFIX_LEN;
|
||||
if (*size == 0) {
|
||||
if (!(*data = taosStrdup(""))) return -1;
|
||||
if (!(*data = taosStrdup(""))) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t *tmp = (uint8_t *)taosMemoryCalloc(*size, 1);
|
||||
if (tmp == NULL) return -1;
|
||||
if (tmp == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int8_t num = 0;
|
||||
uint8_t *byte = tmp + *size - 1;
|
||||
|
||||
|
@ -542,6 +593,7 @@ int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size) {
|
|||
}
|
||||
}
|
||||
*data = tmp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -614,7 +666,10 @@ static char valueOf(uint8_t symbol) {
|
|||
int32_t taosAscii2Hex(const char *z, uint32_t n, void **data, uint32_t *size) {
|
||||
*size = n * 2 + HEX_PREFIX_LEN;
|
||||
uint8_t *tmp = (uint8_t *)taosMemoryCalloc(*size + 1, 1);
|
||||
if (tmp == NULL) return -1;
|
||||
if (tmp == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
*data = tmp;
|
||||
*(tmp++) = '\\';
|
||||
*(tmp++) = 'x';
|
||||
|
@ -623,5 +678,6 @@ int32_t taosAscii2Hex(const char *z, uint32_t n, void **data, uint32_t *size) {
|
|||
tmp[i * 2] = valueOf(val >> 4);
|
||||
tmp[i * 2 + 1] = valueOf(val & 0x0F);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -139,13 +139,14 @@ static void taosGetProcIOnfos() {
|
|||
tsStreamMax = TMAX(sysconf(_SC_STREAM_MAX), 0);
|
||||
tsProcId = (pid_t)syscall(SYS_gettid);
|
||||
|
||||
snprintf(tsProcMemFile, sizeof(tsProcMemFile), "/proc/%d/status", tsProcId);
|
||||
snprintf(tsProcCpuFile, sizeof(tsProcCpuFile), "/proc/%d/stat", tsProcId);
|
||||
snprintf(tsProcIOFile, sizeof(tsProcIOFile), "/proc/%d/io", tsProcId);
|
||||
(void)snprintf(tsProcMemFile, sizeof(tsProcMemFile), "/proc/%d/status", tsProcId);
|
||||
(void)snprintf(tsProcCpuFile, sizeof(tsProcCpuFile), "/proc/%d/stat", tsProcId);
|
||||
(void)snprintf(tsProcIOFile, sizeof(tsProcIOFile), "/proc/%d/io", tsProcId);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
|
||||
int32_t code = 0;
|
||||
#ifdef WINDOWS
|
||||
FILETIME pre_idleTime = {0};
|
||||
FILETIME pre_kernelTime = {0};
|
||||
|
@ -168,29 +169,38 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
|
|||
#else
|
||||
TdFilePtr pFile = taosOpenFile(tsSysCpuFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
char line[1024];
|
||||
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||
if (bytes < 0) {
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
code = terrno;
|
||||
(void)taosCloseFile(&pFile);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
char cpu[10] = {0};
|
||||
sscanf(line,
|
||||
code = sscanf(line,
|
||||
"%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
|
||||
" %" PRIu64,
|
||||
cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle, &cpuInfo->wa, &cpuInfo->hi,
|
||||
&cpuInfo->si, &cpuInfo->st, &cpuInfo->guest, &cpuInfo->guest_nice);
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (EOF == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
(void)taosCloseFile(&pFile);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
||||
int32_t code = 0;
|
||||
|
||||
#ifdef WINDOWS
|
||||
FILETIME pre_krnlTm = {0};
|
||||
FILETIME pre_usrTm = {0};
|
||||
|
@ -210,27 +220,35 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
|||
#else
|
||||
TdFilePtr pFile = taosOpenFile(tsProcCpuFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
char line[1024] = {0};
|
||||
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||
if (bytes < 0) {
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
code = terrno;
|
||||
(void)taosCloseFile(&pFile);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
for (int i = 0, blank = 0; line[i] != 0; ++i) {
|
||||
if (line[i] == ' ') blank++;
|
||||
if (blank == PROCESS_ITEM) {
|
||||
sscanf(line + i + 1, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &cpuInfo->utime, &cpuInfo->stime,
|
||||
code = sscanf(line + i + 1, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &cpuInfo->utime, &cpuInfo->stime,
|
||||
&cpuInfo->cutime, &cpuInfo->cstime);
|
||||
if (EOF == code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -256,10 +274,10 @@ void taosGetSystemInfo() {
|
|||
tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
#else
|
||||
taosGetProcIOnfos();
|
||||
taosGetCpuCores(&tsNumOfCores, false);
|
||||
taosGetTotalMemory(&tsTotalMemoryKB);
|
||||
taosGetCpuUsage(NULL, NULL);
|
||||
taosGetCpuInstructions(&tsSSE42Supported, &tsAVXSupported, &tsAVX2Supported, &tsFMASupported, &tsAVX512Supported);
|
||||
(void)taosGetCpuCores(&tsNumOfCores, false);
|
||||
(void)taosGetTotalMemory(&tsTotalMemoryKB);
|
||||
(void)taosGetCpuUsage(NULL, NULL);
|
||||
(void)taosGetCpuInstructions(&tsSSE42Supported, &tsAVXSupported, &tsAVX2Supported, &tsFMASupported, &tsAVX512Supported);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -291,14 +309,16 @@ int32_t taosGetEmail(char *email, int32_t maxLen) {
|
|||
#endif // CUS_PROMPT
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
||||
if (pFile == NULL) return false;
|
||||
if (pFile == NULL) return terrno;
|
||||
|
||||
if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
int32_t code = terrno;
|
||||
(void)taosCloseFile(&pFile);
|
||||
return code;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
@ -372,13 +392,15 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t
|
|||
char line[1024];
|
||||
char *dest = NULL;
|
||||
size_t size = 0;
|
||||
int32_t code = -1;
|
||||
int32_t code = 0;
|
||||
int32_t cnt = 0;
|
||||
|
||||
TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) return code;
|
||||
if (pFile == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
while ((size = taosGetsFile(pFile, sizeof(line), line)) != -1) {
|
||||
while ((size = taosGetsFile(pFile, sizeof(line), line)) > 0) {
|
||||
line[size - 1] = '\0';
|
||||
if (strncmp(line, "NAME", 4) == 0) {
|
||||
dest = sName;
|
||||
|
@ -401,7 +423,7 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t
|
|||
if (++cnt >= 3) break;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
@ -450,13 +472,13 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
|||
char line[1024] = {0};
|
||||
size_t size = 0;
|
||||
int32_t done = 0;
|
||||
int32_t code = -1;
|
||||
int32_t code = 0;
|
||||
float coreCount = 0;
|
||||
|
||||
TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) return code;
|
||||
if (pFile == NULL) return terrno;
|
||||
|
||||
while (done != 3 && (size = taosGetsFile(pFile, sizeof(line), line)) != -1) {
|
||||
while (done != 3 && (size = taosGetsFile(pFile, sizeof(line), line)) > 0) {
|
||||
line[size - 1] = '\0';
|
||||
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
|
||||
const char *v = strchr(line, ':') + 2;
|
||||
|
@ -471,13 +493,13 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
|||
if (strncmp(line, "processor", 9) == 0) coreCount += 1;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)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);
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
if (bytes > 0) {
|
||||
code = 0;
|
||||
done |= 1;
|
||||
|
@ -487,7 +509,9 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
|||
|
||||
if (code != 0 && (done & 1) == 0) {
|
||||
TdCmdPtr pCmd = taosOpenCmd("uname -a");
|
||||
if (pCmd == NULL) return code;
|
||||
if (pCmd == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
if (taosGetsCmd(pCmd, maxLen, cpuModel) > 0) {
|
||||
code = 0;
|
||||
done |= 1;
|
||||
|
@ -516,11 +540,12 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
|||
goto _sys;
|
||||
}
|
||||
char qline[32] = {0};
|
||||
if (taosGetsFile(pFile, sizeof(qline), qline) < 0) {
|
||||
taosCloseFile(&pFile);
|
||||
if (taosGetsFile(pFile, sizeof(qline), qline) <= 0) {
|
||||
(void)taosCloseFile(&pFile);
|
||||
goto _sys;
|
||||
}
|
||||
taosCloseFile(&pFile);
|
||||
|
||||
(void)taosCloseFile(&pFile);
|
||||
float quota = taosStr2Float(qline, NULL);
|
||||
if (quota < 0) {
|
||||
goto _sys;
|
||||
|
@ -529,12 +554,14 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
|||
if (!(pFile = taosOpenFile(tsCpuPeriodFile, TD_FILE_READ | TD_FILE_STREAM))) {
|
||||
goto _sys;
|
||||
}
|
||||
|
||||
char pline[32] = {0};
|
||||
if (taosGetsFile(pFile, sizeof(pline), pline) < 0) {
|
||||
taosCloseFile(&pFile);
|
||||
if (taosGetsFile(pFile, sizeof(pline), pline) <= 0) {
|
||||
(void)taosCloseFile(&pFile);
|
||||
goto _sys;
|
||||
}
|
||||
taosCloseFile(&pFile);
|
||||
|
||||
(void)taosCloseFile(&pFile);
|
||||
|
||||
float period = taosStr2Float(pline, NULL);
|
||||
float quotaCores = quota / period;
|
||||
|
@ -545,10 +572,13 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
|||
*numOfCores = sysCores;
|
||||
}
|
||||
goto _end;
|
||||
|
||||
_sys:
|
||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
_end:
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -565,7 +595,7 @@ int32_t taosGetCpuCores(float *numOfCores, bool physical) {
|
|||
if (physical) {
|
||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
} else {
|
||||
taosCntrGetCpuCores(numOfCores);
|
||||
(void)taosCntrGetCpuCores(numOfCores);
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -684,14 +714,14 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
|
|||
TdFilePtr pFile = taosOpenFile(tsProcMemFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) {
|
||||
// printf("open file:%s failed", tsProcMemFile);
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
ssize_t bytes = 0;
|
||||
char line[1024] = {0};
|
||||
while (!taosEOFFile(pFile)) {
|
||||
bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||
if (bytes < 0) {
|
||||
if (bytes <= 0) {
|
||||
break;
|
||||
}
|
||||
if (strstr(line, "VmRSS:") != NULL) {
|
||||
|
@ -700,9 +730,10 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
|
|||
}
|
||||
|
||||
char tmp[10];
|
||||
sscanf(line, "%s %" PRId64, tmp, usedKB);
|
||||
(void)sscanf(line, "%s %" PRId64, tmp, usedKB);
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
@ -761,13 +792,14 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
|
|||
}
|
||||
#else
|
||||
struct statvfs info;
|
||||
if (statvfs(dataDir, &info)) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
if (-1 == statvfs(dataDir, &info)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
} else {
|
||||
diskSize->total = info.f_blocks * info.f_frsize;
|
||||
diskSize->avail = info.f_bavail * info.f_frsize;
|
||||
diskSize->used = diskSize->total - diskSize->avail;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -792,7 +824,9 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
|
|||
return 0;
|
||||
#else
|
||||
TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) return -1;
|
||||
if (pFile == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
ssize_t bytes = 0;
|
||||
char line[1024] = {0};
|
||||
|
@ -805,16 +839,16 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
|
|||
break;
|
||||
}
|
||||
if (strstr(line, "rchar:") != NULL) {
|
||||
sscanf(line, "%s %" PRId64, tmp, rchars);
|
||||
(void)sscanf(line, "%s %" PRId64, tmp, rchars);
|
||||
readIndex++;
|
||||
} else if (strstr(line, "wchar:") != NULL) {
|
||||
sscanf(line, "%s %" PRId64, tmp, wchars);
|
||||
(void)sscanf(line, "%s %" PRId64, tmp, wchars);
|
||||
readIndex++;
|
||||
} else if (strstr(line, "read_bytes:") != NULL) { // read_bytes
|
||||
sscanf(line, "%s %" PRId64, tmp, read_bytes);
|
||||
(void)sscanf(line, "%s %" PRId64, tmp, read_bytes);
|
||||
readIndex++;
|
||||
} else if (strstr(line, "write_bytes:") != NULL) { // write_bytes
|
||||
sscanf(line, "%s %" PRId64, tmp, write_bytes);
|
||||
(void)sscanf(line, "%s %" PRId64, tmp, write_bytes);
|
||||
readIndex++;
|
||||
} else {
|
||||
}
|
||||
|
@ -822,7 +856,7 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
|
|||
if (readIndex >= 4) break;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
|
||||
if (readIndex < 4) {
|
||||
return -1;
|
||||
|
@ -876,7 +910,9 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
|||
return 0;
|
||||
#else
|
||||
TdFilePtr pFile = taosOpenFile(tsSysNetFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) return -1;
|
||||
if (pFile == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
ssize_t _bytes = 0;
|
||||
char line[1024];
|
||||
|
@ -895,7 +931,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
|||
char nouse0[200] = {0};
|
||||
|
||||
_bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||
if (_bytes < 0) {
|
||||
if (_bytes <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -905,7 +941,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
|||
continue;
|
||||
}
|
||||
|
||||
sscanf(line,
|
||||
(void)sscanf(line,
|
||||
"%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
|
||||
" %" PRId64,
|
||||
nouse0, &o_rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &o_tbytes, &tpackets);
|
||||
|
@ -913,7 +949,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
|||
*transmit_bytes += o_tbytes;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -951,8 +987,8 @@ void taosKillSystem() {
|
|||
exit(0);
|
||||
#else
|
||||
// SIGINT
|
||||
printf("taosd will shut down soon");
|
||||
kill(tsProcId, 2);
|
||||
(void)printf("taosd will shut down soon");
|
||||
(void)kill(tsProcId, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -984,10 +1020,13 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
|
|||
// fd = open("/proc/sys/kernel/random/uuid", 0);
|
||||
TdFilePtr pFile = taosOpenFile("/proc/sys/kernel/random/uuid", TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
} else {
|
||||
len = taosReadFile(pFile, uid, uidlen);
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
if (len < 0) {
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
if (len >= 36) {
|
||||
|
@ -1015,7 +1054,7 @@ char *taosGetCmdlineByPID(int pid) {
|
|||
return cmdline;
|
||||
#else
|
||||
static char cmdline[1024];
|
||||
sprintf(cmdline, "/proc/%d/cmdline", pid);
|
||||
(void)sprintf(cmdline, "/proc/%d/cmdline", pid);
|
||||
|
||||
// int fd = open(cmdline, O_RDONLY);
|
||||
TdFilePtr pFile = taosOpenFile(cmdline, TD_FILE_READ);
|
||||
|
@ -1027,7 +1066,7 @@ char *taosGetCmdlineByPID(int pid) {
|
|||
|
||||
cmdline[n] = 0;
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
} else {
|
||||
cmdline[0] = 0;
|
||||
}
|
||||
|
@ -1041,9 +1080,13 @@ int64_t taosGetOsUptime() {
|
|||
#elif defined(_TD_DARWIN_64)
|
||||
#else
|
||||
struct sysinfo info;
|
||||
if (0 == sysinfo(&info)) {
|
||||
return (int64_t)info.uptime * 1000;
|
||||
if (-1 == sysinfo(&info)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return (int64_t)info.uptime * 1000;
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -1093,7 +1136,7 @@ void taosSetCoreDump(bool enable) {
|
|||
|
||||
int name[] = {CTL_KERN, KERN_CORE_USES_PID};
|
||||
|
||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
(void)memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
args.name = name;
|
||||
args.nlen = sizeof(name) / sizeof(name[0]);
|
||||
args.oldval = &old_usespid;
|
||||
|
@ -1113,7 +1156,7 @@ void taosSetCoreDump(bool enable) {
|
|||
|
||||
old_usespid = 0;
|
||||
old_len = 0;
|
||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
(void)memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
args.name = name;
|
||||
args.nlen = sizeof(name) / sizeof(name[0]);
|
||||
args.oldval = &old_usespid;
|
||||
|
@ -1176,6 +1219,8 @@ SysNameInfo taosGetSysNameInfo() {
|
|||
tstrncpy(info.release, uts.release, sizeof(info.release));
|
||||
tstrncpy(info.version, uts.version, sizeof(info.version));
|
||||
tstrncpy(info.machine, uts.machine, sizeof(info.machine));
|
||||
} else {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
return info;
|
||||
|
@ -1240,6 +1285,11 @@ int taosGetlocalhostname(char *hostname, size_t maxLen) {
|
|||
return 0;
|
||||
}
|
||||
#else
|
||||
return gethostname(hostname, maxLen);
|
||||
int r = gethostname(hostname, maxLen);
|
||||
if (-1 == r) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -162,8 +162,8 @@ int taosSetConsoleEcho(bool on) {
|
|||
struct termios term;
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &term) == -1) {
|
||||
/*perror("Cannot get the attribution of the terminal");*/
|
||||
return -1;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (on)
|
||||
|
@ -172,18 +172,18 @@ int taosSetConsoleEcho(bool on) {
|
|||
term.c_lflag &= ~ECHOFLAGS;
|
||||
|
||||
err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
|
||||
if (err == -1 || err == EINTR) {
|
||||
/*printf("Cannot set the attribution of the terminal");*/
|
||||
return -1;
|
||||
if (err == -1) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void taosSetTerminalMode() {
|
||||
int32_t taosSetTerminalMode() {
|
||||
#if defined(WINDOWS)
|
||||
|
||||
return 0;
|
||||
#else
|
||||
struct termios newtio;
|
||||
|
||||
|
@ -192,7 +192,7 @@ void taosSetTerminalMode() {
|
|||
/* exit(EXIT_FAILURE); */
|
||||
/* } */
|
||||
|
||||
memcpy(&newtio, &oldtio, sizeof(oldtio));
|
||||
(void)memcpy(&newtio, &oldtio, sizeof(oldtio));
|
||||
|
||||
// Set new terminal attributes.
|
||||
newtio.c_iflag &= ~(IXON | IXOFF | ICRNL | INLCR | IGNCR | IMAXBEL | ISTRIP);
|
||||
|
@ -207,10 +207,13 @@ void taosSetTerminalMode() {
|
|||
newtio.c_cc[VMIN] = 1;
|
||||
newtio.c_cc[VTIME] = 0;
|
||||
|
||||
if (tcsetattr(0, TCSANOW, &newtio) != 0) {
|
||||
fprintf(stderr, "Fail to set terminal properties!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
if (-1 == tcsetattr(0, TCSANOW, &newtio)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
(void)fprintf(stderr, "Fail to set terminal properties!\n");
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -219,54 +222,75 @@ int32_t taosGetOldTerminalMode() {
|
|||
#else
|
||||
/* Make sure stdin is a terminal. */
|
||||
if (!isatty(STDIN_FILENO)) {
|
||||
return -1;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
// Get the parameter of current terminal
|
||||
if (tcgetattr(0, &oldtio) != 0) {
|
||||
return -1;
|
||||
if (-1 == tcgetattr(0, &oldtio)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void taosResetTerminalMode() {
|
||||
int32_t taosResetTerminalMode() {
|
||||
#if defined(WINDOWS)
|
||||
#else
|
||||
if (tcsetattr(0, TCSANOW, &oldtio) != 0) {
|
||||
fprintf(stderr, "Fail to reset the terminal properties!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
if (-1 == tcsetattr(0, TCSANOW, &oldtio)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
(void)fprintf(stderr, "Fail to reset the terminal properties!\n");
|
||||
return terrno;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
TdCmdPtr taosOpenCmd(const char* cmd) {
|
||||
if (cmd == NULL) return NULL;
|
||||
if (cmd == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
return (TdCmdPtr)_popen(cmd, "r");
|
||||
#else
|
||||
return (TdCmdPtr)popen(cmd, "r");
|
||||
TdCmdPtr p = (TdCmdPtr)popen(cmd, "r");
|
||||
if (NULL == p) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t taosGetsCmd(TdCmdPtr pCmd, int32_t maxSize, char* __restrict buf) {
|
||||
if (pCmd == NULL || buf == NULL) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
if (fgets(buf, maxSize, (FILE*)pCmd) == NULL) {
|
||||
return -1;
|
||||
if (feof((FILE*)pCmd)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
terrno = TAOS_SYSTEM_ERROR(ferror((FILE*)pCmd));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return strlen(buf);
|
||||
}
|
||||
|
||||
int64_t taosGetLineCmd(TdCmdPtr pCmd, char** __restrict ptrBuf) {
|
||||
if (pCmd == NULL || ptrBuf == NULL) {
|
||||
return -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
if (*ptrBuf != NULL) {
|
||||
taosMemoryFreeClear(*ptrBuf);
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
*ptrBuf = taosMemoryMalloc(1024);
|
||||
if (*ptrBuf == NULL) return -1;
|
||||
|
@ -277,8 +301,13 @@ int64_t taosGetLineCmd(TdCmdPtr pCmd, char** __restrict ptrBuf) {
|
|||
(*ptrBuf)[1023] = 0;
|
||||
return strlen(*ptrBuf);
|
||||
#else
|
||||
size_t len = 0;
|
||||
return getline(ptrBuf, &len, (FILE*)pCmd);
|
||||
ssize_t len = 0;
|
||||
len = getline(ptrBuf, (size_t*)&len, (FILE*)pCmd);
|
||||
if (-1 == len) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
return len;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -289,15 +318,14 @@ int32_t taosEOFCmd(TdCmdPtr pCmd) {
|
|||
return feof((FILE*)pCmd);
|
||||
}
|
||||
|
||||
int64_t taosCloseCmd(TdCmdPtr* ppCmd) {
|
||||
void taosCloseCmd(TdCmdPtr* ppCmd) {
|
||||
if (ppCmd == NULL || *ppCmd == NULL) {
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
_pclose((FILE*)(*ppCmd));
|
||||
#else
|
||||
pclose((FILE*)(*ppCmd));
|
||||
(void)pclose((FILE*)(*ppCmd));
|
||||
#endif
|
||||
*ppCmd = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -18,68 +18,159 @@
|
|||
#include "os.h"
|
||||
|
||||
int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start)(void *), void *arg) {
|
||||
return pthread_create(tid, attr, start, arg);
|
||||
int32_t code = pthread_create(tid, attr, start, arg);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { return pthread_attr_destroy(attr); }
|
||||
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) {
|
||||
int32_t code = pthread_attr_destroy(attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachstate) {
|
||||
return pthread_attr_getdetachstate(attr, detachstate);
|
||||
int32_t code = pthread_attr_getdetachstate(attr, detachstate);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inheritsched) {
|
||||
return pthread_attr_getinheritsched(attr, inheritsched);
|
||||
int32_t code = pthread_attr_getinheritsched(attr, inheritsched);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param *param) {
|
||||
return pthread_attr_getschedparam(attr, param);
|
||||
int32_t code = pthread_attr_getschedparam(attr, param);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy) {
|
||||
return pthread_attr_getschedpolicy(attr, policy);
|
||||
int32_t code = pthread_attr_getschedpolicy(attr, policy);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscope) {
|
||||
return pthread_attr_getscope(attr, contentionscope);
|
||||
int32_t code = pthread_attr_getscope(attr, contentionscope);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize) {
|
||||
return pthread_attr_getstacksize(attr, stacksize);
|
||||
int32_t code = pthread_attr_getstacksize(attr, stacksize);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrInit(TdThreadAttr *attr) { return pthread_attr_init(attr); }
|
||||
int32_t taosThreadAttrInit(TdThreadAttr *attr) {
|
||||
int32_t code = pthread_attr_init(attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) {
|
||||
return pthread_attr_setdetachstate(attr, detachstate);
|
||||
int32_t code = pthread_attr_setdetachstate(attr, detachstate);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched) {
|
||||
return pthread_attr_setinheritsched(attr, inheritsched);
|
||||
int32_t code = pthread_attr_setinheritsched(attr, inheritsched);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param *param) {
|
||||
return pthread_attr_setschedparam(attr, param);
|
||||
int32_t code = pthread_attr_setschedparam(attr, param);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) {
|
||||
return pthread_attr_setschedpolicy(attr, policy);
|
||||
int32_t code = pthread_attr_setschedpolicy(attr, policy);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) {
|
||||
return pthread_attr_setscope(attr, contentionscope);
|
||||
int32_t code = pthread_attr_setscope(attr, contentionscope);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) {
|
||||
return pthread_attr_setstacksize(attr, stacksize);
|
||||
int32_t code = pthread_attr_setstacksize(attr, stacksize);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadCancel(TdThread thread) { return pthread_cancel(thread); }
|
||||
int32_t taosThreadCancel(TdThread thread) {
|
||||
int32_t code = pthread_cancel(thread);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadCondDestroy(TdThreadCond *cond) {
|
||||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_cond_destroy(cond);
|
||||
int32_t code = pthread_cond_destroy(cond);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -88,7 +179,12 @@ int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) {
|
|||
InitializeConditionVariable(cond);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_cond_init(cond, attr);
|
||||
int32_t code = pthread_cond_init(cond, attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -97,7 +193,12 @@ int32_t taosThreadCondSignal(TdThreadCond *cond) {
|
|||
WakeConditionVariable(cond);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_cond_signal(cond);
|
||||
int32_t code = pthread_cond_signal(cond);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -106,7 +207,12 @@ int32_t taosThreadCondBroadcast(TdThreadCond *cond) {
|
|||
WakeAllConditionVariable(cond);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_cond_broadcast(cond);
|
||||
int32_t code = pthread_cond_broadcast(cond);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -117,7 +223,12 @@ int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) {
|
|||
}
|
||||
return 0;
|
||||
#else
|
||||
return pthread_cond_wait(cond, mutex);
|
||||
int32_t code = pthread_cond_wait(cond, mutex);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -130,7 +241,12 @@ int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const
|
|||
}
|
||||
return EINVAL;
|
||||
#else
|
||||
return pthread_cond_timedwait(cond, mutex, abstime);
|
||||
int32_t code = pthread_cond_timedwait(cond, mutex, abstime);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -138,7 +254,12 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) {
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_condattr_destroy(attr);
|
||||
int32_t code = pthread_condattr_destroy(attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -147,7 +268,12 @@ int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *psha
|
|||
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_condattr_getpshared(attr, pshared);
|
||||
int32_t code = pthread_condattr_getpshared(attr, pshared);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -155,7 +281,12 @@ int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) {
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_condattr_init(attr);
|
||||
int32_t code = pthread_condattr_init(attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -165,7 +296,12 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) {
|
|||
#elif defined(__APPLE__)
|
||||
return 0;
|
||||
#else
|
||||
return pthread_condattr_setclock(attr, clockId);
|
||||
int32_t code = pthread_condattr_setclock(attr, clockId);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -173,31 +309,80 @@ int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_condattr_setpshared(attr, pshared);
|
||||
int32_t code = pthread_condattr_setpshared(attr, pshared);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t taosThreadDetach(TdThread thread) { return pthread_detach(thread); }
|
||||
int32_t taosThreadDetach(TdThread thread) {
|
||||
int32_t code = pthread_detach(thread);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadEqual(TdThread t1, TdThread t2) { return pthread_equal(t1, t2); }
|
||||
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
|
||||
return pthread_equal(t1, t2);
|
||||
}
|
||||
|
||||
void taosThreadExit(void *valuePtr) { return pthread_exit(valuePtr); }
|
||||
void taosThreadExit(void *valuePtr) {
|
||||
return pthread_exit(valuePtr);
|
||||
}
|
||||
|
||||
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
|
||||
return pthread_getschedparam(thread, policy, param);
|
||||
int32_t code = pthread_getschedparam(thread, policy, param);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
void *taosThreadGetSpecific(TdThreadKey key) { return pthread_getspecific(key); }
|
||||
void *taosThreadGetSpecific(TdThreadKey key) {
|
||||
return pthread_getspecific(key);
|
||||
}
|
||||
|
||||
int32_t taosThreadJoin(TdThread thread, void **valuePtr) { return pthread_join(thread, valuePtr); }
|
||||
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
|
||||
int32_t code = pthread_join(thread, valuePtr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
|
||||
return pthread_key_create(key, destructor);
|
||||
int32_t code = pthread_key_create(key, destructor);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadKeyDelete(TdThreadKey key) { return pthread_key_delete(key); }
|
||||
int32_t taosThreadKeyDelete(TdThreadKey key) {
|
||||
int32_t code = pthread_key_delete(key);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadKill(TdThread thread, int32_t sig) { return pthread_kill(thread, sig); }
|
||||
int32_t taosThreadKill(TdThread thread, int32_t sig) {
|
||||
int32_t code = pthread_kill(thread, sig);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
// int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) {
|
||||
// return pthread_mutex_consistent(mutex);
|
||||
|
@ -208,7 +393,12 @@ int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) {
|
|||
DeleteCriticalSection(mutex);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutex_destroy(mutex);
|
||||
int32_t code = pthread_mutex_destroy(mutex);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -222,7 +412,12 @@ int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr)
|
|||
InitializeCriticalSection(mutex);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutex_init(mutex, attr);
|
||||
int32_t code = pthread_mutex_init(mutex, attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -231,7 +426,12 @@ int32_t taosThreadMutexLock(TdThreadMutex *mutex) {
|
|||
EnterCriticalSection(mutex);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutex_lock(mutex);
|
||||
int32_t code = pthread_mutex_lock(mutex);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -244,7 +444,12 @@ int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) {
|
|||
if (TryEnterCriticalSection(mutex)) return 0;
|
||||
return EBUSY;
|
||||
#else
|
||||
return pthread_mutex_trylock(mutex);
|
||||
int32_t code = pthread_mutex_trylock(mutex);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -253,7 +458,12 @@ int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) {
|
|||
LeaveCriticalSection(mutex);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutex_unlock(mutex);
|
||||
int32_t code = pthread_mutex_unlock(mutex);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -261,7 +471,12 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) {
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutexattr_destroy(attr);
|
||||
int32_t code = pthread_mutexattr_destroy(attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -270,7 +485,12 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *ps
|
|||
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutexattr_getpshared(attr, pshared);
|
||||
int32_t code = pthread_mutexattr_getpshared(attr, pshared);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -283,7 +503,12 @@ int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr *attr, int32_t *kind)
|
|||
if (kind) *kind = PTHREAD_MUTEX_NORMAL;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutexattr_gettype(attr, kind);
|
||||
int32_t code = pthread_mutexattr_gettype(attr, kind);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -291,7 +516,12 @@ int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) {
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutexattr_init(attr);
|
||||
int32_t code = pthread_mutexattr_init(attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -299,7 +529,12 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared)
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutexattr_setpshared(attr, pshared);
|
||||
int32_t code = pthread_mutexattr_setpshared(attr, pshared);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -311,12 +546,22 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_mutexattr_settype(attr, kind);
|
||||
int32_t code = pthread_mutexattr_settype(attr, kind);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) {
|
||||
return pthread_once(onceControl, initRoutine);
|
||||
int32_t code = pthread_once(onceControl, initRoutine);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) {
|
||||
|
@ -326,7 +571,12 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) {
|
|||
*/
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlock_destroy(rwlock);
|
||||
int32_t code = pthread_rwlock_destroy(rwlock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -336,7 +586,12 @@ int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *a
|
|||
InitializeSRWLock(&rwlock->lock);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlock_init(rwlock, attr);
|
||||
int32_t code = pthread_rwlock_init(rwlock, attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -345,7 +600,12 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) {
|
|||
AcquireSRWLockShared(&rwlock->lock);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlock_rdlock(rwlock);
|
||||
int32_t code = pthread_rwlock_rdlock(rwlock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -362,7 +622,12 @@ int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) {
|
|||
if (!TryAcquireSRWLockShared(&rwlock->lock)) return EBUSY;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlock_tryrdlock(rwlock);
|
||||
int32_t code = pthread_rwlock_tryrdlock(rwlock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -372,7 +637,12 @@ int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) {
|
|||
atomic_store_8(&rwlock->excl, 1);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlock_trywrlock(rwlock);
|
||||
int32_t code = pthread_rwlock_trywrlock(rwlock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -385,7 +655,12 @@ int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) {
|
|||
}
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlock_unlock(rwlock);
|
||||
int32_t code = pthread_rwlock_unlock(rwlock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -395,7 +670,12 @@ int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) {
|
|||
atomic_store_8(&rwlock->excl, 1);
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlock_wrlock(rwlock);
|
||||
int32_t code = pthread_rwlock_wrlock(rwlock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -403,7 +683,12 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) {
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlockattr_destroy(attr);
|
||||
int32_t code = pthread_rwlockattr_destroy(attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -412,7 +697,12 @@ int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *
|
|||
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlockattr_getpshared(attr, pshared);
|
||||
int32_t code = pthread_rwlockattr_getpshared(attr, pshared);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -420,7 +710,12 @@ int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) {
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlockattr_init(attr);
|
||||
int32_t code = pthread_rwlockattr_init(attr);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -428,27 +723,63 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared
|
|||
#ifdef __USE_WIN_THREAD
|
||||
return 0;
|
||||
#else
|
||||
return pthread_rwlockattr_setpshared(attr, pshared);
|
||||
int32_t code = pthread_rwlockattr_setpshared(attr, pshared);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
TdThread taosThreadSelf(void) { return pthread_self(); }
|
||||
|
||||
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) { return pthread_setcancelstate(state, oldstate); }
|
||||
|
||||
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { return pthread_setcanceltype(type, oldtype); }
|
||||
|
||||
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
|
||||
return pthread_setschedparam(thread, policy, param);
|
||||
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
|
||||
int32_t code = pthread_setcancelstate(state, oldstate);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { return pthread_setspecific(key, value); }
|
||||
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
|
||||
int32_t code = pthread_setcanceltype(type, oldtype);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
|
||||
int32_t code = pthread_setschedparam(thread, policy, param);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
|
||||
int32_t code = pthread_setspecific(key, value);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
|
||||
#ifdef TD_USE_SPINLOCK_AS_MUTEX
|
||||
return pthread_mutex_destroy((pthread_mutex_t *)lock);
|
||||
#else
|
||||
return pthread_spin_destroy((pthread_spinlock_t *)lock);
|
||||
int32_t code = pthread_spin_destroy((pthread_spinlock_t *)lock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -458,7 +789,12 @@ int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) {
|
|||
if (pshared != 0) return -1;
|
||||
return pthread_mutex_init((pthread_mutex_t *)lock, NULL);
|
||||
#else
|
||||
return pthread_spin_init((pthread_spinlock_t *)lock, pshared);
|
||||
int32_t code = pthread_spin_init((pthread_spinlock_t *)lock, pshared);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -466,7 +802,12 @@ int32_t taosThreadSpinLock(TdThreadSpinlock *lock) {
|
|||
#ifdef TD_USE_SPINLOCK_AS_MUTEX
|
||||
return pthread_mutex_lock((pthread_mutex_t *)lock);
|
||||
#else
|
||||
return pthread_spin_lock((pthread_spinlock_t *)lock);
|
||||
int32_t code = pthread_spin_lock((pthread_spinlock_t *)lock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -474,7 +815,12 @@ int32_t taosThreadSpinTrylock(TdThreadSpinlock *lock) {
|
|||
#ifdef TD_USE_SPINLOCK_AS_MUTEX
|
||||
return pthread_mutex_trylock((pthread_mutex_t *)lock);
|
||||
#else
|
||||
return pthread_spin_trylock((pthread_spinlock_t *)lock);
|
||||
int32_t code = pthread_spin_trylock((pthread_spinlock_t *)lock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -482,10 +828,19 @@ int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) {
|
|||
#ifdef TD_USE_SPINLOCK_AS_MUTEX
|
||||
return pthread_mutex_unlock((pthread_mutex_t *)lock);
|
||||
#else
|
||||
return pthread_spin_unlock((pthread_spinlock_t *)lock);
|
||||
int32_t code = pthread_spin_unlock((pthread_spinlock_t *)lock);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return terrno;
|
||||
}
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
void taosThreadTestCancel(void) { return pthread_testcancel(); }
|
||||
void taosThreadTestCancel(void) {
|
||||
return pthread_testcancel();
|
||||
}
|
||||
|
||||
void taosThreadClear(TdThread *thread) { memset(thread, 0, sizeof(TdThread)); }
|
||||
void taosThreadClear(TdThread *thread) {
|
||||
(void)memset(thread, 0, sizeof(TdThread));
|
||||
}
|
||||
|
|
|
@ -945,7 +945,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
char buf[68] = {0};
|
||||
if (pFile != NULL) {
|
||||
int len = taosReadFile(pFile, buf, 64);
|
||||
if (len < 64 && taosGetErrorFile(pFile)) {
|
||||
if (len < 0) {
|
||||
(void)taosCloseFile(&pFile);
|
||||
(void)printf("read /etc/timezone error, reason:%s", strerror(errno));
|
||||
return;
|
||||
|
|
|
@ -40,7 +40,8 @@ TEST(osTest, osFQDNSuccess) {
|
|||
char fqdn[1024];
|
||||
char ipString[INET_ADDRSTRLEN];
|
||||
int code = taosGetFqdn(fqdn);
|
||||
uint32_t ipv4 = taosGetIpv4FromFqdn(fqdn);
|
||||
uint32_t ipv4 = 0;
|
||||
code = taosGetIpv4FromFqdn(fqdn, &ipv4);
|
||||
ASSERT_NE(ipv4, 0xffffffff);
|
||||
|
||||
struct in_addr addr;
|
||||
|
@ -54,8 +55,9 @@ TEST(osTest, osFQDNSuccess) {
|
|||
TEST(osTest, osFQDNFailed) {
|
||||
char fqdn[1024] = "fqdn_test_not_found";
|
||||
char ipString[24];
|
||||
uint32_t ipv4 = taosGetIpv4FromFqdn(fqdn);
|
||||
ASSERT_EQ(ipv4, 0xffffffff);
|
||||
uint32_t ipv4 = 0;
|
||||
int32_t code = taosGetIpv4FromFqdn(fqdn, &ipv4);
|
||||
ASSERT_NE(code, 0);
|
||||
|
||||
terrno = TSDB_CODE_RPC_FQDN_ERROR;
|
||||
printf("fqdn:%s transfer to ip failed!\n", fqdn);
|
||||
|
|
|
@ -1241,13 +1241,14 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
|
||||
char *buf = taosMemoryMalloc(fileSize);
|
||||
char *buf = taosMemoryMalloc(fileSize + 1);
|
||||
if (!buf) {
|
||||
taosCloseFile(&pFile);
|
||||
uError("load json file error: %s, failed to alloc memory", filepath);
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
buf[fileSize] = 0;
|
||||
taosLSeekFile(pFile, 0, SEEK_SET);
|
||||
if (taosReadFile(pFile, buf, fileSize) <= 0) {
|
||||
taosCloseFile(&pFile);
|
||||
|
@ -1277,7 +1278,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
if (itemValueString != NULL && itemName != NULL) {
|
||||
size_t itemNameLen = strlen(itemName);
|
||||
size_t itemValueStringLen = strlen(itemValueString);
|
||||
cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2);
|
||||
cfgLineBuf = taosMemoryRealloc(cfgLineBuf, itemNameLen + itemValueStringLen + 3);
|
||||
if (NULL == cfgLineBuf) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err_json;
|
||||
|
@ -1286,7 +1287,6 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
memcpy(cfgLineBuf, itemName, itemNameLen);
|
||||
cfgLineBuf[itemNameLen] = ' ';
|
||||
memcpy(&cfgLineBuf[itemNameLen + 1], itemValueString, itemValueStringLen);
|
||||
cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0';
|
||||
|
||||
paGetToken(cfgLineBuf, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
|
@ -1325,6 +1325,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
taosMemoryFree(cfgLineBuf);
|
||||
uInfo("load from apoll url not implemented yet");
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) {
|
|||
uError("mempool malloc failed\n");
|
||||
return NULL;
|
||||
} else {
|
||||
memset(pool_p, 0, sizeof(pool_t));
|
||||
(void)memset(pool_p, 0, sizeof(pool_t));
|
||||
}
|
||||
|
||||
pool_p->blockSize = blockSize;
|
||||
|
@ -58,9 +58,9 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
taosThreadMutexInit(&(pool_p->mutex), NULL);
|
||||
(void)taosThreadMutexInit(&(pool_p->mutex), NULL);
|
||||
|
||||
memset(pool_p->pool, 0, (size_t)(blockSize * numOfBlock));
|
||||
(void)memset(pool_p->pool, 0, (size_t)(blockSize * numOfBlock));
|
||||
for (i = 0; i < pool_p->numOfBlock; ++i) pool_p->freeList[i] = i;
|
||||
|
||||
pool_p->first = 0;
|
||||
|
@ -73,7 +73,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
|
|||
char *pos = NULL;
|
||||
pool_t *pool_p = (pool_t *)handle;
|
||||
|
||||
taosThreadMutexLock(&(pool_p->mutex));
|
||||
(void)taosThreadMutexLock(&(pool_p->mutex));
|
||||
|
||||
if (pool_p->numOfFree > 0) {
|
||||
pos = pool_p->pool + pool_p->blockSize * (pool_p->freeList[pool_p->first]);
|
||||
|
@ -82,7 +82,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
|
|||
pool_p->numOfFree--;
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&(pool_p->mutex));
|
||||
(void)taosThreadMutexUnlock(&(pool_p->mutex));
|
||||
|
||||
if (pos == NULL) uDebug("mempool: out of memory");
|
||||
return pos;
|
||||
|
@ -106,22 +106,22 @@ void taosMemPoolFree(mpool_h handle, char *pMem) {
|
|||
return;
|
||||
}
|
||||
|
||||
memset(pMem, 0, (size_t)pool_p->blockSize);
|
||||
(void)memset(pMem, 0, (size_t)pool_p->blockSize);
|
||||
|
||||
taosThreadMutexLock(&pool_p->mutex);
|
||||
(void)taosThreadMutexLock(&pool_p->mutex);
|
||||
|
||||
pool_p->freeList[(pool_p->first + pool_p->numOfFree) % pool_p->numOfBlock] = index;
|
||||
pool_p->numOfFree++;
|
||||
|
||||
taosThreadMutexUnlock(&pool_p->mutex);
|
||||
(void)taosThreadMutexUnlock(&pool_p->mutex);
|
||||
}
|
||||
|
||||
void taosMemPoolCleanUp(mpool_h handle) {
|
||||
pool_t *pool_p = (pool_t *)handle;
|
||||
|
||||
taosThreadMutexDestroy(&pool_p->mutex);
|
||||
(void)taosThreadMutexDestroy(&pool_p->mutex);
|
||||
if (pool_p->pool) taosMemoryFree(pool_p->pool);
|
||||
if (pool_p->freeList) taosMemoryFree(pool_p->freeList);
|
||||
memset(pool_p, 0, sizeof(*pool_p));
|
||||
(void)memset(pool_p, 0, sizeof(*pool_p));
|
||||
taosMemoryFree(pool_p);
|
||||
}
|
||||
|
|
|
@ -1118,7 +1118,7 @@ void shellSourceFile(const char *file) {
|
|||
}
|
||||
|
||||
char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1);
|
||||
while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) != -1) {
|
||||
while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) > 0) {
|
||||
if ( cmd_len + read_len >= TSDB_MAX_ALLOWED_SQL_LEN) {
|
||||
printf("read command line too long over 1M, ignore this line. cmd_len = %d read_len=%d \n", (int32_t)cmd_len, read_len);
|
||||
cmd_len = 0;
|
||||
|
|
|
@ -198,7 +198,7 @@ SScript *simParseScript(char *fileName) {
|
|||
simResetParser();
|
||||
|
||||
while (!taosEOFFile(pFile)) {
|
||||
if (taosGetsFile(pFile, sizeof(buffer) - 1, buffer) == -1) continue;
|
||||
if (taosGetsFile(pFile, sizeof(buffer) - 1, buffer) <= 0) continue;
|
||||
|
||||
lineNum++;
|
||||
int32_t cmdlen = (int32_t)strlen(buffer);
|
||||
|
|
Loading…
Reference in New Issue