提交 2ad31334 编写于 作者: H Haojun Liao

[td-225] refactor shell code.

上级 3ff538c6
......@@ -284,7 +284,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
st = taosGetTimestampUs();
TAOS_RES* pSql = taos_query(con, command);
result = pSql; // set it into the global variable
atomic_store_ptr(&result, pSql); // set the global TAOS_RES pointer
if (taos_errno(pSql)) {
taos_error(pSql);
......@@ -295,7 +295,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
fprintf(stdout, "Database changed.\n\n");
fflush(stdout);
result = NULL;
atomic_store_ptr(&result, 0);
taos_free_result(pSql);
return;
}
......@@ -304,7 +304,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
int error_no = 0;
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
if (numOfRows < 0) {
result = NULL;
atomic_store_ptr(&result, 0);
taos_free_result(pSql);
return;
}
......@@ -327,7 +327,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
wordfree(&full_path);
}
result = NULL;
atomic_store_ptr(&result, 0);
taos_free_result(pSql);
}
......@@ -493,7 +493,6 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
} while( row != NULL);
result = NULL;
//taos_free_result(tres);
fclose(fp);
return numOfRows;
......@@ -798,8 +797,8 @@ void write_history() {
}
void taos_error(TAOS_RES *tres) {
atomic_store_ptr(&result, 0);
fprintf(stderr, "\nDB error: %s\n", taos_errstr(tres));
result = NULL;
taos_free_result(tres);
}
......
......@@ -18,11 +18,10 @@
pthread_t pid;
// TODO: IMPLEMENT INTERRUPT HANDLER.
void interruptHandler(int signum) {
void shellQueryInterruptHandler(int signum) {
#ifdef LINUX
taos_stop_query(result);
result = NULL;
void* pResHandle = atomic_val_compare_exchange_64(&result, result, 0);
taos_stop_query(pResHandle);
#else
printf("\nReceive ctrl+c or other signal, quit shell.\n");
exit(0);
......@@ -86,7 +85,7 @@ int main(int argc, char* argv[]) {
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = interruptHandler;
act.sa_handler = shellQueryInterruptHandler;
sigaction(SIGTERM, &act, NULL);
sigaction(SIGINT, &act, NULL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册