From 0495644242a932c29699b1143a6b2f3307151e73 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 9 Jun 2020 03:18:51 +0000 Subject: [PATCH] [TD_543] fix coverity scan, cid:267845 267846 --- src/client/src/tscSystem.c | 2 +- src/os/linux/src/linuxSysPara.c | 93 ++++++--------------------------- 2 files changed, 18 insertions(+), 77 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index d3c8eefbb9..fd7d31aa9f 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/os/linux/src/linuxSysPara.c b/src/os/linux/src/linuxSysPara.c index ca244dcd94..b270eb14cf 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 -- GitLab