提交 73c158e1 编写于 作者: S Shengliang Guan

[TD-364] fix definite lost while get card info

上级 561f9a06
...@@ -332,33 +332,42 @@ bool taosGetDisk() { ...@@ -332,33 +332,42 @@ bool taosGetDisk() {
} }
static bool taosGetCardInfo(int64_t *bytes) { static bool taosGetCardInfo(int64_t *bytes) {
*bytes = 0;
FILE *fp = fopen(tsSysNetFile, "r"); FILE *fp = fopen(tsSysNetFile, "r");
if (fp == NULL) { if (fp == NULL) {
uError("open file:%s failed", tsSysNetFile); uError("open file:%s failed", tsSysNetFile);
return false; return false;
} }
int64_t rbytes, rpackts, tbytes, tpackets;
int64_t nouse1, nouse2, nouse3, nouse4, nouse5, nouse6;
char nouse0[200] = {0};
size_t len; size_t len = 2048;
char * line = NULL; char * line = calloc(1, len);
*bytes = 0;
while (!feof(fp)) { while (!feof(fp)) {
tfree(line); memset(line, 0, len);
len = 0;
int64_t rbytes = 0;
int64_t rpackts = 0;
int64_t tbytes = 0;
int64_t tpackets = 0;
int64_t nouse1 = 0;
int64_t nouse2 = 0;
int64_t nouse3 = 0;
int64_t nouse4 = 0;
int64_t nouse5 = 0;
int64_t nouse6 = 0;
char nouse0[200] = {0};
getline(&line, &len, fp); getline(&line, &len, fp);
if (line == NULL) { line[len - 1] = 0;
break;
}
if (strstr(line, "lo:") != NULL) { if (strstr(line, "lo:") != NULL) {
continue; continue;
} }
sscanf(line, sscanf(line,
"%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
" %" PRId64,
nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &tbytes, &tpackets); nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &tbytes, &tpackets);
*bytes += (rbytes + tbytes); *bytes += (rbytes + tbytes);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册