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

[td-225] refactor shell code.

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