move signal handle to thread
This commit is contained in:
parent
fce7a9d299
commit
b157f711f4
|
@ -260,6 +260,14 @@ int32_t shellRunCommand(TAOS* con, char* command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void freeResultWithRid(int64_t rid) {
|
||||||
|
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
|
||||||
|
if(pSql){
|
||||||
|
taos_free_result(pSql);
|
||||||
|
taosReleaseRef(tscObjRef, rid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void shellRunCommandOnServer(TAOS *con, char command[]) {
|
void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
int64_t st, et;
|
int64_t st, et;
|
||||||
wordexp_t full_path;
|
wordexp_t full_path;
|
||||||
|
@ -301,14 +309,15 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = ((SSqlObj*)tmpSql)->self;
|
atomic_store_64(&result, ((SSqlObj*)tmpSql)->self);
|
||||||
|
int64_t oresult = atomic_load_64(&result);
|
||||||
|
|
||||||
if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
|
if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
|
||||||
fprintf(stdout, "Database changed.\n\n");
|
fprintf(stdout, "Database changed.\n\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
atomic_store_64(&result, 0);
|
atomic_store_64(&result, 0);
|
||||||
taos_free_result(pSql);
|
freeResultWithRid(oresult);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +326,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
|
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
|
||||||
if (numOfRows < 0) {
|
if (numOfRows < 0) {
|
||||||
atomic_store_64(&result, 0);
|
atomic_store_64(&result, 0);
|
||||||
taos_free_result(pSql);
|
freeResultWithRid(oresult);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +349,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_store_64(&result, 0);
|
atomic_store_64(&result, 0);
|
||||||
taos_free_result(pSql);
|
freeResultWithRid(oresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function to do regular expression check */
|
/* Function to do regular expression check */
|
||||||
|
|
|
@ -19,17 +19,31 @@
|
||||||
#include "tnettest.h"
|
#include "tnettest.h"
|
||||||
|
|
||||||
pthread_t pid;
|
pthread_t pid;
|
||||||
|
static tsem_t cancelSem;
|
||||||
|
|
||||||
void shellQueryInterruptHandler(int signum) {
|
void shellQueryInterruptHandler(int signum) {
|
||||||
|
tsem_post(&cancelSem);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *cancelHandler(void *arg) {
|
||||||
|
while(1) {
|
||||||
|
if (tsem_wait(&cancelSem) != 0) {
|
||||||
|
taosMsleep(10);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
int64_t rid = atomic_val_compare_exchange_64(&result, result, 0);
|
int64_t rid = atomic_val_compare_exchange_64(&result, result, 0);
|
||||||
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
|
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
|
||||||
taos_stop_query(pSql);
|
taos_stop_query(pSql);
|
||||||
taosReleaseRef(tscObjRef, rid);
|
taosReleaseRef(tscObjRef, rid);
|
||||||
#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);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkVersion() {
|
int checkVersion() {
|
||||||
|
@ -107,6 +121,14 @@ int main(int argc, char* argv[]) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tsem_init(&cancelSem, 0, 0) != 0) {
|
||||||
|
printf("failed to create cancel semphore\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_t spid;
|
||||||
|
pthread_create(&spid, NULL, cancelHandler, NULL);
|
||||||
|
|
||||||
/* Interrupt handler. */
|
/* Interrupt handler. */
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
memset(&act, 0, sizeof(struct sigaction));
|
memset(&act, 0, sizeof(struct sigaction));
|
||||||
|
|
Loading…
Reference in New Issue