diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index d3c8eefbb9c37d85f1cf72a361f5ff72c9bb93d9..fd7d31aa9f198aa14ccec0763d4fedd31e043c09 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -201,7 +201,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { tscPrint("set shellActivityTimer:%d", tsShellActivityTimer); } else { tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, pStr, - tsCfgStatusStr[cfg->cfgStatus], (int32_t *)cfg->ptr); + tsCfgStatusStr[cfg->cfgStatus], *(int32_t *)cfg->ptr); } break; diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 954f2cb8a30b2d4bff75c9580f2e6c9be1f9b909..f04607f6fadf931b836d36fa7dc6fa4998f8bd71 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -727,10 +727,6 @@ void read_history() { char f_history[TSDB_FILENAME_LEN]; get_history_path(f_history); - if (access(f_history, R_OK) == -1) { - return; - } - FILE *f = fopen(f_history, "r"); if (f == NULL) { fprintf(stderr, "Opening file %s\n", f_history); @@ -809,14 +805,6 @@ void source_file(TAOS *con, char *fptr) { return; } - if (access(fname, R_OK) != 0) { - fprintf(stderr, "ERROR: file %s is not readable\n", fptr); - - wordfree(&full_path); - free(cmd); - return; - } - FILE *f = fopen(fname, "r"); if (f == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index f03b46ac470e828bdb62b76d31cea796c83fed81..d96f80ed206a2f5541daf7bbbd0f4036da4ab7b3 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -646,10 +646,9 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp); } - tclose(fd); - remove(".table.tmp"); + close(fd); - return 0; + return remove(".table.tmp"); } void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, SDumpArguments *arguments, FILE *fp) { diff --git a/src/os/linux/src/linuxSysPara.c b/src/os/linux/src/linuxSysPara.c index ca244dcd949cbc2c9819b0b6e36cfb682268e34c..b270eb14cf4c652a531cb0228c949868dc58f7a9 100644 --- a/src/os/linux/src/linuxSysPara.c +++ b/src/os/linux/src/linuxSysPara.c @@ -331,66 +331,7 @@ bool taosGetDisk() { return true; } -static bool taosGetCardName(char *ip, char *name) { - struct ifaddrs *ifaddr, *ifa; - int family, s; - char host[NI_MAXHOST]; - bool ret = false; - - if (getifaddrs(&ifaddr) == -1) { - return false; - } - - /* Walk through linked list, maintaining head pointer so we can free list - * later */ - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) continue; - - family = ifa->ifa_addr->sa_family; - if (family != AF_INET) { - continue; - } - - s = getnameinfo(ifa->ifa_addr, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), host, - NI_MAXHOST, NULL, 0, NI_NUMERICHOST); - if (s != 0) { - break; - } - - if (strcmp(host, "127.0.0.1") == 0) { - continue; - } - - // TODO: the ip not config - // if (strcmp(host, ip) == 0) { - strcpy(name, ifa->ifa_name); - ret = true; - // } - } - - freeifaddrs(ifaddr); - return ret; -} - static bool taosGetCardInfo(int64_t *bytes) { - static char tsPublicCard[1000] = {0}; - static char tsPrivateIp[40]; - - if (tsPublicCard[0] == 0) { - if (!taosGetCardName(tsPrivateIp, tsPublicCard)) { - uError("can't get card name from ip:%s", tsPrivateIp); - return false; - } - int cardNameLen = (int)strlen(tsPublicCard); - for (int i = 0; i < cardNameLen; ++i) { - if (tsPublicCard[i] == ':') { - tsPublicCard[i] = 0; - break; - } - } - // uTrace("card name of public ip:%s is %s", tsPublicIp, tsPublicCard); - } - FILE *fp = fopen(tsSysNetFile, "r"); if (fp == NULL) { uError("open file:%s failed", tsSysNetFile); @@ -403,6 +344,7 @@ static bool taosGetCardInfo(int64_t *bytes) { size_t len; char * line = NULL; + *bytes = 0; while (!feof(fp)) { tfree(line); @@ -411,23 +353,20 @@ static bool taosGetCardInfo(int64_t *bytes) { if (line == NULL) { break; } - if (strstr(line, tsPublicCard) != NULL) { - break; + if (strstr(line, "lo:") != NULL) { + continue; } + + sscanf(line, + "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, + nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &tbytes, &tpackets); + *bytes += (rbytes + tbytes); } - if (line != NULL) { - sscanf(line, "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3, - &nouse4, &nouse5, &nouse6, &tbytes, &tpackets); - *bytes = rbytes + tbytes; - tfree(line); - fclose(fp); - return true; - } else { - uWarn("can't get card:%s info from device:%s", tsPublicCard, tsSysNetFile); - *bytes = 0; - fclose(fp); - return false; - } + + tfree(line); + fclose(fp); + + return true; } bool taosGetBandSpeed(float *bandSpeedKb) { @@ -443,13 +382,15 @@ bool taosGetBandSpeed(float *bandSpeedKb) { if (lastTime == 0 || lastBytes == 0) { lastTime = curTime; lastBytes = curBytes; - return false; + *bandSpeedKb = 0; + return true; } if (lastTime >= curTime || lastBytes > curBytes) { lastTime = curTime; lastBytes = curBytes; - return false; + *bandSpeedKb = 0; + return true; } double totalBytes = (double)(curBytes - lastBytes) / 1024 * 8; // Kb diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index fbe6757ccbcdea09bce8d8feabfae95e2691a549..41209801233c6621c9f5a7d233c7d01718d54ba4 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -22,9 +22,27 @@ #include "taosdef.h" static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest}; -static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL}; +static HttpEncodeMethod gcHeartBeatMethod = { + .startJsonFp = NULL, + .stopJsonFp = gcSendHeartBeatResp, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = NULL, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod gcQueryMethod = { - NULL, gcStopQueryJson, gcBuildQueryJson, NULL, gcInitQueryJson, gcCleanQueryJson, NULL, NULL}; + .startJsonFp = NULL, + .stopJsonFp = gcStopQueryJson, + .buildQueryJsonFp = gcBuildQueryJson, + .buildAffectRowJsonFp = NULL, + .initJsonFp = gcInitQueryJson, + .cleanJsonFp = gcCleanQueryJson, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void gcInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &gcDecodeMethod); } diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index af9ad8e38acdfdf7752bbdf14ea8daf54bcc2152..6ff93b3e8a728d72d33e717991d9a1917e5e3c55 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -87,7 +87,7 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { } if (code < 0) { - if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : code)) { + if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, -code)) { singleCmd->code = code; httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql); diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index a2dc7d06a1a75fd51fa17f910599b67ea6129575..d481a654d89e41ee296645fe32cb5fff38abf521 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -22,11 +22,37 @@ static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest}; static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest}; static HttpEncodeMethod restEncodeSqlTimestampMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlTimestampJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlTimestampJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlLocalTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlLocalTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlLocalTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlUtcTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlUtcTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlUtcTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void restInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &restDecodeMethod); diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index ffb2ccb2f932a715da56364069235cd0b98ea0d3..c6a2230bfb28fb3bffb5d760937423291190a787 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -62,9 +62,16 @@ #define TG_MAX_SORT_TAG_SIZE 20 static HttpDecodeMethod tgDecodeMethod = {"telegraf", tgProcessRquest}; -static HttpEncodeMethod tgQueryMethod = {tgStartQueryJson, tgStopQueryJson, NULL, - tgBuildSqlAffectRowsJson, tgInitQueryJson, tgCleanQueryJson, - tgCheckFinished, tgSetNextCmd}; +static HttpEncodeMethod tgQueryMethod = { + .startJsonFp = tgStartQueryJson, + .stopJsonFp = tgStopQueryJson, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = tgBuildSqlAffectRowsJson, + .initJsonFp = tgInitQueryJson, + .cleanJsonFp = tgCleanQueryJson, + .checkFinishedFp = tgCheckFinished, + .setNextCmdFp = tgSetNextCmd +}; static const char DEFAULT_TELEGRAF_CFG[] = "{\"metrics\":[" @@ -303,7 +310,7 @@ bool tgGetUserFromUrl(HttpContext *pContext) { return false; } - strcpy(pContext->user, pParser->path[TG_USER_URL_POS].pos); + tstrncpy(pContext->user, pParser->path[TG_USER_URL_POS].pos, TSDB_USER_LEN); return true; } diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 47521fc36e594b9f4bfde1171c5cfdb0831a9e2e..01a0eabbca39258951f2e0d6c4e098c7bf009be8 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -191,15 +191,14 @@ void taosResetLog() { } static bool taosCheckFileIsOpen(char *logFileName) { - int32_t exist = access(logFileName, F_OK); - if (exist != 0) { - return false; - } - - int32_t fd = open(logFileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(logFileName, O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { - printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); - return true; + if (errno == ENOENT) { + return false; + } else { + printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); + return true; + } } if (taosLockFile(fd)) {