os: fix flashing black console error

This commit is contained in:
afwerar 2022-08-19 14:09:33 +08:00
parent 72b2a3cf26
commit a642607c68
2 changed files with 30 additions and 46 deletions

View File

@ -331,9 +331,11 @@ endif(${BUILD_WITH_TRAFT})
# LIBUV # LIBUV
if(${BUILD_WITH_UV}) if(${BUILD_WITH_UV})
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if (TD_WINDOWS)
MESSAGE("Windows need set no-sign-compare") # There is no GetHostNameW function on win7.
add_compile_options(-Wno-sign-compare) file(READ "libuv/src/win/util.c" LIBUV_WIN_UTIL_CONTENT)
string(REPLACE "if (GetHostNameW(buf, UV_MAXHOSTNAMESIZE" "DWORD nSize = UV_MAXHOSTNAMESIZE;\n if (GetComputerNameW(buf, &nSize" LIBUV_WIN_UTIL_CONTENT "${LIBUV_WIN_UTIL_CONTENT}")
file(WRITE "libuv/src/win/util.c" "${LIBUV_WIN_UTIL_CONTENT}")
endif () endif ()
add_subdirectory(libuv EXCLUDE_FROM_ALL) add_subdirectory(libuv EXCLUDE_FROM_ALL)
endif(${BUILD_WITH_UV}) endif(${BUILD_WITH_UV})

View File

@ -33,6 +33,8 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd);
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url); int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype); int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype);
extern char **environ;
SConfig *cfgInit() { SConfig *cfgInit() {
SConfig *pCfg = taosMemoryCalloc(1, sizeof(SConfig)); SConfig *pCfg = taosMemoryCalloc(1, sizeof(SConfig));
if (pCfg == NULL) { if (pCfg == NULL) {
@ -627,24 +629,17 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
} }
int32_t cfgLoadFromEnvVar(SConfig *pConfig) { int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
char *line = NULL, *name, *value, *value2, *value3; char line[1024], *name, *value, *value2, *value3;
int32_t olen, vlen, vlen2, vlen3; int32_t olen, vlen, vlen2, vlen3;
int32_t code = 0; int32_t code = 0;
ssize_t _bytes = 0; char **pEnv = environ;
TdCmdPtr pCmd = taosOpenCmd("set"); line[1023] = 0;
if (pCmd == NULL) { while(*pEnv != NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
while (!taosEOFCmd(pCmd)) {
name = value = value2 = value3 = NULL; name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0; olen = vlen = vlen2 = vlen3 = 0;
_bytes = taosGetLineCmd(pCmd, &line); strncpy(line, *pEnv, sizeof(line)-1);
if (_bytes < 0) { *pEnv++;
break;
}
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
taosEnvToCfg(line, line); taosEnvToCfg(line, line);
paGetToken(line, &name, &olen); paGetToken(line, &name, &olen);
@ -671,9 +666,6 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
} }
} }
taosCloseCmd(&pCmd);
if (line != NULL) taosMemoryFreeClear(line);
uInfo("load from env variables cfg success"); uInfo("load from env variables cfg success");
return 0; return 0;
} }
@ -1040,34 +1032,25 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
index++; index++;
} }
char *line = NULL; char line[1024];
ssize_t _bytes = 0; char **pEnv = environ;
TdCmdPtr pCmd = taosOpenCmd("set"); line[1023] = 0;
if (pCmd != NULL) { while(*pEnv != NULL) {
while (!taosEOFCmd(pCmd)) { strncpy(line, *pEnv, sizeof(line)-1);
_bytes = taosGetLineCmd(pCmd, &line); *pEnv++;
if (_bytes < 0) { if (strncmp(line, "TAOS_APOLLO_URL", 14) == 0) {
break; char *p = strchr(line, '=');
} if (p != NULL) {
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; p++;
if (strncmp(line, "TAOS_APOLLO_URL", 14) == 0) { if (*p == '\'') {
char *p = strchr(line, '=');
if (p != NULL) {
p++; p++;
if (*p == '\'') { p[strlen(p)-1] = '\0';
p++;
p[strlen(p)-1] = '\0';
}
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl);
taosCloseCmd(&pCmd);
if (line != NULL) taosMemoryFreeClear(line);
return 0;
} }
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl);
return 0;
} }
} }
taosCloseCmd(&pCmd);
if (line != NULL) taosMemoryFreeClear(line);
} }
const char *filepath = ".env"; const char *filepath = ".env";
@ -1083,10 +1066,11 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
return 0; return 0;
} }
} }
int64_t _bytes;
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
if (pFile != NULL) { if (pFile != NULL) {
while (!taosEOFFile(pFile)) { while (!taosEOFFile(pFile)) {
_bytes = taosGetLineFile(pFile, &line); _bytes = taosGetsFile(pFile, sizeof(line) - 1, &line);
if (_bytes <= 0) { if (_bytes <= 0) {
break; break;
} }
@ -1101,14 +1085,12 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
} }
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
taosCloseFile(&pFile); taosCloseFile(&pFile);
if (line != NULL) taosMemoryFreeClear(line);
uInfo("get apollo url from env file success"); uInfo("get apollo url from env file success");
return 0; return 0;
} }
} }
} }
taosCloseFile(&pFile); taosCloseFile(&pFile);
if (line != NULL) taosMemoryFreeClear(line);
} }
uInfo("fail get apollo url from cmd env file"); uInfo("fail get apollo url from cmd env file");