fix: os return code
This commit is contained in:
parent
2f284b252f
commit
d3ab79da10
|
@ -44,7 +44,7 @@ int64_t taosGetLineCmd(TdCmdPtr pCmd, char **__restrict ptrBuf);
|
||||||
|
|
||||||
int32_t taosEOFCmd(TdCmdPtr pCmd);
|
int32_t taosEOFCmd(TdCmdPtr pCmd);
|
||||||
|
|
||||||
int64_t taosCloseCmd(TdCmdPtr *ppCmd);
|
void taosCloseCmd(TdCmdPtr *ppCmd);
|
||||||
|
|
||||||
void *taosLoadDll(const char *filename);
|
void *taosLoadDll(const char *filename);
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@ void taosCloseDll(void *handle);
|
||||||
|
|
||||||
int32_t taosSetConsoleEcho(bool on);
|
int32_t taosSetConsoleEcho(bool on);
|
||||||
|
|
||||||
void taosSetTerminalMode();
|
int32_t taosSetTerminalMode();
|
||||||
|
|
||||||
int32_t taosGetOldTerminalMode();
|
int32_t taosGetOldTerminalMode();
|
||||||
|
|
||||||
void taosResetTerminalMode();
|
int32_t taosResetTerminalMode();
|
||||||
|
|
||||||
#define STACKSIZE 100
|
#define STACKSIZE 100
|
||||||
|
|
||||||
|
|
|
@ -952,6 +952,8 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) {
|
||||||
return 0xFFFFFFFF;
|
return 0xFFFFFFFF;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LINUX)
|
||||||
struct addrinfo hints = {0};
|
struct addrinfo hints = {0};
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
@ -984,6 +986,34 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
struct addrinfo hints = {0};
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
|
struct addrinfo *result = NULL;
|
||||||
|
|
||||||
|
int32_t ret = getaddrinfo(fqdn, NULL, &hints, &result);
|
||||||
|
if (result) {
|
||||||
|
struct sockaddr *sa = result->ai_addr;
|
||||||
|
struct sockaddr_in *si = (struct sockaddr_in *)sa;
|
||||||
|
struct in_addr ia = si->sin_addr;
|
||||||
|
uint32_t ip = ia.s_addr;
|
||||||
|
freeaddrinfo(result);
|
||||||
|
return ip;
|
||||||
|
} else {
|
||||||
|
#ifdef EAI_SYSTEM
|
||||||
|
if (ret == EAI_SYSTEM) {
|
||||||
|
// printf("failed to get the ip address, fqdn:%s, errno:%d, since:%s", fqdn, errno, strerror(errno));
|
||||||
|
} else {
|
||||||
|
// printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret));
|
||||||
|
#endif
|
||||||
|
return 0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosGetFqdn(char *fqdn) {
|
int32_t taosGetFqdn(char *fqdn) {
|
||||||
|
|
|
@ -201,14 +201,14 @@ iconv_t taosAcquireConv(int32_t *idx, ConvType type) {
|
||||||
iconv_t c = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
iconv_t c = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||||
if ((iconv_t)-1 == c || (iconv_t)0 == c) {
|
if ((iconv_t)-1 == c || (iconv_t)0 == c) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
return c;
|
||||||
} else {
|
} else {
|
||||||
iconv_t c = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
iconv_t c = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||||
if ((iconv_t)-1 == c || (iconv_t)0 == c) {
|
if ((iconv_t)-1 == c || (iconv_t)0 == c) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -509,7 +509,9 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
|
|
||||||
if (code != 0 && (done & 1) == 0) {
|
if (code != 0 && (done & 1) == 0) {
|
||||||
TdCmdPtr pCmd = taosOpenCmd("uname -a");
|
TdCmdPtr pCmd = taosOpenCmd("uname -a");
|
||||||
if (pCmd == NULL) return code;
|
if (pCmd == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
if (taosGetsCmd(pCmd, maxLen, cpuModel) > 0) {
|
if (taosGetsCmd(pCmd, maxLen, cpuModel) > 0) {
|
||||||
code = 0;
|
code = 0;
|
||||||
done |= 1;
|
done |= 1;
|
||||||
|
@ -539,10 +541,11 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
}
|
}
|
||||||
char qline[32] = {0};
|
char qline[32] = {0};
|
||||||
if (taosGetsFile(pFile, sizeof(qline), qline) <= 0) {
|
if (taosGetsFile(pFile, sizeof(qline), qline) <= 0) {
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
goto _sys;
|
goto _sys;
|
||||||
}
|
}
|
||||||
taosCloseFile(&pFile);
|
|
||||||
|
(void)taosCloseFile(&pFile);
|
||||||
float quota = taosStr2Float(qline, NULL);
|
float quota = taosStr2Float(qline, NULL);
|
||||||
if (quota < 0) {
|
if (quota < 0) {
|
||||||
goto _sys;
|
goto _sys;
|
||||||
|
@ -551,12 +554,14 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
if (!(pFile = taosOpenFile(tsCpuPeriodFile, TD_FILE_READ | TD_FILE_STREAM))) {
|
if (!(pFile = taosOpenFile(tsCpuPeriodFile, TD_FILE_READ | TD_FILE_STREAM))) {
|
||||||
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);
|
(void)taosCloseFile(&pFile);
|
||||||
goto _sys;
|
goto _sys;
|
||||||
}
|
}
|
||||||
taosCloseFile(&pFile);
|
|
||||||
|
(void)taosCloseFile(&pFile);
|
||||||
|
|
||||||
float period = taosStr2Float(pline, NULL);
|
float period = taosStr2Float(pline, NULL);
|
||||||
float quotaCores = quota / period;
|
float quotaCores = quota / period;
|
||||||
|
@ -567,10 +572,13 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
*numOfCores = sysCores;
|
*numOfCores = sysCores;
|
||||||
}
|
}
|
||||||
goto _end;
|
goto _end;
|
||||||
|
|
||||||
_sys:
|
_sys:
|
||||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,7 +595,7 @@ int32_t taosGetCpuCores(float *numOfCores, bool physical) {
|
||||||
if (physical) {
|
if (physical) {
|
||||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
} else {
|
} else {
|
||||||
taosCntrGetCpuCores(numOfCores);
|
(void)taosCntrGetCpuCores(numOfCores);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -706,7 +714,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
|
||||||
TdFilePtr pFile = taosOpenFile(tsProcMemFile, TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile(tsProcMemFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
// printf("open file:%s failed", tsProcMemFile);
|
// printf("open file:%s failed", tsProcMemFile);
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t bytes = 0;
|
ssize_t bytes = 0;
|
||||||
|
@ -722,9 +730,10 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char tmp[10];
|
char tmp[10];
|
||||||
sscanf(line, "%s %" PRId64, tmp, usedKB);
|
(void)sscanf(line, "%s %" PRId64, tmp, usedKB);
|
||||||
|
|
||||||
|
(void)taosCloseFile(&pFile);
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -783,13 +792,14 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct statvfs info;
|
struct statvfs info;
|
||||||
if (statvfs(dataDir, &info)) {
|
if (-1 == statvfs(dataDir, &info)) {
|
||||||
// terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return terrno;
|
||||||
} else {
|
} else {
|
||||||
diskSize->total = info.f_blocks * info.f_frsize;
|
diskSize->total = info.f_blocks * info.f_frsize;
|
||||||
diskSize->avail = info.f_bavail * info.f_frsize;
|
diskSize->avail = info.f_bavail * info.f_frsize;
|
||||||
diskSize->used = diskSize->total - diskSize->avail;
|
diskSize->used = diskSize->total - diskSize->avail;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -814,7 +824,9 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) return -1;
|
if (pFile == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
ssize_t bytes = 0;
|
ssize_t bytes = 0;
|
||||||
char line[1024] = {0};
|
char line[1024] = {0};
|
||||||
|
@ -827,16 +839,16 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strstr(line, "rchar:") != NULL) {
|
if (strstr(line, "rchar:") != NULL) {
|
||||||
sscanf(line, "%s %" PRId64, tmp, rchars);
|
(void)sscanf(line, "%s %" PRId64, tmp, rchars);
|
||||||
readIndex++;
|
readIndex++;
|
||||||
} else if (strstr(line, "wchar:") != NULL) {
|
} else if (strstr(line, "wchar:") != NULL) {
|
||||||
sscanf(line, "%s %" PRId64, tmp, wchars);
|
(void)sscanf(line, "%s %" PRId64, tmp, wchars);
|
||||||
readIndex++;
|
readIndex++;
|
||||||
} else if (strstr(line, "read_bytes:") != NULL) { // read_bytes
|
} else if (strstr(line, "read_bytes:") != NULL) { // read_bytes
|
||||||
sscanf(line, "%s %" PRId64, tmp, read_bytes);
|
(void)sscanf(line, "%s %" PRId64, tmp, read_bytes);
|
||||||
readIndex++;
|
readIndex++;
|
||||||
} else if (strstr(line, "write_bytes:") != NULL) { // write_bytes
|
} else if (strstr(line, "write_bytes:") != NULL) { // write_bytes
|
||||||
sscanf(line, "%s %" PRId64, tmp, write_bytes);
|
(void)sscanf(line, "%s %" PRId64, tmp, write_bytes);
|
||||||
readIndex++;
|
readIndex++;
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
@ -844,7 +856,7 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
|
||||||
if (readIndex >= 4) break;
|
if (readIndex >= 4) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (readIndex < 4) {
|
if (readIndex < 4) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -898,7 +910,9 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
TdFilePtr pFile = taosOpenFile(tsSysNetFile, TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile(tsSysNetFile, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) return -1;
|
if (pFile == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
ssize_t _bytes = 0;
|
ssize_t _bytes = 0;
|
||||||
char line[1024];
|
char line[1024];
|
||||||
|
@ -927,7 +941,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sscanf(line,
|
(void)sscanf(line,
|
||||||
"%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
|
"%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
|
||||||
" %" PRId64,
|
" %" PRId64,
|
||||||
nouse0, &o_rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &o_tbytes, &tpackets);
|
nouse0, &o_rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &o_tbytes, &tpackets);
|
||||||
|
@ -935,7 +949,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
*transmit_bytes += o_tbytes;
|
*transmit_bytes += o_tbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -973,8 +987,8 @@ void taosKillSystem() {
|
||||||
exit(0);
|
exit(0);
|
||||||
#else
|
#else
|
||||||
// SIGINT
|
// SIGINT
|
||||||
printf("taosd will shut down soon");
|
(void)printf("taosd will shut down soon");
|
||||||
kill(tsProcId, 2);
|
(void)kill(tsProcId, 2);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1006,10 +1020,13 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
|
||||||
// fd = open("/proc/sys/kernel/random/uuid", 0);
|
// fd = open("/proc/sys/kernel/random/uuid", 0);
|
||||||
TdFilePtr pFile = taosOpenFile("/proc/sys/kernel/random/uuid", TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile("/proc/sys/kernel/random/uuid", TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return -1;
|
return terrno;
|
||||||
} else {
|
} else {
|
||||||
len = taosReadFile(pFile, uid, uidlen);
|
len = taosReadFile(pFile, uid, uidlen);
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
|
if (len < 0) {
|
||||||
|
return len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len >= 36) {
|
if (len >= 36) {
|
||||||
|
@ -1037,7 +1054,7 @@ char *taosGetCmdlineByPID(int pid) {
|
||||||
return cmdline;
|
return cmdline;
|
||||||
#else
|
#else
|
||||||
static char cmdline[1024];
|
static char cmdline[1024];
|
||||||
sprintf(cmdline, "/proc/%d/cmdline", pid);
|
(void)sprintf(cmdline, "/proc/%d/cmdline", pid);
|
||||||
|
|
||||||
// int fd = open(cmdline, O_RDONLY);
|
// int fd = open(cmdline, O_RDONLY);
|
||||||
TdFilePtr pFile = taosOpenFile(cmdline, TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile(cmdline, TD_FILE_READ);
|
||||||
|
@ -1049,7 +1066,7 @@ char *taosGetCmdlineByPID(int pid) {
|
||||||
|
|
||||||
cmdline[n] = 0;
|
cmdline[n] = 0;
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
} else {
|
} else {
|
||||||
cmdline[0] = 0;
|
cmdline[0] = 0;
|
||||||
}
|
}
|
||||||
|
@ -1063,9 +1080,13 @@ int64_t taosGetOsUptime() {
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
#else
|
#else
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
if (0 == sysinfo(&info)) {
|
if (-1 == sysinfo(&info)) {
|
||||||
return (int64_t)info.uptime * 1000;
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (int64_t)info.uptime * 1000;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1115,7 +1136,7 @@ void taosSetCoreDump(bool enable) {
|
||||||
|
|
||||||
int name[] = {CTL_KERN, KERN_CORE_USES_PID};
|
int name[] = {CTL_KERN, KERN_CORE_USES_PID};
|
||||||
|
|
||||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
(void)memset(&args, 0, sizeof(struct __sysctl_args));
|
||||||
args.name = name;
|
args.name = name;
|
||||||
args.nlen = sizeof(name) / sizeof(name[0]);
|
args.nlen = sizeof(name) / sizeof(name[0]);
|
||||||
args.oldval = &old_usespid;
|
args.oldval = &old_usespid;
|
||||||
|
@ -1135,7 +1156,7 @@ void taosSetCoreDump(bool enable) {
|
||||||
|
|
||||||
old_usespid = 0;
|
old_usespid = 0;
|
||||||
old_len = 0;
|
old_len = 0;
|
||||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
(void)memset(&args, 0, sizeof(struct __sysctl_args));
|
||||||
args.name = name;
|
args.name = name;
|
||||||
args.nlen = sizeof(name) / sizeof(name[0]);
|
args.nlen = sizeof(name) / sizeof(name[0]);
|
||||||
args.oldval = &old_usespid;
|
args.oldval = &old_usespid;
|
||||||
|
@ -1198,6 +1219,8 @@ SysNameInfo taosGetSysNameInfo() {
|
||||||
tstrncpy(info.release, uts.release, sizeof(info.release));
|
tstrncpy(info.release, uts.release, sizeof(info.release));
|
||||||
tstrncpy(info.version, uts.version, sizeof(info.version));
|
tstrncpy(info.version, uts.version, sizeof(info.version));
|
||||||
tstrncpy(info.machine, uts.machine, sizeof(info.machine));
|
tstrncpy(info.machine, uts.machine, sizeof(info.machine));
|
||||||
|
} else {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
|
@ -1262,6 +1285,11 @@ int taosGetlocalhostname(char *hostname, size_t maxLen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return gethostname(hostname, maxLen);
|
int r = gethostname(hostname, maxLen);
|
||||||
|
if (-1 == r) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,8 +162,8 @@ int taosSetConsoleEcho(bool on) {
|
||||||
struct termios term;
|
struct termios term;
|
||||||
|
|
||||||
if (tcgetattr(STDIN_FILENO, &term) == -1) {
|
if (tcgetattr(STDIN_FILENO, &term) == -1) {
|
||||||
/*perror("Cannot get the attribution of the terminal");*/
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (on)
|
if (on)
|
||||||
|
@ -172,18 +172,18 @@ int taosSetConsoleEcho(bool on) {
|
||||||
term.c_lflag &= ~ECHOFLAGS;
|
term.c_lflag &= ~ECHOFLAGS;
|
||||||
|
|
||||||
err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
|
err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
|
||||||
if (err == -1 || err == EINTR) {
|
if (err == -1) {
|
||||||
/*printf("Cannot set the attribution of the terminal");*/
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosSetTerminalMode() {
|
int32_t taosSetTerminalMode() {
|
||||||
#if defined(WINDOWS)
|
#if defined(WINDOWS)
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
struct termios newtio;
|
struct termios newtio;
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ void taosSetTerminalMode() {
|
||||||
/* exit(EXIT_FAILURE); */
|
/* exit(EXIT_FAILURE); */
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
memcpy(&newtio, &oldtio, sizeof(oldtio));
|
(void)memcpy(&newtio, &oldtio, sizeof(oldtio));
|
||||||
|
|
||||||
// Set new terminal attributes.
|
// Set new terminal attributes.
|
||||||
newtio.c_iflag &= ~(IXON | IXOFF | ICRNL | INLCR | IGNCR | IMAXBEL | ISTRIP);
|
newtio.c_iflag &= ~(IXON | IXOFF | ICRNL | INLCR | IGNCR | IMAXBEL | ISTRIP);
|
||||||
|
@ -207,10 +207,13 @@ void taosSetTerminalMode() {
|
||||||
newtio.c_cc[VMIN] = 1;
|
newtio.c_cc[VMIN] = 1;
|
||||||
newtio.c_cc[VTIME] = 0;
|
newtio.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
if (tcsetattr(0, TCSANOW, &newtio) != 0) {
|
if (-1 == tcsetattr(0, TCSANOW, &newtio)) {
|
||||||
fprintf(stderr, "Fail to set terminal properties!\n");
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
exit(EXIT_FAILURE);
|
(void)fprintf(stderr, "Fail to set terminal properties!\n");
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,54 +222,75 @@ int32_t taosGetOldTerminalMode() {
|
||||||
#else
|
#else
|
||||||
/* Make sure stdin is a terminal. */
|
/* Make sure stdin is a terminal. */
|
||||||
if (!isatty(STDIN_FILENO)) {
|
if (!isatty(STDIN_FILENO)) {
|
||||||
return -1;
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the parameter of current terminal
|
// Get the parameter of current terminal
|
||||||
if (tcgetattr(0, &oldtio) != 0) {
|
if (-1 == tcgetattr(0, &oldtio)) {
|
||||||
return -1;
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosResetTerminalMode() {
|
int32_t taosResetTerminalMode() {
|
||||||
#if defined(WINDOWS)
|
#if defined(WINDOWS)
|
||||||
#else
|
#else
|
||||||
if (tcsetattr(0, TCSANOW, &oldtio) != 0) {
|
if (-1 == tcsetattr(0, TCSANOW, &oldtio)) {
|
||||||
fprintf(stderr, "Fail to reset the terminal properties!\n");
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
exit(EXIT_FAILURE);
|
(void)fprintf(stderr, "Fail to reset the terminal properties!\n");
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TdCmdPtr taosOpenCmd(const char* cmd) {
|
TdCmdPtr taosOpenCmd(const char* cmd) {
|
||||||
if (cmd == NULL) return NULL;
|
if (cmd == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
return (TdCmdPtr)_popen(cmd, "r");
|
return (TdCmdPtr)_popen(cmd, "r");
|
||||||
#else
|
#else
|
||||||
return (TdCmdPtr)popen(cmd, "r");
|
TdCmdPtr p = (TdCmdPtr)popen(cmd, "r");
|
||||||
|
if (NULL == p) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosGetsCmd(TdCmdPtr pCmd, int32_t maxSize, char* __restrict buf) {
|
int64_t taosGetsCmd(TdCmdPtr pCmd, int32_t maxSize, char* __restrict buf) {
|
||||||
if (pCmd == NULL || buf == NULL) {
|
if (pCmd == NULL || buf == NULL) {
|
||||||
return -1;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
if (fgets(buf, maxSize, (FILE*)pCmd) == NULL) {
|
if (fgets(buf, maxSize, (FILE*)pCmd) == NULL) {
|
||||||
return -1;
|
if (feof((FILE*)pCmd)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(ferror((FILE*)pCmd));
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strlen(buf);
|
return strlen(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosGetLineCmd(TdCmdPtr pCmd, char** __restrict ptrBuf) {
|
int64_t taosGetLineCmd(TdCmdPtr pCmd, char** __restrict ptrBuf) {
|
||||||
if (pCmd == NULL || ptrBuf == NULL) {
|
if (pCmd == NULL || ptrBuf == NULL) {
|
||||||
return -1;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
if (*ptrBuf != NULL) {
|
if (*ptrBuf != NULL) {
|
||||||
taosMemoryFreeClear(*ptrBuf);
|
taosMemoryFreeClear(*ptrBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
*ptrBuf = taosMemoryMalloc(1024);
|
*ptrBuf = taosMemoryMalloc(1024);
|
||||||
if (*ptrBuf == NULL) return -1;
|
if (*ptrBuf == NULL) return -1;
|
||||||
|
@ -277,8 +301,13 @@ int64_t taosGetLineCmd(TdCmdPtr pCmd, char** __restrict ptrBuf) {
|
||||||
(*ptrBuf)[1023] = 0;
|
(*ptrBuf)[1023] = 0;
|
||||||
return strlen(*ptrBuf);
|
return strlen(*ptrBuf);
|
||||||
#else
|
#else
|
||||||
size_t len = 0;
|
int64_t len = 0;
|
||||||
return getline(ptrBuf, &len, (FILE*)pCmd);
|
len = getline(ptrBuf, &len, (FILE*)pCmd);
|
||||||
|
if (-1 == len) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,15 +318,14 @@ int32_t taosEOFCmd(TdCmdPtr pCmd) {
|
||||||
return feof((FILE*)pCmd);
|
return feof((FILE*)pCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosCloseCmd(TdCmdPtr* ppCmd) {
|
void taosCloseCmd(TdCmdPtr* ppCmd) {
|
||||||
if (ppCmd == NULL || *ppCmd == NULL) {
|
if (ppCmd == NULL || *ppCmd == NULL) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
_pclose((FILE*)(*ppCmd));
|
_pclose((FILE*)(*ppCmd));
|
||||||
#else
|
#else
|
||||||
pclose((FILE*)(*ppCmd));
|
(void)pclose((FILE*)(*ppCmd));
|
||||||
#endif
|
#endif
|
||||||
*ppCmd = NULL;
|
*ppCmd = NULL;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue