shell: fix taos shell ctrl-c exit error
This commit is contained in:
parent
a7fedb458d
commit
ec5db6e195
|
@ -51,6 +51,13 @@ IF(${TD_WINDOWS})
|
||||||
"If build unit tests using googletest"
|
"If build unit tests using googletest"
|
||||||
ON
|
ON
|
||||||
)
|
)
|
||||||
|
|
||||||
|
option(
|
||||||
|
TDENGINE_3
|
||||||
|
"TDengine 3.x"
|
||||||
|
ON
|
||||||
|
)
|
||||||
|
|
||||||
ELSEIF (TD_DARWIN_64)
|
ELSEIF (TD_DARWIN_64)
|
||||||
add_definitions(-DCOMPILER_SUPPORTS_CXX13)
|
add_definitions(-DCOMPILER_SUPPORTS_CXX13)
|
||||||
option(
|
option(
|
||||||
|
|
|
@ -44,7 +44,11 @@ extern "C" {
|
||||||
#define SIGBREAK 1234
|
#define SIGBREAK 1234
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
typedef BOOL (*FSignalHandler)(DWORD fdwCtrlType);
|
||||||
|
#else
|
||||||
typedef void (*FSignalHandler)(int32_t signum, void *sigInfo, void *context);
|
typedef void (*FSignalHandler)(int32_t signum, void *sigInfo, void *context);
|
||||||
|
#endif
|
||||||
void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||||
void taosIgnSignal(int32_t signum);
|
void taosIgnSignal(int32_t signum);
|
||||||
void taosDflSignal(int32_t signum);
|
void taosDflSignal(int32_t signum);
|
||||||
|
|
|
@ -29,9 +29,6 @@ extern "C" {
|
||||||
#define tcgetattr TCGETATTR_FUNC_TAOS_FORBID
|
#define tcgetattr TCGETATTR_FUNC_TAOS_FORBID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TAOS_CONSOLE_PROMPT_HEADER "taos> "
|
|
||||||
#define TAOS_CONSOLE_PROMPT_CONTINUE " -> "
|
|
||||||
|
|
||||||
typedef struct TdCmd *TdCmdPtr;
|
typedef struct TdCmd *TdCmdPtr;
|
||||||
|
|
||||||
TdCmdPtr taosOpenCmd(const char* cmd);
|
TdCmdPtr taosOpenCmd(const char* cmd);
|
||||||
|
|
|
@ -18,10 +18,6 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#if defined(WINDOWS)
|
#if defined(WINDOWS)
|
||||||
BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) {
|
|
||||||
printf("\n" TAOS_CONSOLE_PROMPT_HEADER);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
#else
|
#else
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
@ -128,7 +124,6 @@ int taosSetConsoleEcho(bool on) {
|
||||||
|
|
||||||
void taosSetTerminalMode() {
|
void taosSetTerminalMode() {
|
||||||
#if defined(WINDOWS)
|
#if defined(WINDOWS)
|
||||||
SetConsoleCtrlHandler(CtrlHandler, TRUE);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
struct termios newtio;
|
struct termios newtio;
|
||||||
|
@ -179,7 +174,6 @@ int32_t taosGetOldTerminalMode() {
|
||||||
|
|
||||||
void taosResetTerminalMode() {
|
void taosResetTerminalMode() {
|
||||||
#if defined(WINDOWS)
|
#if defined(WINDOWS)
|
||||||
SetConsoleCtrlHandler(CtrlHandler, FALSE);
|
|
||||||
#else
|
#else
|
||||||
if (tcsetattr(0, TCSANOW, &oldtio) != 0) {
|
if (tcsetattr(0, TCSANOW, &oldtio) != 0) {
|
||||||
fprintf(stderr, "Fail to reset the terminal properties!\n");
|
fprintf(stderr, "Fail to reset the terminal properties!\n");
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
#include "shellInt.h"
|
#include "shellInt.h"
|
||||||
|
|
||||||
|
#define TAOS_CONSOLE_PROMPT_HEADER "taos> "
|
||||||
|
#define TAOS_CONSOLE_PROMPT_CONTINUE " -> "
|
||||||
|
|
||||||
#define SHELL_HOST "The auth string to use when connecting to the server."
|
#define SHELL_HOST "The auth string to use when connecting to the server."
|
||||||
#define SHELL_PORT "The TCP/IP port number to use for the connection."
|
#define SHELL_PORT "The TCP/IP port number to use for the connection."
|
||||||
#define SHELL_USER "The user name to use when connecting to the server."
|
#define SHELL_USER "The user name to use when connecting to the server."
|
||||||
|
|
|
@ -41,7 +41,7 @@ static void shellPrintError(TAOS_RES *tres, int64_t st);
|
||||||
static bool shellIsCommentLine(char *line);
|
static bool shellIsCommentLine(char *line);
|
||||||
static void shellSourceFile(const char *file);
|
static void shellSourceFile(const char *file);
|
||||||
static void shellGetGrantInfo();
|
static void shellGetGrantInfo();
|
||||||
static void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context);
|
|
||||||
static void shellCleanup(void *arg);
|
static void shellCleanup(void *arg);
|
||||||
static void *shellCancelHandler(void *arg);
|
static void *shellCancelHandler(void *arg);
|
||||||
static void *shellThreadLoop(void *arg);
|
static void *shellThreadLoop(void *arg);
|
||||||
|
@ -919,11 +919,14 @@ void shellGetGrantInfo() {
|
||||||
fprintf(stdout, "\r\n");
|
fprintf(stdout, "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { tsem_post(&shell.cancelSem); }
|
#ifdef WINDOWS
|
||||||
|
BOOL shellQueryInterruptHandler(DWORD fdwCtrlType) {
|
||||||
void shellSigintHandler(int32_t signum, void *sigInfo, void *context) {
|
tsem_post(&shell.cancelSem);
|
||||||
// do nothing
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { tsem_post(&shell.cancelSem); }
|
||||||
|
#endif
|
||||||
|
|
||||||
void shellCleanup(void *arg) { taosResetTerminalMode(); }
|
void shellCleanup(void *arg) { taosResetTerminalMode(); }
|
||||||
|
|
||||||
|
@ -934,11 +937,10 @@ void *shellCancelHandler(void *arg) {
|
||||||
taosMsleep(10);
|
taosMsleep(10);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
taos_kill_query(shell.conn);
|
||||||
taosResetTerminalMode();
|
#ifdef WINDOWS
|
||||||
printf("\r\nReceive SIGTERM or other signal, quit shell.\r\n");
|
printf("\n%s", shell.info.promptHeader);
|
||||||
shellWriteHistory();
|
#endif
|
||||||
shellExit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1022,7 +1024,7 @@ int32_t shellExecute() {
|
||||||
taosSetSignal(SIGHUP, shellQueryInterruptHandler);
|
taosSetSignal(SIGHUP, shellQueryInterruptHandler);
|
||||||
taosSetSignal(SIGABRT, shellQueryInterruptHandler);
|
taosSetSignal(SIGABRT, shellQueryInterruptHandler);
|
||||||
|
|
||||||
taosSetSignal(SIGINT, shellSigintHandler);
|
taosSetSignal(SIGINT, shellQueryInterruptHandler);
|
||||||
|
|
||||||
shellGetGrantInfo();
|
shellGetGrantInfo();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue