fix: ut issue
This commit is contained in:
parent
47c5958cb2
commit
fdfec17c64
|
@ -52,7 +52,9 @@ int32_t taosDflSignal(int32_t signum) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosKillChildOnParentStopped() {}
|
int32_t taosKillChildOnParentStopped() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
|
@ -957,11 +957,13 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) {
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
struct addrinfo *result = NULL;
|
struct addrinfo *result = NULL;
|
||||||
|
bool inRetry = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int32_t ret = getaddrinfo(fqdn, NULL, &hints, &result);
|
int32_t ret = getaddrinfo(fqdn, NULL, &hints, &result);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (EAI_AGAIN == ret) {
|
if (EAI_AGAIN == ret && !inRetry) {
|
||||||
|
inRetry = true;
|
||||||
continue;
|
continue;
|
||||||
} else if (EAI_SYSTEM == ret) {
|
} else if (EAI_SYSTEM == ret) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
|
|
@ -139,13 +139,14 @@ static void taosGetProcIOnfos() {
|
||||||
tsStreamMax = TMAX(sysconf(_SC_STREAM_MAX), 0);
|
tsStreamMax = TMAX(sysconf(_SC_STREAM_MAX), 0);
|
||||||
tsProcId = (pid_t)syscall(SYS_gettid);
|
tsProcId = (pid_t)syscall(SYS_gettid);
|
||||||
|
|
||||||
snprintf(tsProcMemFile, sizeof(tsProcMemFile), "/proc/%d/status", tsProcId);
|
(void)snprintf(tsProcMemFile, sizeof(tsProcMemFile), "/proc/%d/status", tsProcId);
|
||||||
snprintf(tsProcCpuFile, sizeof(tsProcCpuFile), "/proc/%d/stat", tsProcId);
|
(void)snprintf(tsProcCpuFile, sizeof(tsProcCpuFile), "/proc/%d/stat", tsProcId);
|
||||||
snprintf(tsProcIOFile, sizeof(tsProcIOFile), "/proc/%d/io", tsProcId);
|
(void)snprintf(tsProcIOFile, sizeof(tsProcIOFile), "/proc/%d/io", tsProcId);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
|
static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
|
||||||
|
int32_t code = 0;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
FILETIME pre_idleTime = {0};
|
FILETIME pre_idleTime = {0};
|
||||||
FILETIME pre_kernelTime = {0};
|
FILETIME pre_kernelTime = {0};
|
||||||
|
@ -168,29 +169,38 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
|
||||||
#else
|
#else
|
||||||
TdFilePtr pFile = taosOpenFile(tsSysCpuFile, TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile(tsSysCpuFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
code = terrno;
|
||||||
return -1;
|
(void)taosCloseFile(&pFile);
|
||||||
|
terrno = code;
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
char cpu[10] = {0};
|
char cpu[10] = {0};
|
||||||
sscanf(line,
|
code = sscanf(line,
|
||||||
"%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
|
"%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
|
||||||
" %" PRIu64,
|
" %" PRIu64,
|
||||||
cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle, &cpuInfo->wa, &cpuInfo->hi,
|
cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle, &cpuInfo->wa, &cpuInfo->hi,
|
||||||
&cpuInfo->si, &cpuInfo->st, &cpuInfo->guest, &cpuInfo->guest_nice);
|
&cpuInfo->si, &cpuInfo->st, &cpuInfo->guest, &cpuInfo->guest_nice);
|
||||||
|
if (EOF == code) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
FILETIME pre_krnlTm = {0};
|
FILETIME pre_krnlTm = {0};
|
||||||
FILETIME pre_usrTm = {0};
|
FILETIME pre_usrTm = {0};
|
||||||
|
@ -210,27 +220,35 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
||||||
#else
|
#else
|
||||||
TdFilePtr pFile = taosOpenFile(tsProcCpuFile, TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile(tsProcCpuFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
code = terrno;
|
||||||
return -1;
|
(void)taosCloseFile(&pFile);
|
||||||
|
terrno = code;
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0, blank = 0; line[i] != 0; ++i) {
|
for (int i = 0, blank = 0; line[i] != 0; ++i) {
|
||||||
if (line[i] == ' ') blank++;
|
if (line[i] == ' ') blank++;
|
||||||
if (blank == PROCESS_ITEM) {
|
if (blank == PROCESS_ITEM) {
|
||||||
sscanf(line + i + 1, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &cpuInfo->utime, &cpuInfo->stime,
|
code = sscanf(line + i + 1, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &cpuInfo->utime, &cpuInfo->stime,
|
||||||
&cpuInfo->cutime, &cpuInfo->cstime);
|
&cpuInfo->cutime, &cpuInfo->cstime);
|
||||||
|
if (EOF == code) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,10 +274,10 @@ void taosGetSystemInfo() {
|
||||||
tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
#else
|
#else
|
||||||
taosGetProcIOnfos();
|
taosGetProcIOnfos();
|
||||||
taosGetCpuCores(&tsNumOfCores, false);
|
(void)taosGetCpuCores(&tsNumOfCores, false);
|
||||||
taosGetTotalMemory(&tsTotalMemoryKB);
|
(void)taosGetTotalMemory(&tsTotalMemoryKB);
|
||||||
taosGetCpuUsage(NULL, NULL);
|
(void)taosGetCpuUsage(NULL, NULL);
|
||||||
taosGetCpuInstructions(&tsSSE42Supported, &tsAVXSupported, &tsAVX2Supported, &tsFMASupported, &tsAVX512Supported);
|
(void)taosGetCpuInstructions(&tsSSE42Supported, &tsAVXSupported, &tsAVX2Supported, &tsFMASupported, &tsAVX512Supported);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,14 +309,16 @@ int32_t taosGetEmail(char *email, int32_t maxLen) {
|
||||||
#endif // CUS_PROMPT
|
#endif // CUS_PROMPT
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
||||||
if (pFile == NULL) return false;
|
if (pFile == NULL) return terrno;
|
||||||
|
|
||||||
if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
|
if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
|
||||||
taosCloseFile(&pFile);
|
int32_t code = terrno;
|
||||||
return -1;
|
(void)taosCloseFile(&pFile);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -372,13 +392,15 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t
|
||||||
char line[1024];
|
char line[1024];
|
||||||
char *dest = NULL;
|
char *dest = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
int32_t code = -1;
|
int32_t code = 0;
|
||||||
int32_t cnt = 0;
|
int32_t cnt = 0;
|
||||||
|
|
||||||
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 terrno;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@ -401,7 +423,7 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t
|
||||||
if (++cnt >= 3) break;
|
if (++cnt >= 3) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -450,13 +472,13 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
char line[1024] = {0};
|
char line[1024] = {0};
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
int32_t done = 0;
|
int32_t done = 0;
|
||||||
int32_t code = -1;
|
int32_t code = 0;
|
||||||
float coreCount = 0;
|
float coreCount = 0;
|
||||||
|
|
||||||
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 terrno;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -471,13 +493,13 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
if (strncmp(line, "processor", 9) == 0) coreCount += 1;
|
if (strncmp(line, "processor", 9) == 0) coreCount += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0 && (done & 1) == 0) {
|
if (code != 0 && (done & 1) == 0) {
|
||||||
TdFilePtr pFile1 = taosOpenFile("/proc/device-tree/model", TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile1 = taosOpenFile("/proc/device-tree/model", TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile1 != NULL) {
|
if (pFile1 != NULL) {
|
||||||
ssize_t bytes = taosGetsFile(pFile1, maxLen, cpuModel);
|
ssize_t bytes = taosGetsFile(pFile1, maxLen, cpuModel);
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
if (bytes > 0) {
|
if (bytes > 0) {
|
||||||
code = 0;
|
code = 0;
|
||||||
done |= 1;
|
done |= 1;
|
||||||
|
|
|
@ -57,7 +57,7 @@ TEST(osTest, osFQDNFailed) {
|
||||||
char ipString[24];
|
char ipString[24];
|
||||||
uint32_t ipv4 = 0;
|
uint32_t ipv4 = 0;
|
||||||
int32_t code = taosGetIpv4FromFqdn(fqdn, &ipv4);
|
int32_t code = taosGetIpv4FromFqdn(fqdn, &ipv4);
|
||||||
ASSERT_EQ(ipv4, 0xffffffff);
|
ASSERT_NE(code, 0);
|
||||||
|
|
||||||
terrno = TSDB_CODE_RPC_FQDN_ERROR;
|
terrno = TSDB_CODE_RPC_FQDN_ERROR;
|
||||||
printf("fqdn:%s transfer to ip failed!\n", fqdn);
|
printf("fqdn:%s transfer to ip failed!\n", fqdn);
|
||||||
|
|
Loading…
Reference in New Issue