Feature/sangshuduo/td 5844 cmdline parameters align (#7442)
* [TD-5844]<feature>: make cmd line parameter similar. * fix test case align with taosdemo change. * fix windows stack overflow issue. * fix mac compile error. * fix taosdemo cmdline parameter in tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py * fix windows compiler options. * make taos.exe use mysql style password input. * make taos shell and taosdump use mysql style password input. * determine scanf return value. * make console echo off during password input.
This commit is contained in:
parent
d4105ff20b
commit
47625967d2
|
@ -866,10 +866,12 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
|
|||
arguments->user = argv[++i];
|
||||
} else if (strncmp(argv[i], "-p", 2) == 0) {
|
||||
if (strlen(argv[i]) == 2) {
|
||||
printf("Enter password:");
|
||||
printf("Enter password: ");
|
||||
taosSetConsoleEcho(false);
|
||||
if (scanf("%s", arguments->password) > 1) {
|
||||
fprintf(stderr, "password read error!\n");
|
||||
}
|
||||
taosSetConsoleEcho(true);
|
||||
} else {
|
||||
tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
|
||||
}
|
||||
|
|
|
@ -561,9 +561,11 @@ static void parse_password(
|
|||
if (strncmp(argv[i], "-p", 2) == 0) {
|
||||
if (strlen(argv[i]) == 2) {
|
||||
printf("Enter password: ");
|
||||
taosSetConsoleEcho(false);
|
||||
if(scanf("%20s", arguments->password) > 1) {
|
||||
errorPrint("%s() LN%d, password read error!\n", __func__, __LINE__);
|
||||
}
|
||||
taosSetConsoleEcho(true);
|
||||
} else {
|
||||
tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ void* taosLoadDll(const char *filename);
|
|||
void* taosLoadSym(void* handle, char* name);
|
||||
void taosCloseDll(void *handle);
|
||||
|
||||
int taosSetConsoleEcho(bool on);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -29,4 +29,30 @@ void* taosLoadSym(void* handle, char* name) {
|
|||
void taosCloseDll(void *handle) {
|
||||
}
|
||||
|
||||
int taosSetConsoleEcho(bool on)
|
||||
{
|
||||
#if 0
|
||||
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
|
||||
int err;
|
||||
struct termios term;
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &term) == -1) {
|
||||
perror("Cannot get the attribution of the terminal");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (on)
|
||||
term.c_lflag|=ECHOFLAGS;
|
||||
else
|
||||
term.c_lflag &=~ECHOFLAGS;
|
||||
|
||||
err = tcsetattr(STDIN_FILENO,TCSAFLUSH,&term);
|
||||
if (err == -1 && err == EINTR) {
|
||||
perror("Cannot set the attribution of the terminal");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,4 +51,28 @@ void taosCloseDll(void *handle) {
|
|||
}
|
||||
}
|
||||
|
||||
int taosSetConsoleEcho(bool on)
|
||||
{
|
||||
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
|
||||
int err;
|
||||
struct termios term;
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &term) == -1) {
|
||||
perror("Cannot get the attribution of the terminal");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (on)
|
||||
term.c_lflag|=ECHOFLAGS;
|
||||
else
|
||||
term.c_lflag &=~ECHOFLAGS;
|
||||
|
||||
err = tcsetattr(STDIN_FILENO,TCSAFLUSH,&term);
|
||||
if (err == -1 && err == EINTR) {
|
||||
perror("Cannot set the attribution of the terminal");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,3 +30,17 @@ void taosCloseDll(void *handle) {
|
|||
}
|
||||
|
||||
|
||||
int taosSetConsoleEcho(bool on)
|
||||
{
|
||||
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD mode = 0;
|
||||
GetConsoleMode(hStdin, &mode );
|
||||
if (on) {
|
||||
mode |= ENABLE_ECHO_INPUT;
|
||||
} else {
|
||||
mode &= ~ENABLE_ECHO_INPUT;
|
||||
}
|
||||
SetConsoleMode(hStdin, mode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue