Merge pull request #28250 from taosdata/fix/TD-32409
fix: use safe function
This commit is contained in:
commit
fc05f92fc9
|
@ -64,7 +64,7 @@ static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) {
|
||||||
: 1000000000;
|
: 1000000000;
|
||||||
time_t t = taosTime(NULL);
|
time_t t = taosTime(NULL);
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
(void) taosLocalTime(&t, &tm, NULL);
|
(void) taosLocalTime(&t, &tm, NULL, 0);
|
||||||
tm.tm_hour = 0;
|
tm.tm_hour = 0;
|
||||||
tm.tm_min = 0;
|
tm.tm_min = 0;
|
||||||
tm.tm_sec = 0;
|
tm.tm_sec = 0;
|
||||||
|
|
|
@ -247,9 +247,12 @@ void syslog(int unused, const char *format, ...);
|
||||||
#define TD_DIRSEP_CHAR '/'
|
#define TD_DIRSEP_CHAR '/'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TD_FQDN_LEN 128
|
||||||
#define TD_LOCALE_LEN 64
|
#define TD_LOCALE_LEN 64
|
||||||
#define TD_CHARSET_LEN 64
|
#define TD_CHARSET_LEN 64
|
||||||
#define TD_TIMEZONE_LEN 96
|
#define TD_TIMEZONE_LEN 96
|
||||||
|
#define TD_TIME_STR_LEN 128
|
||||||
|
#define TD_IP_LEN 64
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs
|
||||||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
|
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
|
||||||
int32_t 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);
|
bool taosValidateEncodec(const char *encodec);
|
||||||
int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len);
|
int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len, int32_t bufSize);
|
||||||
int32_t taosHexDecode(const char *src, char *dst, int32_t len);
|
int32_t taosHexDecode(const char *src, char *dst, int32_t len);
|
||||||
|
|
||||||
int32_t taosWcharWidth(TdWchar wchar);
|
int32_t taosWcharWidth(TdWchar wchar);
|
||||||
|
|
|
@ -91,7 +91,7 @@ static FORCE_INLINE int64_t taosGetMonoTimestampMs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm);
|
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm);
|
||||||
struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf);
|
struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf, int32_t bufSize);
|
||||||
struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst);
|
struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst);
|
||||||
time_t taosTime(time_t *t);
|
time_t taosTime(time_t *t);
|
||||||
time_t taosMktime(struct tm *timep);
|
time_t taosMktime(struct tm *timep);
|
||||||
|
|
|
@ -284,7 +284,7 @@ typedef enum ELogicConditionType {
|
||||||
|
|
||||||
#define TSDB_CLUSTER_ID_LEN 40
|
#define TSDB_CLUSTER_ID_LEN 40
|
||||||
#define TSDB_MACHINE_ID_LEN 24
|
#define TSDB_MACHINE_ID_LEN 24
|
||||||
#define TSDB_FQDN_LEN 128
|
#define TSDB_FQDN_LEN TD_FQDN_LEN
|
||||||
#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6)
|
#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6)
|
||||||
#define TSDB_IPv4ADDR_LEN 16
|
#define TSDB_IPv4ADDR_LEN 16
|
||||||
#define TSDB_FILENAME_LEN 128
|
#define TSDB_FILENAME_LEN 128
|
||||||
|
|
|
@ -2446,7 +2446,7 @@ _error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
static char* formatTimestamp(char* buf, int32_t bufSize, int64_t val, int precision) {
|
||||||
time_t tt;
|
time_t tt;
|
||||||
int32_t ms = 0;
|
int32_t ms = 0;
|
||||||
if (precision == TSDB_TIME_PRECISION_NANO) {
|
if (precision == TSDB_TIME_PRECISION_NANO) {
|
||||||
|
@ -2479,11 +2479,11 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct tm ptm = {0};
|
struct tm ptm = {0};
|
||||||
if (taosLocalTime(&tt, &ptm, buf) == NULL) {
|
if (taosLocalTime(&tt, &ptm, buf, bufSize) == NULL) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
|
size_t pos = strftime(buf, bufSize, "%Y-%m-%d %H:%M:%S", &ptm);
|
||||||
if (precision == TSDB_TIME_PRECISION_NANO) {
|
if (precision == TSDB_TIME_PRECISION_NANO) {
|
||||||
sprintf(buf + pos, ".%09d", ms);
|
sprintf(buf + pos, ".%09d", ms);
|
||||||
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
|
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
|
||||||
|
@ -2500,7 +2500,7 @@ int32_t dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf
|
||||||
int32_t size = 2048 * 1024;
|
int32_t size = 2048 * 1024;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
char* dumpBuf = NULL;
|
char* dumpBuf = NULL;
|
||||||
char pBuf[128] = {0};
|
char pBuf[TD_TIME_STR_LEN] = {0};
|
||||||
int32_t rows = pDataBlock->info.rows;
|
int32_t rows = pDataBlock->info.rows;
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
|
|
||||||
|
@ -2543,7 +2543,7 @@ int32_t dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf
|
||||||
switch (pColInfoData->info.type) {
|
switch (pColInfoData->info.type) {
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
memset(pBuf, 0, sizeof(pBuf));
|
memset(pBuf, 0, sizeof(pBuf));
|
||||||
(void)formatTimestamp(pBuf, *(uint64_t*)var, pColInfoData->info.precision);
|
(void)formatTimestamp(pBuf, sizeof(pBuf), *(uint64_t*)var, pColInfoData->info.precision);
|
||||||
len += snprintf(dumpBuf + len, size - len, " %25s |", pBuf);
|
len += snprintf(dumpBuf + len, size - len, " %25s |", pBuf);
|
||||||
if (len >= size - 1) goto _exit;
|
if (len >= size - 1) goto _exit;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -33,7 +33,7 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
|
||||||
}
|
}
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t t = (time_t)start;
|
time_t t = (time_t)start;
|
||||||
taosLocalTime(&t, &tm);
|
taosLocalTime(&t, &tm, NULL, 0);
|
||||||
tm.tm_sec = 0;
|
tm.tm_sec = 0;
|
||||||
tm.tm_min = 0;
|
tm.tm_min = 0;
|
||||||
tm.tm_hour = 0;
|
tm.tm_hour = 0;
|
||||||
|
|
|
@ -693,7 +693,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
|
||||||
|
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
|
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
|
||||||
struct tm* ptm = taosLocalTime(&tt, &tm, NULL);
|
struct tm* ptm = taosLocalTime(&tt, &tm, NULL, 0);
|
||||||
int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)numOfMonth;
|
int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)numOfMonth;
|
||||||
tm.tm_year = mon / 12;
|
tm.tm_year = mon / 12;
|
||||||
tm.tm_mon = mon % 12;
|
tm.tm_mon = mon % 12;
|
||||||
|
@ -754,11 +754,11 @@ int32_t taosTimeCountIntervalForFill(int64_t skey, int64_t ekey, int64_t interva
|
||||||
|
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t t = (time_t)skey;
|
time_t t = (time_t)skey;
|
||||||
struct tm* ptm = taosLocalTime(&t, &tm, NULL);
|
struct tm* ptm = taosLocalTime(&t, &tm, NULL, 0);
|
||||||
int32_t smon = tm.tm_year * 12 + tm.tm_mon;
|
int32_t smon = tm.tm_year * 12 + tm.tm_mon;
|
||||||
|
|
||||||
t = (time_t)ekey;
|
t = (time_t)ekey;
|
||||||
ptm = taosLocalTime(&t, &tm, NULL);
|
ptm = taosLocalTime(&t, &tm, NULL, 0);
|
||||||
int32_t emon = tm.tm_year * 12 + tm.tm_mon;
|
int32_t emon = tm.tm_year * 12 + tm.tm_mon;
|
||||||
|
|
||||||
if (unit == 'y') {
|
if (unit == 'y') {
|
||||||
|
@ -782,7 +782,7 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) {
|
||||||
start /= (int64_t)(TSDB_TICK_PER_SECOND(precision));
|
start /= (int64_t)(TSDB_TICK_PER_SECOND(precision));
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t tt = (time_t)start;
|
time_t tt = (time_t)start;
|
||||||
struct tm* ptm = taosLocalTime(&tt, &tm, NULL);
|
struct tm* ptm = taosLocalTime(&tt, &tm, NULL, 0);
|
||||||
tm.tm_sec = 0;
|
tm.tm_sec = 0;
|
||||||
tm.tm_min = 0;
|
tm.tm_min = 0;
|
||||||
tm.tm_hour = 0;
|
tm.tm_hour = 0;
|
||||||
|
@ -911,13 +911,13 @@ int64_t taosTimeGetIntervalEnd(int64_t intervalStart, const SInterval* pInterval
|
||||||
// 2020-07-03 17:48:42
|
// 2020-07-03 17:48:42
|
||||||
// and the parameter can also be a variable.
|
// and the parameter can also be a variable.
|
||||||
const char* fmtts(int64_t ts) {
|
const char* fmtts(int64_t ts) {
|
||||||
static char buf[96] = {0};
|
static char buf[TD_TIME_STR_LEN] = {0};
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
|
||||||
if (ts > -62135625943 && ts < 32503651200) {
|
if (ts > -62135625943 && ts < 32503651200) {
|
||||||
time_t t = (time_t)ts;
|
time_t t = (time_t)ts;
|
||||||
if (taosLocalTime(&t, &tm, buf) == NULL) {
|
if (taosLocalTime(&t, &tm, buf, sizeof(buf)) == NULL) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
pos += strftime(buf + pos, sizeof(buf), "s=%Y-%m-%d %H:%M:%S", &tm);
|
pos += strftime(buf + pos, sizeof(buf), "s=%Y-%m-%d %H:%M:%S", &tm);
|
||||||
|
@ -925,7 +925,7 @@ const char* fmtts(int64_t ts) {
|
||||||
|
|
||||||
if (ts > -62135625943000 && ts < 32503651200000) {
|
if (ts > -62135625943000 && ts < 32503651200000) {
|
||||||
time_t t = (time_t)(ts / 1000);
|
time_t t = (time_t)(ts / 1000);
|
||||||
if (taosLocalTime(&t, &tm, buf) == NULL) {
|
if (taosLocalTime(&t, &tm, buf, sizeof(buf)) == NULL) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
|
@ -939,7 +939,7 @@ const char* fmtts(int64_t ts) {
|
||||||
|
|
||||||
{
|
{
|
||||||
time_t t = (time_t)(ts / 1000000);
|
time_t t = (time_t)(ts / 1000000);
|
||||||
if (taosLocalTime(&t, &tm, buf) == NULL) {
|
if (taosLocalTime(&t, &tm, buf, sizeof(buf)) == NULL) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
|
@ -993,7 +993,7 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio
|
||||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == taosLocalTime(", &ptm, buf)) {
|
if (NULL == taosLocalTime(", &ptm, buf, bufLen)) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||||
}
|
}
|
||||||
int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", &ptm);
|
int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", &ptm);
|
||||||
|
@ -1007,7 +1007,7 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio
|
||||||
int32_t taosTs2Tm(int64_t ts, int32_t precision, struct STm* tm) {
|
int32_t taosTs2Tm(int64_t ts, int32_t precision, struct STm* tm) {
|
||||||
tm->fsec = ts % TICK_PER_SECOND[precision] * (TICK_PER_SECOND[TSDB_TIME_PRECISION_NANO] / TICK_PER_SECOND[precision]);
|
tm->fsec = ts % TICK_PER_SECOND[precision] * (TICK_PER_SECOND[TSDB_TIME_PRECISION_NANO] / TICK_PER_SECOND[precision]);
|
||||||
time_t t = ts / TICK_PER_SECOND[precision];
|
time_t t = ts / TICK_PER_SECOND[precision];
|
||||||
if (NULL == taosLocalTime(&t, &tm->tm, NULL)) {
|
if (NULL == taosLocalTime(&t, &tm->tm, NULL, 0)) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -2916,7 +2916,7 @@ int32_t ctgHandleGetTbTSMARsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf
|
||||||
|
|
||||||
if (META_TYPE_BOTH_TABLE == pOut->metaType) {
|
if (META_TYPE_BOTH_TABLE == pOut->metaType) {
|
||||||
// rewrite tsma fetch table with it's super table name
|
// rewrite tsma fetch table with it's super table name
|
||||||
(void)sprintf(pFetch->tsmaSourceTbName.tname, "%s", pOut->tbName);
|
(void)snprintf(pFetch->tsmaSourceTbName.tname, sizeof(pFetch->tsmaSourceTbName.tname), "%s", pOut->tbName);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgGetTbTSMAFromMnode(pCtg, pConn, &pFetch->tsmaSourceTbName, NULL, tReq, TDMT_MND_GET_TABLE_TSMA));
|
CTG_ERR_JRET(ctgGetTbTSMAFromMnode(pCtg, pConn, &pFetch->tsmaSourceTbName, NULL, tReq, TDMT_MND_GET_TABLE_TSMA));
|
||||||
|
|
|
@ -176,22 +176,22 @@ int32_t ctgdLaunchAsyncCall(SCatalog *pCtg, SRequestConnInfo *pConn, uint64_t re
|
||||||
taosArrayPush(req.pTableMeta, &name);
|
taosArrayPush(req.pTableMeta, &name);
|
||||||
taosArrayPush(req.pTableHash, &name);
|
taosArrayPush(req.pTableHash, &name);
|
||||||
|
|
||||||
strcpy(dbFName, "1.db1");
|
tstrncpy(dbFName, "1.db1", sizeof(dbFName));
|
||||||
taosArrayPush(req.pDbVgroup, dbFName);
|
taosArrayPush(req.pDbVgroup, dbFName);
|
||||||
taosArrayPush(req.pDbCfg, dbFName);
|
taosArrayPush(req.pDbCfg, dbFName);
|
||||||
taosArrayPush(req.pDbInfo, dbFName);
|
taosArrayPush(req.pDbInfo, dbFName);
|
||||||
strcpy(dbFName, "1.db2");
|
tstrncpy(dbFName, "1.db2", sizeof(dbFName));
|
||||||
taosArrayPush(req.pDbVgroup, dbFName);
|
taosArrayPush(req.pDbVgroup, dbFName);
|
||||||
taosArrayPush(req.pDbCfg, dbFName);
|
taosArrayPush(req.pDbCfg, dbFName);
|
||||||
taosArrayPush(req.pDbInfo, dbFName);
|
taosArrayPush(req.pDbInfo, dbFName);
|
||||||
|
|
||||||
strcpy(funcName, "udf1");
|
tstrncpy(funcName, "udf1", sizeof(funcName));
|
||||||
taosArrayPush(req.pUdf, funcName);
|
taosArrayPush(req.pUdf, funcName);
|
||||||
strcpy(funcName, "udf2");
|
tstrncpy(funcName, "udf2", sizeof(funcName));
|
||||||
taosArrayPush(req.pUdf, funcName);
|
taosArrayPush(req.pUdf, funcName);
|
||||||
|
|
||||||
strcpy(user.user, "root");
|
tstrncpy(user.user, "root", sizeof(user.user));
|
||||||
strcpy(user.dbFName, "1.db1");
|
tstrncpy(user.dbFName, "1.db1", sizeof(user.dbFName));
|
||||||
user.type = AUTH_TYPE_READ;
|
user.type = AUTH_TYPE_READ;
|
||||||
taosArrayPush(req.pUser, &user);
|
taosArrayPush(req.pUser, &user);
|
||||||
user.type = AUTH_TYPE_WRITE;
|
user.type = AUTH_TYPE_WRITE;
|
||||||
|
@ -199,8 +199,8 @@ int32_t ctgdLaunchAsyncCall(SCatalog *pCtg, SRequestConnInfo *pConn, uint64_t re
|
||||||
user.type = AUTH_TYPE_OTHER;
|
user.type = AUTH_TYPE_OTHER;
|
||||||
taosArrayPush(req.pUser, &user);
|
taosArrayPush(req.pUser, &user);
|
||||||
|
|
||||||
strcpy(user.user, "user1");
|
tstrncpy(user.user, "user1", sizeof(user.user));
|
||||||
strcpy(user.dbFName, "1.db2");
|
tstrncpy(user.dbFName, "1.db2", sizeof(user.dbFName));
|
||||||
user.type = AUTH_TYPE_READ;
|
user.type = AUTH_TYPE_READ;
|
||||||
taosArrayPush(req.pUser, &user);
|
taosArrayPush(req.pUser, &user);
|
||||||
user.type = AUTH_TYPE_WRITE;
|
user.type = AUTH_TYPE_WRITE;
|
||||||
|
@ -335,7 +335,7 @@ int32_t ctgdHandleDbgCommand(char *command) {
|
||||||
CTG_RET(TSDB_CODE_INVALID_PARA);
|
CTG_RET(TSDB_CODE_INVALID_PARA);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool enable = atoi(param);
|
bool enable = taosStr2Int32(param, NULL, 10);
|
||||||
|
|
||||||
int32_t code = ctgdEnableDebug(option, enable);
|
int32_t code = ctgdEnableDebug(option, enable);
|
||||||
|
|
||||||
|
|
|
@ -1303,7 +1303,7 @@ int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo* pConn, const
|
||||||
int32_t msgLen = 0;
|
int32_t msgLen = 0;
|
||||||
int32_t reqType = TDMT_MND_TABLE_META;
|
int32_t reqType = TDMT_MND_TABLE_META;
|
||||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||||
(void)sprintf(tbFName, "%s.%s", dbFName, tbName);
|
(void)snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName);
|
||||||
void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont;
|
void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont;
|
||||||
|
|
||||||
ctgDebug("try to get table meta from mnode, tbFName:%s", tbFName);
|
ctgDebug("try to get table meta from mnode, tbFName:%s", tbFName);
|
||||||
|
@ -1369,7 +1369,7 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa
|
||||||
(void)tNameGetFullDbName(pTableName, dbFName);
|
(void)tNameGetFullDbName(pTableName, dbFName);
|
||||||
int32_t reqType = (pTask && pTask->type == CTG_TASK_GET_TB_NAME ? TDMT_VND_TABLE_NAME : TDMT_VND_TABLE_META);
|
int32_t reqType = (pTask && pTask->type == CTG_TASK_GET_TB_NAME ? TDMT_VND_TABLE_NAME : TDMT_VND_TABLE_META);
|
||||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||||
(void)sprintf(tbFName, "%s.%s", dbFName, pTableName->tname);
|
(void)snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, pTableName->tname);
|
||||||
void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont;
|
void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont;
|
||||||
|
|
||||||
SEp* pEp = &vgroupInfo->epSet.eps[vgroupInfo->epSet.inUse];
|
SEp* pEp = &vgroupInfo->epSet.eps[vgroupInfo->epSet.inUse];
|
||||||
|
|
|
@ -1386,7 +1386,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR
|
||||||
}
|
}
|
||||||
|
|
||||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||||
(void)sprintf(tbFullName, "%s.", dbFName);
|
(void)snprintf(tbFullName, sizeof(tbFullName), "%s.", dbFName);
|
||||||
int32_t offset = strlen(tbFullName);
|
int32_t offset = strlen(tbFullName);
|
||||||
SName* pName = NULL;
|
SName* pName = NULL;
|
||||||
int32_t tbNameLen = 0;
|
int32_t tbNameLen = 0;
|
||||||
|
@ -2070,7 +2070,7 @@ int32_t ctgChkSetTbAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)sprintf(tbFName, "%s.%s", dbFName, stbName);
|
(void)snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, stbName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,14 +78,15 @@ static void logGroupCacheExecInfo(SGroupCacheOperatorInfo* pGrpCacheOperator) {
|
||||||
if (pGrpCacheOperator->downstreamNum <= 0 || NULL == pGrpCacheOperator->execInfo.pDownstreamBlkNum) {
|
if (pGrpCacheOperator->downstreamNum <= 0 || NULL == pGrpCacheOperator->execInfo.pDownstreamBlkNum) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* buf = taosMemoryMalloc(pGrpCacheOperator->downstreamNum * 32 + 100);
|
int32_t bufSize = pGrpCacheOperator->downstreamNum * 32 + 100;
|
||||||
|
char* buf = taosMemoryMalloc(bufSize);
|
||||||
if (NULL == buf) {
|
if (NULL == buf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int32_t offset = sprintf(buf, "groupCache exec info, downstreamBlkNum:");
|
int32_t offset = snprintf(buf, bufSize, "groupCache exec info, downstreamBlkNum:");
|
||||||
for (int32_t i = 0; i < pGrpCacheOperator->downstreamNum; ++i) {
|
for (int32_t i = 0; i < pGrpCacheOperator->downstreamNum; ++i) {
|
||||||
offset += sprintf(buf + offset, " %" PRId64 , pGrpCacheOperator->execInfo.pDownstreamBlkNum[i]);
|
offset += snprintf(buf + offset, bufSize, " %" PRId64 , pGrpCacheOperator->execInfo.pDownstreamBlkNum[i]);
|
||||||
}
|
}
|
||||||
qDebug("%s", buf);
|
qDebug("%s", buf);
|
||||||
taosMemoryFree(buf);
|
taosMemoryFree(buf);
|
||||||
|
@ -234,7 +235,7 @@ static int32_t acquireFdFromFileCtx(SGcFileCacheCtx* pFileCtx, int32_t fileId, S
|
||||||
|
|
||||||
SGroupCacheFileInfo* pTmp = taosHashGet(pFileCtx->pCacheFile, &fileId, sizeof(fileId));
|
SGroupCacheFileInfo* pTmp = taosHashGet(pFileCtx->pCacheFile, &fileId, sizeof(fileId));
|
||||||
if (NULL == pTmp) {
|
if (NULL == pTmp) {
|
||||||
(void)sprintf(&pFileCtx->baseFilename[pFileCtx->baseNameLen], "_%d", fileId);
|
(void)snprintf(&pFileCtx->baseFilename[pFileCtx->baseNameLen], sizeof(pFileCtx->baseFilename) - pFileCtx->baseNameLen, "_%d", fileId);
|
||||||
|
|
||||||
SGroupCacheFileInfo newFile = {0};
|
SGroupCacheFileInfo newFile = {0};
|
||||||
if (taosHashPut(pFileCtx->pCacheFile, &fileId, sizeof(fileId), &newFile, sizeof(newFile))) {
|
if (taosHashPut(pFileCtx->pCacheFile, &fileId, sizeof(fileId), &newFile, sizeof(newFile))) {
|
||||||
|
@ -439,7 +440,7 @@ static FORCE_INLINE void chkRemoveVgroupCurrFile(SGcFileCacheCtx* pFileCtx, int3
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* debug only */
|
/* debug only */
|
||||||
sprintf(&pFileCtx->baseFilename[pFileCtx->baseNameLen], "_%d", pFileCtx->fileId);
|
snprintf(&pFileCtx->baseFilename[pFileCtx->baseNameLen], sizeof(pFileCtx->baseFilename) - pFileCtx->baseNameLen, "_%d", pFileCtx->fileId);
|
||||||
taosRemoveFile(pFileCtx->baseFilename);
|
taosRemoveFile(pFileCtx->baseFilename);
|
||||||
/* debug only */
|
/* debug only */
|
||||||
#endif
|
#endif
|
||||||
|
@ -813,7 +814,7 @@ static int32_t addFileRefTableNum(SGcFileCacheCtx* pFileCtx, int32_t fileId, int
|
||||||
|
|
||||||
SGroupCacheFileInfo* pTmp = taosHashGet(pFileCtx->pCacheFile, &fileId, sizeof(fileId));
|
SGroupCacheFileInfo* pTmp = taosHashGet(pFileCtx->pCacheFile, &fileId, sizeof(fileId));
|
||||||
if (NULL == pTmp) {
|
if (NULL == pTmp) {
|
||||||
(void)sprintf(&pFileCtx->baseFilename[pFileCtx->baseNameLen], "_%u", fileId);
|
(void)snprintf(&pFileCtx->baseFilename[pFileCtx->baseNameLen], sizeof(pFileCtx->baseFilename) - pFileCtx->baseNameLen, "_%u", fileId);
|
||||||
|
|
||||||
SGroupCacheFileInfo newFile = {0};
|
SGroupCacheFileInfo newFile = {0};
|
||||||
newFile.groupNum = 1;
|
newFile.groupNum = 1;
|
||||||
|
@ -1377,7 +1378,7 @@ static void freeRemoveGroupCacheData(void* p) {
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* debug only */
|
/* debug only */
|
||||||
sprintf(&pFileCtx->baseFilename[pFileCtx->baseNameLen], "_%d", pGroup->fileId);
|
snprintf(&pFileCtx->baseFilename[pFileCtx->baseNameLen], sizeof(pFileCtx->baseFilename) - pFileCtx->baseNameLen, "_%d", pGroup->fileId);
|
||||||
taosRemoveFile(pFileCtx->baseFilename);
|
taosRemoveFile(pFileCtx->baseFilename);
|
||||||
/* debug only */
|
/* debug only */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -209,10 +209,10 @@ static int32_t countTrailingSpaces(const SValueNode* pVal, bool isLtrim) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t addTimezoneParam(SNodeList* pList) {
|
static int32_t addTimezoneParam(SNodeList* pList) {
|
||||||
char buf[6] = {0};
|
char buf[TD_TIME_STR_LEN] = {0};
|
||||||
time_t t = taosTime(NULL);
|
time_t t = taosTime(NULL);
|
||||||
struct tm tmInfo;
|
struct tm tmInfo;
|
||||||
if (taosLocalTime(&t, &tmInfo, buf) != NULL) {
|
if (taosLocalTime(&t, &tmInfo, buf, sizeof(buf)) != NULL) {
|
||||||
(void)strftime(buf, sizeof(buf), "%z", &tmInfo);
|
(void)strftime(buf, sizeof(buf), "%z", &tmInfo);
|
||||||
}
|
}
|
||||||
int32_t len = (int32_t)strlen(buf);
|
int32_t len = (int32_t)strlen(buf);
|
||||||
|
|
|
@ -4058,9 +4058,10 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_NCHAR: {
|
case TSDB_DATA_TYPE_NCHAR: {
|
||||||
// cJSON only support utf-8 encoding. Convert memory content to hex string.
|
// cJSON only support utf-8 encoding. Convert memory content to hex string.
|
||||||
char* buf = taosMemoryCalloc(varDataLen(pNode->datum.p) * 2 + 1, sizeof(char));
|
int32_t bufSize = varDataLen(pNode->datum.p) * 2 + 1;
|
||||||
|
char* buf = taosMemoryCalloc(bufSize, sizeof(char));
|
||||||
if (!buf) return terrno;
|
if (!buf) return terrno;
|
||||||
code = taosHexEncode(varDataVal(pNode->datum.p), buf, varDataLen(pNode->datum.p));
|
code = taosHexEncode(varDataVal(pNode->datum.p), buf, varDataLen(pNode->datum.p), bufSize);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
taosMemoryFree(buf);
|
taosMemoryFree(buf);
|
||||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||||
|
@ -4076,9 +4077,10 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_JSON: {
|
case TSDB_DATA_TYPE_JSON: {
|
||||||
int32_t len = getJsonValueLen(pNode->datum.p);
|
int32_t len = getJsonValueLen(pNode->datum.p);
|
||||||
char* buf = taosMemoryCalloc(len * 2 + 1, sizeof(char));
|
int32_t bufSize = len * 2 + 1;
|
||||||
|
char* buf = taosMemoryCalloc(bufSize, sizeof(char));
|
||||||
if (!buf) return terrno;
|
if (!buf) return terrno;
|
||||||
code = taosHexEncode(pNode->datum.p, buf, len);
|
code = taosHexEncode(pNode->datum.p, buf, len, bufSize);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
taosMemoryFree(buf);
|
taosMemoryFree(buf);
|
||||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||||
|
|
|
@ -539,7 +539,7 @@ int32_t qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbFName[0] && tbName[0]) {
|
if (dbFName[0] && tbName[0]) {
|
||||||
(void)sprintf(tbInfo.tbFName, "%s.%s", dbFName, tbName);
|
(void)snprintf(tbInfo.tbFName, sizeof(tbInfo.tbFName), "%s.%s", dbFName, tbName);
|
||||||
} else {
|
} else {
|
||||||
tbInfo.tbFName[0] = 0;
|
tbInfo.tbFName[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2193,7 +2193,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
|
||||||
NUM_TO_STRING(type, input, sizeof(fraction), fraction);
|
NUM_TO_STRING(type, input, sizeof(fraction), fraction);
|
||||||
int32_t fractionLen;
|
int32_t fractionLen;
|
||||||
|
|
||||||
char buf[64] = {0};
|
char buf[TD_TIME_STR_LEN] = {0};
|
||||||
int64_t timeVal;
|
int64_t timeVal;
|
||||||
char* format = NULL;
|
char* format = NULL;
|
||||||
int64_t quot = 0;
|
int64_t quot = 0;
|
||||||
|
@ -2244,7 +2244,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
|
||||||
struct tm tmInfo;
|
struct tm tmInfo;
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
|
|
||||||
if (taosLocalTime((const time_t *)", &tmInfo, buf) == NULL) {
|
if (taosLocalTime((const time_t *)", &tmInfo, buf, sizeof(buf)) == NULL) {
|
||||||
len = (int32_t)strlen(buf);
|
len = (int32_t)strlen(buf);
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -729,7 +729,7 @@ int32_t schMakeHbCallbackParam(SSchJob *pJob, SSchTask *pTask, void **pParam) {
|
||||||
|
|
||||||
param->nodeEpId.nodeId = addr->nodeId;
|
param->nodeEpId.nodeId = addr->nodeId;
|
||||||
SEp* pEp = SCH_GET_CUR_EP(addr);
|
SEp* pEp = SCH_GET_CUR_EP(addr);
|
||||||
strcpy(param->nodeEpId.ep.fqdn, pEp->fqdn);
|
tstrncpy(param->nodeEpId.ep.fqdn, pEp->fqdn, sizeof(param->nodeEpId.ep.fqdn));
|
||||||
param->nodeEpId.ep.port = pEp->port;
|
param->nodeEpId.ep.port = pEp->port;
|
||||||
param->pTrans = pJob->pTrans;
|
param->pTrans = pJob->pTrans;
|
||||||
|
|
||||||
|
|
|
@ -288,7 +288,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (SCH_IS_DATA_SRC_TASK(task) && job->dataSrcEps.numOfEps < SCH_MAX_CANDIDATE_EP_NUM) {
|
if (SCH_IS_DATA_SRC_TASK(task) && job->dataSrcEps.numOfEps < SCH_MAX_CANDIDATE_EP_NUM) {
|
||||||
strncpy(job->dataSrcEps.fqdn[job->dataSrcEps.numOfEps], task->execAddr.fqdn, sizeof(task->execAddr.fqdn));
|
tstrncpy(job->dataSrcEps.fqdn[job->dataSrcEps.numOfEps], task->execAddr.fqdn, sizeof(task->execAddr.fqdn));
|
||||||
job->dataSrcEps.port[job->dataSrcEps.numOfEps] = task->execAddr.port;
|
job->dataSrcEps.port[job->dataSrcEps.numOfEps] = task->execAddr.port;
|
||||||
|
|
||||||
++job->dataSrcEps.numOfEps;
|
++job->dataSrcEps.numOfEps;
|
||||||
|
@ -840,7 +840,7 @@ int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int32_t i = 0; i < job->dataSrcEps.numOfEps && addNum < SCH_MAX_CANDIDATE_EP_NUM; ++i) {
|
for (int32_t i = 0; i < job->dataSrcEps.numOfEps && addNum < SCH_MAX_CANDIDATE_EP_NUM; ++i) {
|
||||||
strncpy(epSet->fqdn[epSet->numOfEps], job->dataSrcEps.fqdn[i], sizeof(job->dataSrcEps.fqdn[i]));
|
tstrncpy(epSet->fqdn[epSet->numOfEps], job->dataSrcEps.fqdn[i], sizeof(job->dataSrcEps.fqdn[i]));
|
||||||
epSet->port[epSet->numOfEps] = job->dataSrcEps.port[i];
|
epSet->port[epSet->numOfEps] = job->dataSrcEps.port[i];
|
||||||
|
|
||||||
++epSet->numOfEps;
|
++epSet->numOfEps;
|
||||||
|
|
|
@ -60,7 +60,7 @@ bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId*
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char ipbuf[128] = {0};
|
char ipbuf[TD_IP_LEN] = {0};
|
||||||
tinet_ntoa(ipbuf, ipv4);
|
tinet_ntoa(ipbuf, ipv4);
|
||||||
raftId->addr = SYNC_ADDR(pInfo);
|
raftId->addr = SYNC_ADDR(pInfo);
|
||||||
raftId->vgId = vgId;
|
raftId->vgId = vgId;
|
||||||
|
|
|
@ -223,7 +223,7 @@ static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port,
|
||||||
tError("http-report failed to resolving domain names %s, reason: %s", server, tstrerror(code));
|
tError("http-report failed to resolving domain names %s, reason: %s", server, tstrerror(code));
|
||||||
return TSDB_CODE_RPC_FQDN_ERROR;
|
return TSDB_CODE_RPC_FQDN_ERROR;
|
||||||
}
|
}
|
||||||
char buf[256] = {0};
|
char buf[TD_IP_LEN] = {0};
|
||||||
tinet_ntoa(buf, ip);
|
tinet_ntoa(buf, ip);
|
||||||
int ret = uv_ip4_addr(buf, port, dest);
|
int ret = uv_ip4_addr(buf, port, dest);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|
|
@ -1790,7 +1790,7 @@ static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn) {
|
||||||
size_t len = strlen(fqdn);
|
size_t len = strlen(fqdn);
|
||||||
uint32_t* v = taosHashGet(cache, fqdn, len);
|
uint32_t* v = taosHashGet(cache, fqdn, len);
|
||||||
if (addr != *v) {
|
if (addr != *v) {
|
||||||
char old[64] = {0}, new[64] = {0};
|
char old[TD_IP_LEN] = {0}, new[TD_IP_LEN] = {0};
|
||||||
tinet_ntoa(old, *v);
|
tinet_ntoa(old, *v);
|
||||||
tinet_ntoa(new, addr);
|
tinet_ntoa(new, addr);
|
||||||
tWarn("update ip of fqdn:%s, old: %s, new: %s", fqdn, old, new);
|
tWarn("update ip of fqdn:%s, old: %s, new: %s", fqdn, old, new);
|
||||||
|
|
|
@ -151,7 +151,7 @@ int32_t taosMulMkDir(const char *dirname) {
|
||||||
}
|
}
|
||||||
if (temp[1] == ':') pos += 3;
|
if (temp[1] == ':') pos += 3;
|
||||||
#else
|
#else
|
||||||
(void)strcpy(temp, dirname);
|
tstrncpy(temp, dirname, sizeof(temp));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (taosDirExist(temp)) return code;
|
if (taosDirExist(temp)) return code;
|
||||||
|
@ -216,7 +216,7 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
||||||
}
|
}
|
||||||
if (temp[1] == ':') pos += 3;
|
if (temp[1] == ':') pos += 3;
|
||||||
#else
|
#else
|
||||||
(void)strcpy(temp, dirname);
|
tstrncpy(temp, dirname, sizeof(temp));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (taosDirExist(temp)) {
|
if (taosDirExist(temp)) {
|
||||||
|
@ -341,7 +341,7 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
|
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
|
||||||
(void)strncpy(outname, full_path.we_wordv[0], maxlen);
|
tstrncpy(outname, full_path.we_wordv[0], maxlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
wordfree(&full_path);
|
wordfree(&full_path);
|
||||||
|
@ -358,9 +358,9 @@ int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
|
||||||
#endif
|
#endif
|
||||||
if (strlen(tmp) < maxlen) {
|
if (strlen(tmp) < maxlen) {
|
||||||
if (realPath == NULL) {
|
if (realPath == NULL) {
|
||||||
(void)strncpy(dirname, tmp, maxlen);
|
tstrncpy(dirname, tmp, maxlen);
|
||||||
} else {
|
} else {
|
||||||
(void)strncpy(realPath, tmp, maxlen);
|
tstrncpy(realPath, tmp, maxlen);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -440,8 +440,7 @@ TdDirPtr taosOpenDir(const char *dirname) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(szFind, dirname);
|
snprintf(szFind, sizeof(szFind), "%s%s", dirname, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录
|
||||||
strcat(szFind, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录
|
|
||||||
|
|
||||||
pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
|
pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
|
||||||
if (INVALID_HANDLE_VALUE == pDir->hFind) {
|
if (INVALID_HANDLE_VALUE == pDir->hFind) {
|
||||||
|
@ -560,6 +559,6 @@ void taosGetCwd(char *buf, int32_t len) {
|
||||||
char *unused __attribute__((unused));
|
char *unused __attribute__((unused));
|
||||||
unused = getcwd(buf, len - 1);
|
unused = getcwd(buf, len - 1);
|
||||||
#else
|
#else
|
||||||
strncpy(buf, "not implemented on windows", len - 1);
|
tstrncpy(buf, "not implemented on windows", len);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,21 +77,21 @@ int32_t osDefaultInit() {
|
||||||
tmpDir = getenv("temp");
|
tmpDir = getenv("temp");
|
||||||
}
|
}
|
||||||
if (tmpDir != NULL) {
|
if (tmpDir != NULL) {
|
||||||
(void)strcpy(tsTempDir, tmpDir);
|
tstrncpy(tsTempDir, tmpDir, sizeof(tsTempDir));
|
||||||
}
|
}
|
||||||
(void)strcpy(tsOsName, "Windows");
|
tstrncpy(tsOsName, "Windows", sizeof(tsOsName));
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
(void)strcpy(tsOsName, "Darwin");
|
tstrncpy(tsOsName, "Darwin", sizeof(tsOsName));
|
||||||
#else
|
#else
|
||||||
(void)strcpy(tsOsName, "Linux");
|
tstrncpy(tsOsName, "Linux", sizeof(tsOsName));
|
||||||
#endif
|
#endif
|
||||||
if (configDir[0] == 0) {
|
if (configDir[0] == 0) {
|
||||||
(void)strcpy(configDir, TD_CFG_DIR_PATH);
|
tstrncpy(configDir, TD_CFG_DIR_PATH, sizeof(configDir));
|
||||||
}
|
}
|
||||||
(void)strcpy(tsDataDir, TD_DATA_DIR_PATH);
|
tstrncpy(tsDataDir, TD_DATA_DIR_PATH, sizeof(tsDataDir));
|
||||||
(void)strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
tstrncpy(tsLogDir, TD_LOG_DIR_PATH, sizeof(tsLogDir));
|
||||||
if(strlen(tsTempDir) == 0){
|
if (strlen(tsTempDir) == 0){
|
||||||
(void)strcpy(tsTempDir, TD_TMP_DIR_PATH);
|
tstrncpy(tsTempDir, TD_TMP_DIR_PATH, sizeof(tsTempDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -91,11 +91,7 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha
|
||||||
tmpPath[len++] = '\\';
|
tmpPath[len++] = '\\';
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(tmpPath + len, TD_TMP_FILE_PREFIX);
|
snprintf(tmpPath + len, sizeof(tmpPath) - len, "%s%s%s", TD_TMP_FILE_PREFIX, fileNamePrefix, "-%d-%s");
|
||||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
|
||||||
strcat(tmpPath, fileNamePrefix);
|
|
||||||
strcat(tmpPath, "-%d-%s");
|
|
||||||
}
|
|
||||||
|
|
||||||
char rand[8] = {0};
|
char rand[8] = {0};
|
||||||
taosRandStr(rand, tListLen(rand) - 1);
|
taosRandStr(rand, tListLen(rand) - 1);
|
||||||
|
@ -112,15 +108,11 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha
|
||||||
tmpPath[len++] = '/';
|
tmpPath[len++] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)strcpy(tmpPath + len, TD_TMP_FILE_PREFIX);
|
snprintf(tmpPath + len, sizeof(tmpPath) - len, "%s%s%s", TD_TMP_FILE_PREFIX, fileNamePrefix, "-%d-%s");
|
||||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
|
||||||
(void)strcat(tmpPath, fileNamePrefix);
|
|
||||||
(void)strcat(tmpPath, "-%d-%s");
|
|
||||||
}
|
|
||||||
|
|
||||||
char rand[32] = {0};
|
char rand[32] = {0};
|
||||||
|
|
||||||
(void)sprintf(rand, "%" PRIu64, atomic_add_fetch_64(&seqId, 1));
|
(void)snprintf(rand, sizeof(rand), "%" PRIu64, atomic_add_fetch_64(&seqId, 1));
|
||||||
|
|
||||||
(void)snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
|
(void)snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
||||||
if (locale != NULL) {
|
if (locale != NULL) {
|
||||||
tstrncpy(outLocale, locale, TD_LOCALE_LEN);
|
tstrncpy(outLocale, locale, TD_LOCALE_LEN);
|
||||||
}
|
}
|
||||||
strcpy(outCharset, "UTF-8");
|
tstrncpy(outCharset, "UTF-8", TD_CHARSET_LEN);
|
||||||
|
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
/*
|
/*
|
||||||
|
@ -123,7 +123,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
||||||
locale = setlocale(LC_CTYPE, "");
|
locale = setlocale(LC_CTYPE, "");
|
||||||
if (locale == NULL) {
|
if (locale == NULL) {
|
||||||
// printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno));
|
// 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");
|
tstrncpy(outLocale, "en_US.UTF-8", TD_LOCALE_LEN);
|
||||||
} else {
|
} else {
|
||||||
tstrncpy(outLocale, locale, TD_LOCALE_LEN);
|
tstrncpy(outLocale, locale, TD_LOCALE_LEN);
|
||||||
// printf("locale not configured, set to system default:%s", outLocale);
|
// printf("locale not configured, set to system default:%s", outLocale);
|
||||||
|
@ -137,7 +137,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
||||||
char *revisedCharset = taosCharsetReplace(str);
|
char *revisedCharset = taosCharsetReplace(str);
|
||||||
|
|
||||||
if (NULL == revisedCharset) {
|
if (NULL == revisedCharset) {
|
||||||
(void)strcpy(outCharset, "UTF-8");
|
tstrncpy(outCharset, "UTF-8", TD_CHARSET_LEN);
|
||||||
} else {
|
} else {
|
||||||
tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN);
|
tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN);
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
||||||
}
|
}
|
||||||
// printf("charset not configured, set to system default:%s", outCharset);
|
// printf("charset not configured, set to system default:%s", outCharset);
|
||||||
} else {
|
} else {
|
||||||
strcpy(outCharset, "UTF-8");
|
tstrncpy(outCharset, "UTF-8", TD_CHARSET_LEN);
|
||||||
// printf("can't get locale and charset from system, set it to UTF-8");
|
// printf("can't get locale and charset from system, set it to UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
||||||
locale = setlocale(LC_CTYPE, "");
|
locale = setlocale(LC_CTYPE, "");
|
||||||
if (locale == NULL) {
|
if (locale == NULL) {
|
||||||
// printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno));
|
// printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno));
|
||||||
(void)strcpy(outLocale, "en_US.UTF-8");
|
tstrncpy(outLocale, "en_US.UTF-8", TD_LOCALE_LEN);
|
||||||
} else {
|
} else {
|
||||||
tstrncpy(outLocale, locale, TD_LOCALE_LEN);
|
tstrncpy(outLocale, locale, TD_LOCALE_LEN);
|
||||||
//printf("locale not configured, set to system default:%s\n", outLocale);
|
//printf("locale not configured, set to system default:%s\n", outLocale);
|
||||||
|
@ -186,15 +186,15 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
||||||
|
|
||||||
char *revisedCharset = taosCharsetReplace(str);
|
char *revisedCharset = taosCharsetReplace(str);
|
||||||
if (NULL == revisedCharset) {
|
if (NULL == revisedCharset) {
|
||||||
(void)strcpy(outCharset, "UTF-8");
|
tstrncpy(outCharset, "UTF-8", TD_CHARSET_LEN);
|
||||||
} else {
|
} else {
|
||||||
tstrncpy(outCharset, revisedCharset, TD_LOCALE_LEN);
|
tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN);
|
||||||
|
|
||||||
taosMemoryFree(revisedCharset);
|
taosMemoryFree(revisedCharset);
|
||||||
}
|
}
|
||||||
// printf("charset not configured, set to system default:%s", outCharset);
|
// printf("charset not configured, set to system default:%s", outCharset);
|
||||||
} else {
|
} else {
|
||||||
(void)strcpy(outCharset, "UTF-8");
|
tstrncpy(outCharset, "UTF-8", TD_CHARSET_LEN);
|
||||||
// printf("can't get locale and charset from system, set it to UTF-8");
|
// printf("can't get locale and charset from system, set it to UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,8 +332,8 @@ int32_t taosGetFqdn(char *fqdn) {
|
||||||
// thus, we choose AF_INET (ipv4 for the moment) to make getaddrinfo return
|
// thus, we choose AF_INET (ipv4 for the moment) to make getaddrinfo return
|
||||||
// immediately
|
// immediately
|
||||||
// hints.ai_family = AF_INET;
|
// hints.ai_family = AF_INET;
|
||||||
strcpy(fqdn, hostname);
|
tstrncpy(fqdn, hostname, TD_FQDN_LEN);
|
||||||
strcpy(fqdn + strlen(hostname), ".local");
|
tstrncpy(fqdn + strlen(hostname), ".local", TD_FQDN_LEN - strlen(hostname));
|
||||||
#else // linux
|
#else // linux
|
||||||
|
|
||||||
#endif // linux
|
#endif // linux
|
||||||
|
@ -361,7 +361,7 @@ int32_t taosGetFqdn(char *fqdn) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)strcpy(fqdn, result->ai_canonname);
|
tstrncpy(fqdn, result->ai_canonname, TD_FQDN_LEN);
|
||||||
|
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ int32_t taosGetFqdn(char *fqdn) {
|
||||||
// fprintf(stderr, "failed to get fqdn, code:%d, hostname:%s, reason:%s\n", ret, hostname, gai_strerror(ret));
|
// fprintf(stderr, "failed to get fqdn, code:%d, hostname:%s, reason:%s\n", ret, hostname, gai_strerror(ret));
|
||||||
return TAOS_SYSTEM_WINSOCKET_ERROR(WSAGetLastError());
|
return TAOS_SYSTEM_WINSOCKET_ERROR(WSAGetLastError());
|
||||||
}
|
}
|
||||||
strcpy(fqdn, result->ai_canonname);
|
tstrncpy(fqdn, result->ai_canonname, TD_FQDN_LEN);
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -384,7 +384,7 @@ int32_t taosGetFqdn(char *fqdn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tinet_ntoa(char *ipstr, uint32_t ip) {
|
void tinet_ntoa(char *ipstr, uint32_t ip) {
|
||||||
(void)sprintf(ipstr, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24);
|
(void)snprintf(ipstr, TD_IP_LEN, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosIgnSIGPIPE() {
|
int32_t taosIgnSIGPIPE() {
|
||||||
|
|
|
@ -71,7 +71,7 @@ char *taosStrndup(const char *s, int size) {
|
||||||
if (l > size) l = size;
|
if (l > size) l = size;
|
||||||
s2 = malloc(l + 1);
|
s2 = malloc(l + 1);
|
||||||
if (s2) {
|
if (s2) {
|
||||||
strncpy(s2, s, l);
|
tstrncpy(s2, s, l + 1);
|
||||||
s2[l] = '\0';
|
s2[l] = '\0';
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -442,14 +442,14 @@ int32_t taosUcs4len(TdUcs4 *ucs4) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// dst buffer size should be at least 2*len + 1
|
// dst buffer size should be at least 2*len + 1
|
||||||
int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len) {
|
int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len, int32_t bufSize) {
|
||||||
if (!dst) {
|
if (!dst) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < len; ++i) {
|
for (int32_t i = 0; i < len; ++i) {
|
||||||
(void)sprintf(dst + i * 2, "%02x", src[i]);
|
(void)snprintf(dst + i * 2, bufSize - i * 2, "%02x", src[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -389,10 +389,10 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t
|
||||||
}
|
}
|
||||||
if (major >= 20) {
|
if (major >= 20) {
|
||||||
major -= 9; // macOS 11 and newer
|
major -= 9; // macOS 11 and newer
|
||||||
sprintf(releaseName, "macOS %u.%u", major, minor);
|
snprintf(releaseName, maxLen, "macOS %u.%u", major, minor);
|
||||||
} else {
|
} else {
|
||||||
major -= 4; // macOS 10.1.1 and newer
|
major -= 4; // macOS 10.1.1 and newer
|
||||||
sprintf(releaseName, "macOS 10.%d.%d", major, minor);
|
snprintf(releaseName, maxLen, "macOS 10.%d.%d", major, minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -474,7 +474,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
if (taosGetsCmd(pCmd, sizeof(buf) - 1, buf) > 0) {
|
if (taosGetsCmd(pCmd, sizeof(buf) - 1, buf) > 0) {
|
||||||
code = 0;
|
code = 0;
|
||||||
done |= 2;
|
done |= 2;
|
||||||
*numOfCores = atof(buf);
|
*numOfCores = taosStr2Float(buf, NULL);
|
||||||
}
|
}
|
||||||
taosCloseCmd(&pCmd);
|
taosCloseCmd(&pCmd);
|
||||||
|
|
||||||
|
@ -498,7 +498,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
done |= 1;
|
done |= 1;
|
||||||
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
|
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
|
||||||
const char *v = strchr(line, ':') + 2;
|
const char *v = strchr(line, ':') + 2;
|
||||||
*numOfCores = atof(v);
|
*numOfCores = taosStr2Float(v, NULL);
|
||||||
done |= 2;
|
done |= 2;
|
||||||
}
|
}
|
||||||
if (strncmp(line, "processor", 9) == 0) coreCount += 1;
|
if (strncmp(line, "processor", 9) == 0) coreCount += 1;
|
||||||
|
@ -1095,7 +1095,7 @@ char *taosGetCmdlineByPID(int pid) {
|
||||||
return cmdline;
|
return cmdline;
|
||||||
#else
|
#else
|
||||||
static char cmdline[1024];
|
static char cmdline[1024];
|
||||||
(void)sprintf(cmdline, "/proc/%d/cmdline", pid);
|
(void)snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid);
|
||||||
|
|
||||||
// int fd = open(cmdline, O_RDONLY);
|
// int fd = open(cmdline, O_RDONLY);
|
||||||
TdFilePtr pFile = taosOpenFile(cmdline, TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile(cmdline, TD_FILE_READ);
|
||||||
|
|
|
@ -474,22 +474,15 @@ time_t taosMktime(struct tm *timep) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
|
struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf, int32_t bufSize) {
|
||||||
struct tm *res = NULL;
|
struct tm *res = NULL;
|
||||||
if (timep == NULL) {
|
if (timep == NULL || result == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (result == NULL) {
|
|
||||||
res = localtime(timep);
|
|
||||||
if (res == NULL && buf != NULL) {
|
|
||||||
(void)sprintf(buf, "NaN");
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (*timep < -2208988800LL) {
|
if (*timep < -2208988800LL) {
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
sprintf(buf, "NaN");
|
snprintf(buf, bufSize, "NaN");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (*timep < 0) {
|
} else if (*timep < 0) {
|
||||||
|
@ -501,7 +494,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
|
||||||
time_t tt = 0;
|
time_t tt = 0;
|
||||||
if (localtime_s(&tm1, &tt) != 0) {
|
if (localtime_s(&tm1, &tt) != 0) {
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
sprintf(buf, "NaN");
|
snprintf(buf, bufSize, "NaN");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -532,7 +525,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
|
||||||
} else {
|
} else {
|
||||||
if (localtime_s(result, timep) != 0) {
|
if (localtime_s(result, timep) != 0) {
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
sprintf(buf, "NaN");
|
snprintf(buf, bufSize, "NaN");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -540,7 +533,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
|
||||||
#else
|
#else
|
||||||
res = localtime_r(timep, result);
|
res = localtime_r(timep, result);
|
||||||
if (res == NULL && buf != NULL) {
|
if (res == NULL && buf != NULL) {
|
||||||
(void)sprintf(buf, "NaN");
|
(void)snprintf(buf, bufSize, "NaN");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
|
@ -559,7 +552,7 @@ static int isLeapYear(time_t year) {
|
||||||
|
|
||||||
struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst) {
|
struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst) {
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
return localtime(timep);
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (*timep < 0) {
|
if (*timep < 0) {
|
||||||
|
|
|
@ -783,15 +783,15 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
|
||||||
memset(winStr, 0, sizeof(winStr));
|
memset(winStr, 0, sizeof(winStr));
|
||||||
for (size_t i = 0; i < 554; i++) {
|
for (size_t i = 0; i < 554; i++) {
|
||||||
if (strcmp(tz_win[i][0], buf) == 0) {
|
if (strcmp(tz_win[i][0], buf) == 0) {
|
||||||
char keyPath[100];
|
char keyPath[256];
|
||||||
char keyValue[100];
|
char keyValue[100];
|
||||||
DWORD keyValueSize = sizeof(keyValue);
|
DWORD keyValueSize = sizeof(keyValue);
|
||||||
sprintf(keyPath, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s", tz_win[i][1]);
|
snprintf(keyPath, sizeof(keyPath), "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s", tz_win[i][1]);
|
||||||
RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&keyValue, &keyValueSize);
|
RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&keyValue, &keyValueSize);
|
||||||
if (keyValueSize > 0) {
|
if (keyValueSize > 0) {
|
||||||
keyValue[4] = (keyValue[4] == '+' ? '-' : '+');
|
keyValue[4] = (keyValue[4] == '+' ? '-' : '+');
|
||||||
keyValue[10] = 0;
|
keyValue[10] = 0;
|
||||||
sprintf(winStr, "TZ=%s:00", &(keyValue[1]));
|
snprintf(winStr, sizeof(winStr), "TZ=%s:00", &(keyValue[1]));
|
||||||
*tsTimezone = -taosStr2Int32(&keyValue[4], NULL, 10);
|
*tsTimezone = -taosStr2Int32(&keyValue[4], NULL, 10);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -805,7 +805,7 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
|
||||||
char *ppp = strchr(inTimezoneStr, ',');
|
char *ppp = strchr(inTimezoneStr, ',');
|
||||||
int indexStr;
|
int indexStr;
|
||||||
if (pp == NULL || ppp == NULL) {
|
if (pp == NULL || ppp == NULL) {
|
||||||
indexStr = sprintf(winStr, "TZ=UTC");
|
indexStr = snprintf(winStr, sizeof(winStr), "TZ=UTC");
|
||||||
} else {
|
} else {
|
||||||
memcpy(winStr, "TZ=", 3);
|
memcpy(winStr, "TZ=", 3);
|
||||||
pp++;
|
pp++;
|
||||||
|
@ -814,7 +814,7 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
|
||||||
}
|
}
|
||||||
char to[5];
|
char to[5];
|
||||||
parseTimeStr(p, to);
|
parseTimeStr(p, to);
|
||||||
sprintf(&winStr[indexStr], "%c%c%c:%c%c:00", (to[0] == '+' ? '+' : '-'), to[1], to[2], to[3], to[4]);
|
snprintf(&winStr[indexStr], sizeof(winStr) - indexStr, "%c%c%c:%c%c:00", (to[0] == '+' ? '+' : '-'), to[1], to[2], to[3], to[4]);
|
||||||
*tsTimezone = -taosStr2Int32(p, NULL, 10);
|
*tsTimezone = -taosStr2Int32(p, NULL, 10);
|
||||||
} else {
|
} else {
|
||||||
*tsTimezone = 0;
|
*tsTimezone = 0;
|
||||||
|
@ -823,7 +823,7 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
|
||||||
_putenv(winStr);
|
_putenv(winStr);
|
||||||
_tzset();
|
_tzset();
|
||||||
if (outTimezoneStr != inTimezoneStr) {
|
if (outTimezoneStr != inTimezoneStr) {
|
||||||
strcpy(outTimezoneStr, inTimezoneStr);
|
tstrncpy(outTimezoneStr, inTimezoneStr, TD_TIMEZONE_LEN);
|
||||||
}
|
}
|
||||||
*outDaylight = 0;
|
*outDaylight = 0;
|
||||||
|
|
||||||
|
@ -839,7 +839,7 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
|
||||||
*tsTimezone = tz;
|
*tsTimezone = tz;
|
||||||
tz += isdst_now;
|
tz += isdst_now;
|
||||||
|
|
||||||
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[isdst_now], tz >= 0 ? "+" : "-", abs(tz));
|
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[isdst_now], tz >= 0 ? "+" : "-", abs(tz));
|
||||||
*outDaylight = isdst_now;
|
*outDaylight = isdst_now;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -853,7 +853,7 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
|
||||||
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
||||||
*tsTimezone = tz;
|
*tsTimezone = tz;
|
||||||
tz += isdst_now;
|
tz += isdst_now;
|
||||||
(void)sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[isdst_now], tz >= 0 ? "+" : "-", abs(tz));
|
(void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[isdst_now], tz >= 0 ? "+" : "-", abs(tz));
|
||||||
*outDaylight = isdst_now;
|
*outDaylight = isdst_now;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -872,21 +872,21 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone)
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
return TAOS_SYSTEM_WINAPI_ERROR(result);
|
return TAOS_SYSTEM_WINAPI_ERROR(result);
|
||||||
}
|
}
|
||||||
strcpy(outTimezoneStr, "not configured");
|
tstrncpy(outTimezoneStr, "not configured", TD_TIMEZONE_LEN);
|
||||||
*tsTimezone = 0;
|
*tsTimezone = 0;
|
||||||
if (bufferSize > 0) {
|
if (bufferSize > 0) {
|
||||||
for (size_t i = 0; i < 139; i++) {
|
for (size_t i = 0; i < 139; i++) {
|
||||||
if (strcmp(win_tz[i][0], value) == 0) {
|
if (strcmp(win_tz[i][0], value) == 0) {
|
||||||
strcpy(outTimezoneStr, win_tz[i][1]);
|
tstrncpy(outTimezoneStr, win_tz[i][1], TD_TIMEZONE_LEN);
|
||||||
bufferSize = sizeof(value);
|
bufferSize = sizeof(value);
|
||||||
sprintf(keyPath, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s", value);
|
snprintf(keyPath, sizeof(keyPath), "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s", value);
|
||||||
result = RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
result = RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
return TAOS_SYSTEM_WINAPI_ERROR(result);
|
return TAOS_SYSTEM_WINAPI_ERROR(result);
|
||||||
}
|
}
|
||||||
if (bufferSize > 0) {
|
if (bufferSize > 0) {
|
||||||
// value[4] = (value[4] == '+' ? '-' : '+');
|
// value[4] = (value[4] == '+' ? '-' : '+');
|
||||||
sprintf(outTimezoneStr, "%s (UTC, %c%c%c%c%c)", outTimezoneStr, value[4], value[5], value[6], value[8],
|
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (UTC, %c%c%c%c%c)", outTimezoneStr, value[4], value[5], value[6], value[8],
|
||||||
value[9]);
|
value[9]);
|
||||||
*tsTimezone = taosStr2Int32(&value[4], NULL, 10);
|
*tsTimezone = taosStr2Int32(&value[4], NULL, 10);
|
||||||
}
|
}
|
||||||
|
@ -926,7 +926,7 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone)
|
||||||
*/
|
*/
|
||||||
time_t tx1 = taosGetTimestampSec();
|
time_t tx1 = taosGetTimestampSec();
|
||||||
struct tm tm1;
|
struct tm tm1;
|
||||||
if (taosLocalTime(&tx1, &tm1, NULL) == NULL) {
|
if (taosLocalTime(&tx1, &tm1, NULL, 0) == NULL) {
|
||||||
return TSDB_CODE_TIME_ERROR;
|
return TSDB_CODE_TIME_ERROR;
|
||||||
}
|
}
|
||||||
daylight = tm1.tm_isdst;
|
daylight = tm1.tm_isdst;
|
||||||
|
@ -956,7 +956,7 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone)
|
||||||
*/
|
*/
|
||||||
time_t tx1 = taosGetTimestampSec();
|
time_t tx1 = taosGetTimestampSec();
|
||||||
struct tm tm1;
|
struct tm tm1;
|
||||||
if(taosLocalTime(&tx1, &tm1, NULL) == NULL) {
|
if(taosLocalTime(&tx1, &tm1, NULL, 0) == NULL) {
|
||||||
return TSDB_CODE_TIME_ERROR;
|
return TSDB_CODE_TIME_ERROR;
|
||||||
}
|
}
|
||||||
/* load time zone string from /etc/timezone */
|
/* load time zone string from /etc/timezone */
|
||||||
|
@ -1037,7 +1037,7 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone)
|
||||||
*/
|
*/
|
||||||
time_t tx1 = taosGetTimestampSec();
|
time_t tx1 = taosGetTimestampSec();
|
||||||
struct tm tm1;
|
struct tm tm1;
|
||||||
if(taosLocalTime(&tx1, &tm1, NULL) == NULL) {
|
if(taosLocalTime(&tx1, &tm1, NULL, 0) == NULL) {
|
||||||
return TSDB_CODE_TIME_ERROR;
|
return TSDB_CODE_TIME_ERROR;
|
||||||
}
|
}
|
||||||
isdst_now = tm1.tm_isdst;
|
isdst_now = tm1.tm_isdst;
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
TEST(osTest, osFQDNSuccess) {
|
TEST(osTest, osFQDNSuccess) {
|
||||||
char fqdn[1024];
|
char fqdn[TD_FQDN_LEN];
|
||||||
char ipString[INET_ADDRSTRLEN];
|
char ipString[INET_ADDRSTRLEN];
|
||||||
int code = taosGetFqdn(fqdn);
|
int code = taosGetFqdn(fqdn);
|
||||||
uint32_t ipv4 = 0;
|
uint32_t ipv4 = 0;
|
||||||
|
|
|
@ -31,20 +31,20 @@
|
||||||
|
|
||||||
TEST(osTimeTests, taosLocalTimeNolock) {
|
TEST(osTimeTests, taosLocalTimeNolock) {
|
||||||
time_t currentTime;
|
time_t currentTime;
|
||||||
// Test when result is NULL
|
|
||||||
struct tm* result = taosLocalTimeNolock(NULL, ¤tTime, 0);
|
|
||||||
// Test when result is not NULL
|
// Test when result is not NULL
|
||||||
struct tm expectedTime;
|
struct tm expectedTime;
|
||||||
result = taosLocalTimeNolock(&expectedTime, ¤tTime, 1);
|
struct tm* result = taosLocalTimeNolock(&expectedTime, ¤tTime, 1);
|
||||||
EXPECT_EQ(expectedTime.tm_year, result->tm_year);
|
if (result) {
|
||||||
EXPECT_EQ(expectedTime.tm_mon, result->tm_mon);
|
EXPECT_EQ(expectedTime.tm_year, result->tm_year);
|
||||||
EXPECT_EQ(expectedTime.tm_mday, result->tm_mday);
|
EXPECT_EQ(expectedTime.tm_mon, result->tm_mon);
|
||||||
EXPECT_EQ(expectedTime.tm_hour, result->tm_hour);
|
EXPECT_EQ(expectedTime.tm_mday, result->tm_mday);
|
||||||
EXPECT_EQ(expectedTime.tm_min, result->tm_min);
|
EXPECT_EQ(expectedTime.tm_hour, result->tm_hour);
|
||||||
EXPECT_EQ(expectedTime.tm_sec, result->tm_sec);
|
EXPECT_EQ(expectedTime.tm_min, result->tm_min);
|
||||||
EXPECT_EQ(expectedTime.tm_wday, result->tm_wday);
|
EXPECT_EQ(expectedTime.tm_sec, result->tm_sec);
|
||||||
EXPECT_EQ(expectedTime.tm_yday, result->tm_yday);
|
EXPECT_EQ(expectedTime.tm_wday, result->tm_wday);
|
||||||
EXPECT_EQ(expectedTime.tm_isdst, result->tm_isdst);
|
EXPECT_EQ(expectedTime.tm_yday, result->tm_yday);
|
||||||
|
EXPECT_EQ(expectedTime.tm_isdst, result->tm_isdst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ TEST(osTimeTests, taosLocalTime) {
|
||||||
// Test 1: Test when both timep and result are not NULL
|
// Test 1: Test when both timep and result are not NULL
|
||||||
time_t timep = 1617531000; // 2021-04-04 18:10:00
|
time_t timep = 1617531000; // 2021-04-04 18:10:00
|
||||||
struct tm result;
|
struct tm result;
|
||||||
struct tm* local_time = taosLocalTime(&timep, &result, NULL);
|
struct tm* local_time = taosLocalTime(&timep, &result, NULL, 0);
|
||||||
ASSERT_NE(local_time, nullptr);
|
ASSERT_NE(local_time, nullptr);
|
||||||
ASSERT_EQ(local_time->tm_year, 121);
|
ASSERT_EQ(local_time->tm_year, 121);
|
||||||
ASSERT_EQ(local_time->tm_mon, 3);
|
ASSERT_EQ(local_time->tm_mon, 3);
|
||||||
|
@ -62,20 +62,13 @@ TEST(osTimeTests, taosLocalTime) {
|
||||||
ASSERT_EQ(local_time->tm_sec, 00);
|
ASSERT_EQ(local_time->tm_sec, 00);
|
||||||
|
|
||||||
// Test 2: Test when timep is NULL
|
// Test 2: Test when timep is NULL
|
||||||
local_time = taosLocalTime(NULL, &result, NULL);
|
local_time = taosLocalTime(NULL, &result, NULL, 0);
|
||||||
ASSERT_EQ(local_time, nullptr);
|
ASSERT_EQ(local_time, nullptr);
|
||||||
|
|
||||||
// Test 3: Test when result is NULL
|
|
||||||
local_time = taosLocalTime(&timep, NULL, NULL);
|
|
||||||
ASSERT_NE(local_time, nullptr);
|
|
||||||
ASSERT_EQ(local_time->tm_year, 121);
|
|
||||||
ASSERT_EQ(local_time->tm_mon, 3);
|
|
||||||
ASSERT_EQ(local_time->tm_mday, 4);
|
|
||||||
|
|
||||||
// Test 4: Test when timep is negative on Windows
|
// Test 4: Test when timep is negative on Windows
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
time_t pos_timep = 1609459200; // 2021-01-01 08:00:00
|
time_t pos_timep = 1609459200; // 2021-01-01 08:00:00
|
||||||
local_time = taosLocalTime(&pos_timep, &result, NULL);
|
local_time = taosLocalTime(&pos_timep, &result, NULL, 0);
|
||||||
ASSERT_NE(local_time, nullptr);
|
ASSERT_NE(local_time, nullptr);
|
||||||
ASSERT_EQ(local_time->tm_year, 121);
|
ASSERT_EQ(local_time->tm_year, 121);
|
||||||
ASSERT_EQ(local_time->tm_mon, 0);
|
ASSERT_EQ(local_time->tm_mon, 0);
|
||||||
|
@ -85,7 +78,7 @@ TEST(osTimeTests, taosLocalTime) {
|
||||||
ASSERT_EQ(local_time->tm_sec, 0);
|
ASSERT_EQ(local_time->tm_sec, 0);
|
||||||
|
|
||||||
time_t neg_timep = -1617531000; // 1918-09-29 21:50:00
|
time_t neg_timep = -1617531000; // 1918-09-29 21:50:00
|
||||||
local_time = taosLocalTime(&neg_timep, &result, NULL);
|
local_time = taosLocalTime(&neg_timep, &result, NULL, 0);
|
||||||
ASSERT_NE(local_time, nullptr);
|
ASSERT_NE(local_time, nullptr);
|
||||||
ASSERT_EQ(local_time->tm_year, 18);
|
ASSERT_EQ(local_time->tm_year, 18);
|
||||||
ASSERT_EQ(local_time->tm_mon, 8);
|
ASSERT_EQ(local_time->tm_mon, 8);
|
||||||
|
@ -95,7 +88,7 @@ TEST(osTimeTests, taosLocalTime) {
|
||||||
ASSERT_EQ(local_time->tm_sec, 0);
|
ASSERT_EQ(local_time->tm_sec, 0);
|
||||||
|
|
||||||
time_t neg_timep2 = -315619200; // 1960-01-01 08:00:00
|
time_t neg_timep2 = -315619200; // 1960-01-01 08:00:00
|
||||||
local_time = taosLocalTime(&neg_timep2, &result, NULL);
|
local_time = taosLocalTime(&neg_timep2, &result, NULL, 0);
|
||||||
ASSERT_NE(local_time, nullptr);
|
ASSERT_NE(local_time, nullptr);
|
||||||
ASSERT_EQ(local_time->tm_year, 60);
|
ASSERT_EQ(local_time->tm_year, 60);
|
||||||
ASSERT_EQ(local_time->tm_mon, 0);
|
ASSERT_EQ(local_time->tm_mon, 0);
|
||||||
|
@ -105,7 +98,7 @@ TEST(osTimeTests, taosLocalTime) {
|
||||||
ASSERT_EQ(local_time->tm_sec, 0);
|
ASSERT_EQ(local_time->tm_sec, 0);
|
||||||
|
|
||||||
time_t zero_timep = 0; // 1970-01-01 08:00:00
|
time_t zero_timep = 0; // 1970-01-01 08:00:00
|
||||||
local_time = taosLocalTime(&zero_timep, &result, NULL);
|
local_time = taosLocalTime(&zero_timep, &result, NULL, 0);
|
||||||
ASSERT_NE(local_time, nullptr);
|
ASSERT_NE(local_time, nullptr);
|
||||||
ASSERT_EQ(local_time->tm_year, 70);
|
ASSERT_EQ(local_time->tm_year, 70);
|
||||||
ASSERT_EQ(local_time->tm_mon, 0);
|
ASSERT_EQ(local_time->tm_mon, 0);
|
||||||
|
@ -115,7 +108,7 @@ TEST(osTimeTests, taosLocalTime) {
|
||||||
ASSERT_EQ(local_time->tm_sec, 0);
|
ASSERT_EQ(local_time->tm_sec, 0);
|
||||||
|
|
||||||
time_t neg_timep3 = -78115158887;
|
time_t neg_timep3 = -78115158887;
|
||||||
local_time = taosLocalTime(&neg_timep3, &result, NULL);
|
local_time = taosLocalTime(&neg_timep3, &result, NULL, 0);
|
||||||
ASSERT_EQ(local_time, nullptr);
|
ASSERT_EQ(local_time, nullptr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
|
@ -151,18 +151,18 @@ static int32_t taosStartLog() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getDay(char* buf){
|
static void getDay(char* buf, int32_t bufSize){
|
||||||
time_t t = taosTime(NULL);
|
time_t t = taosTime(NULL);
|
||||||
struct tm tmInfo;
|
struct tm tmInfo;
|
||||||
if (taosLocalTime(&t, &tmInfo, buf) != NULL) {
|
if (taosLocalTime(&t, &tmInfo, buf, bufSize) != NULL) {
|
||||||
TAOS_UNUSED(strftime(buf, LOG_FILE_DAY_LEN, "%Y-%m-%d", &tmInfo));
|
TAOS_UNUSED(strftime(buf, bufSize, "%Y-%m-%d", &tmInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t getTimestampToday() {
|
static int64_t getTimestampToday() {
|
||||||
time_t t = taosTime(NULL);
|
time_t t = taosTime(NULL);
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
if (taosLocalTime(&t, &tm, NULL) == NULL) {
|
if (taosLocalTime(&t, &tm, NULL, 0) == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
tm.tm_hour = 0;
|
tm.tm_hour = 0;
|
||||||
|
@ -198,10 +198,10 @@ int32_t taosInitSlowLog() {
|
||||||
|
|
||||||
getFullPathName(tsLogObj.slowLogName, logFileName);
|
getFullPathName(tsLogObj.slowLogName, logFileName);
|
||||||
|
|
||||||
char name[PATH_MAX + LOG_FILE_DAY_LEN] = {0};
|
char name[PATH_MAX + TD_TIME_STR_LEN] = {0};
|
||||||
char day[LOG_FILE_DAY_LEN] = {0};
|
char day[TD_TIME_STR_LEN] = {0};
|
||||||
getDay(day);
|
getDay(day, sizeof(day));
|
||||||
(void)snprintf(name, PATH_MAX + LOG_FILE_DAY_LEN, "%s.%s", tsLogObj.slowLogName, day);
|
(void)snprintf(name, PATH_MAX + TD_TIME_STR_LEN, "%s.%s", tsLogObj.slowLogName, day);
|
||||||
|
|
||||||
tsLogObj.timestampToday = getTimestampToday();
|
tsLogObj.timestampToday = getTimestampToday();
|
||||||
tsLogObj.slowHandle = taosLogBuffNew(LOG_SLOW_BUF_SIZE);
|
tsLogObj.slowHandle = taosLogBuffNew(LOG_SLOW_BUF_SIZE);
|
||||||
|
@ -430,11 +430,11 @@ static void taosOpenNewSlowLogFile() {
|
||||||
taosWriteLog(tsLogObj.slowHandle);
|
taosWriteLog(tsLogObj.slowHandle);
|
||||||
atomic_store_32(&tsLogObj.slowHandle->lock, 0);
|
atomic_store_32(&tsLogObj.slowHandle->lock, 0);
|
||||||
|
|
||||||
char day[LOG_FILE_DAY_LEN] = {0};
|
char day[TD_TIME_STR_LEN] = {0};
|
||||||
getDay(day);
|
getDay(day, sizeof(day));
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
char name[PATH_MAX + LOG_FILE_DAY_LEN] = {0};
|
char name[PATH_MAX + TD_TIME_STR_LEN] = {0};
|
||||||
(void)snprintf(name, PATH_MAX + LOG_FILE_DAY_LEN, "%s.%s", tsLogObj.slowLogName, day);
|
(void)snprintf(name, PATH_MAX + TD_TIME_STR_LEN, "%s.%s", tsLogObj.slowLogName, day);
|
||||||
pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
uError("open new log file fail! reason:%s, reuse lastlog", strerror(errno));
|
uError("open new log file fail! reason:%s, reuse lastlog", strerror(errno));
|
||||||
|
@ -631,7 +631,7 @@ static inline int32_t taosBuildLogHead(char *buffer, const char *flags) {
|
||||||
|
|
||||||
TAOS_UNUSED(taosGetTimeOfDay(&timeSecs));
|
TAOS_UNUSED(taosGetTimeOfDay(&timeSecs));
|
||||||
time_t curTime = timeSecs.tv_sec;
|
time_t curTime = timeSecs.tv_sec;
|
||||||
ptm = taosLocalTime(&curTime, &Tm, NULL);
|
ptm = taosLocalTime(&curTime, &Tm, NULL, 0);
|
||||||
|
|
||||||
return sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " %s %s", ptm->tm_mon + 1, ptm->tm_mday,
|
return sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " %s %s", ptm->tm_mon + 1, ptm->tm_mday,
|
||||||
ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(),
|
ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(),
|
||||||
|
|
|
@ -44,7 +44,7 @@ static int32_t shellRunSingleCommand(char *command);
|
||||||
static void shellRecordCommandToHistory(char *command);
|
static void shellRecordCommandToHistory(char *command);
|
||||||
static int32_t shellRunCommand(char *command, bool recordHistory);
|
static int32_t shellRunCommand(char *command, bool recordHistory);
|
||||||
static void shellRunSingleCommandImp(char *command);
|
static void shellRunSingleCommandImp(char *command);
|
||||||
static char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision);
|
static char *shellFormatTimestamp(char *buf, int32_t bufSize, int64_t val, int32_t precision);
|
||||||
static int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres);
|
static int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres);
|
||||||
static void shellPrintNChar(const char *str, int32_t length, int32_t width);
|
static void shellPrintNChar(const char *str, int32_t length, int32_t width);
|
||||||
static void shellPrintGeometry(const unsigned char *str, int32_t length, int32_t width);
|
static void shellPrintGeometry(const unsigned char *str, int32_t length, int32_t width);
|
||||||
|
@ -304,7 +304,7 @@ void shellRunSingleCommandImp(char *command) {
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) {
|
char *shellFormatTimestamp(char *buf, int32_t bufSize, int64_t val, int32_t precision) {
|
||||||
if (shell.args.is_raw_time) {
|
if (shell.args.is_raw_time) {
|
||||||
sprintf(buf, "%" PRId64, val);
|
sprintf(buf, "%" PRId64, val);
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -335,7 +335,7 @@ char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tm ptm = {0};
|
struct tm ptm = {0};
|
||||||
if (taosLocalTime(&tt, &ptm, buf) == NULL) {
|
if (taosLocalTime(&tt, &ptm, buf, bufSize) == NULL) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
|
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
|
||||||
|
@ -465,7 +465,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
shellFormatTimestamp(buf, *(int64_t *)val, precision);
|
shellFormatTimestamp(buf, sizeof(buf), *(int64_t *)val, precision);
|
||||||
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
|
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -710,7 +710,7 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
|
||||||
shellPrintGeometry(val, length, width);
|
shellPrintGeometry(val, length, width);
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
shellFormatTimestamp(buf, *(int64_t *)val, precision);
|
shellFormatTimestamp(buf, sizeof(buf), *(int64_t *)val, precision);
|
||||||
printf("%s", buf);
|
printf("%s", buf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -597,7 +597,7 @@ void printParaIntoFile() {
|
||||||
|
|
||||||
time_t tTime = taosGetTimestampSec();
|
time_t tTime = taosGetTimestampSec();
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
taosLocalTime(&tTime, &tm, NULL);
|
taosLocalTime(&tTime, &tm, NULL, 0);
|
||||||
|
|
||||||
taosFprintfFile(pFile, "###################################################################\n");
|
taosFprintfFile(pFile, "###################################################################\n");
|
||||||
taosFprintfFile(pFile, "# configDir: %s\n", configDir);
|
taosFprintfFile(pFile, "# configDir: %s\n", configDir);
|
||||||
|
|
|
@ -166,7 +166,7 @@ static void printHelp() {
|
||||||
char* getCurrentTimeString(char* timeString) {
|
char* getCurrentTimeString(char* timeString) {
|
||||||
time_t tTime = taosGetTimestampSec();
|
time_t tTime = taosGetTimestampSec();
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
taosLocalTime(&tTime, &tm, NULL);
|
taosLocalTime(&tTime, &tm, NULL, 0);
|
||||||
sprintf(timeString, "%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
|
sprintf(timeString, "%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
|
||||||
tm.tm_min, tm.tm_sec);
|
tm.tm_min, tm.tm_sec);
|
||||||
|
|
||||||
|
@ -441,7 +441,7 @@ int32_t saveConsumeContentToTbl(SThreadInfo* pInfo, char* buf) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* shellFormatTimestamp(char* buf, int64_t val, int32_t precision) {
|
static char* shellFormatTimestamp(char* buf, int32_t bufSize, int64_t val, int32_t precision) {
|
||||||
// if (shell.args.is_raw_time) {
|
// if (shell.args.is_raw_time) {
|
||||||
// sprintf(buf, "%" PRId64, val);
|
// sprintf(buf, "%" PRId64, val);
|
||||||
// return buf;
|
// return buf;
|
||||||
|
@ -472,7 +472,7 @@ static char* shellFormatTimestamp(char* buf, int64_t val, int32_t precision) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tm ptm;
|
struct tm ptm;
|
||||||
if (taosLocalTime(&tt, &ptm, buf) == NULL) {
|
if (taosLocalTime(&tt, &ptm, buf, bufSize) == NULL) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
|
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
|
||||||
|
@ -559,7 +559,7 @@ static void shellDumpFieldToFile(TdFilePtr pFile, const char* val, TAOS_FIELD* f
|
||||||
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
|
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
|
||||||
} break;
|
} break;
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
shellFormatTimestamp(buf, *(int64_t*)val, precision);
|
shellFormatTimestamp(buf, sizeof(buf), *(int64_t*)val, precision);
|
||||||
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
|
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -797,7 +797,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
|
||||||
tt = (*(int64_t *)row[i]) / 1000000000;
|
tt = (*(int64_t *)row[i]) / 1000000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosLocalTime(&tt, &tp, timeStr) == NULL) {
|
if (taosLocalTime(&tt, &tp, timeStr, sizeof(timeStr)) == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", &tp);
|
strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", &tp);
|
||||||
|
|
Loading…
Reference in New Issue