fix: shell read file issue
This commit is contained in:
parent
47c5958cb2
commit
4ef485dbf9
|
@ -1442,7 +1442,12 @@ int64_t taosGetsFile(TdFilePtr pFile, int32_t maxSize, char *__restrict buf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(buf, maxSize, pFile->fp) == NULL) {
|
if (fgets(buf, maxSize, pFile->fp) == NULL) {
|
||||||
|
if (feof(pFile->fp)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(ferror(pFile->fp));
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return strlen(buf);
|
return strlen(buf);
|
||||||
|
|
|
@ -173,7 +173,7 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
|
||||||
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||||
if (bytes < 0) {
|
if (bytes <= 0) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
||||||
|
|
||||||
char line[1024] = {0};
|
char line[1024] = {0};
|
||||||
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||||
if (bytes < 0) {
|
if (bytes <= 0) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,7 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t
|
||||||
TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) return code;
|
if (pFile == NULL) return code;
|
||||||
|
|
||||||
while ((size = taosGetsFile(pFile, sizeof(line), line)) != -1) {
|
while ((size = taosGetsFile(pFile, sizeof(line), line)) > 0) {
|
||||||
line[size - 1] = '\0';
|
line[size - 1] = '\0';
|
||||||
if (strncmp(line, "NAME", 4) == 0) {
|
if (strncmp(line, "NAME", 4) == 0) {
|
||||||
dest = sName;
|
dest = sName;
|
||||||
|
@ -456,7 +456,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) return code;
|
if (pFile == NULL) return code;
|
||||||
|
|
||||||
while (done != 3 && (size = taosGetsFile(pFile, sizeof(line), line)) != -1) {
|
while (done != 3 && (size = taosGetsFile(pFile, sizeof(line), line)) > 0) {
|
||||||
line[size - 1] = '\0';
|
line[size - 1] = '\0';
|
||||||
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
|
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
|
||||||
const char *v = strchr(line, ':') + 2;
|
const char *v = strchr(line, ':') + 2;
|
||||||
|
@ -516,7 +516,7 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
goto _sys;
|
goto _sys;
|
||||||
}
|
}
|
||||||
char qline[32] = {0};
|
char qline[32] = {0};
|
||||||
if (taosGetsFile(pFile, sizeof(qline), qline) < 0) {
|
if (taosGetsFile(pFile, sizeof(qline), qline) <= 0) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
goto _sys;
|
goto _sys;
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
goto _sys;
|
goto _sys;
|
||||||
}
|
}
|
||||||
char pline[32] = {0};
|
char pline[32] = {0};
|
||||||
if (taosGetsFile(pFile, sizeof(pline), pline) < 0) {
|
if (taosGetsFile(pFile, sizeof(pline), pline) <= 0) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
goto _sys;
|
goto _sys;
|
||||||
}
|
}
|
||||||
|
@ -691,7 +691,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
|
||||||
char line[1024] = {0};
|
char line[1024] = {0};
|
||||||
while (!taosEOFFile(pFile)) {
|
while (!taosEOFFile(pFile)) {
|
||||||
bytes = taosGetsFile(pFile, sizeof(line), line);
|
bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||||
if (bytes < 0) {
|
if (bytes <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strstr(line, "VmRSS:") != NULL) {
|
if (strstr(line, "VmRSS:") != NULL) {
|
||||||
|
@ -895,7 +895,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
char nouse0[200] = {0};
|
char nouse0[200] = {0};
|
||||||
|
|
||||||
_bytes = taosGetsFile(pFile, sizeof(line), line);
|
_bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||||
if (_bytes < 0) {
|
if (_bytes <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1118,7 +1118,7 @@ void shellSourceFile(const char *file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1);
|
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) {
|
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);
|
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;
|
cmd_len = 0;
|
||||||
|
|
|
@ -198,7 +198,7 @@ SScript *simParseScript(char *fileName) {
|
||||||
simResetParser();
|
simResetParser();
|
||||||
|
|
||||||
while (!taosEOFFile(pFile)) {
|
while (!taosEOFFile(pFile)) {
|
||||||
if (taosGetsFile(pFile, sizeof(buffer) - 1, buffer) == -1) continue;
|
if (taosGetsFile(pFile, sizeof(buffer) - 1, buffer) <= 0) continue;
|
||||||
|
|
||||||
lineNum++;
|
lineNum++;
|
||||||
int32_t cmdlen = (int32_t)strlen(buffer);
|
int32_t cmdlen = (int32_t)strlen(buffer);
|
||||||
|
|
Loading…
Reference in New Issue