fix: refact shell arguments
This commit is contained in:
parent
cf433ec94c
commit
7d65802571
|
@ -505,6 +505,7 @@ static void dmCleanupServer(SDnode *pDnode) {
|
|||
int32_t dmInitTrans(SDnode *pDnode) {
|
||||
if (dmInitServer(pDnode) != 0) return -1;
|
||||
if (dmInitClient(pDnode) != 0) return -1;
|
||||
dmReportStartup(pDnode, "transport", "initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,10 +154,12 @@ static void dmGetServerStatus(SDnode *pDnode, SServerStatusRsp *pStatus) {
|
|||
if (pStatus->statusCode == TSDB_SRV_STATUS_NETWORK_OK) {
|
||||
SStartupInfo *pStartup = &pDnode->startup;
|
||||
|
||||
int32_t len = strlen(pStartup->name) + strlen(pStartup->desc) + 24;
|
||||
pStatus->details = taosMemoryCalloc(1, len);
|
||||
int32_t len = strlen(pStartup->name) + strlen(pStartup->desc);
|
||||
if (len > 0) {
|
||||
pStatus->details = taosMemoryCalloc(1, len + 24);
|
||||
if (pStatus->details != NULL) {
|
||||
pStatus->detailLen = snprintf(pStatus->details, len - 1, "%s: %s", pStartup->name, pStartup->desc) + 1;
|
||||
pStatus->detailLen = snprintf(pStatus->details, len + 20, "%s: %s", pStartup->name, pStartup->desc) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -531,10 +531,10 @@ void showOnScreen(Command *cmd) {
|
|||
void cleanup_handler(void *arg) { resetTerminalMode(); }
|
||||
|
||||
void exitShell() {
|
||||
/*int32_t ret =*/resetTerminalMode();
|
||||
taos_cleanup();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { tsem_post(&cancelSem); }
|
||||
|
||||
void *cancelHandler(void *arg) {
|
||||
|
@ -546,21 +546,9 @@ void *cancelHandler(void *arg) {
|
|||
continue;
|
||||
}
|
||||
|
||||
#ifdef LINUX
|
||||
#if 0
|
||||
int64_t rid = atomic_val_compare_exchange_64(&result, result, 0);
|
||||
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
|
||||
taos_stop_query(pSql);
|
||||
taosReleaseRef(tscObjRef, rid);
|
||||
#endif
|
||||
#else
|
||||
resetTerminalMode();
|
||||
printf("\nReceive ctrl+c or other signal, quit shell.\n");
|
||||
exit(0);
|
||||
#endif
|
||||
resetTerminalMode();
|
||||
printf("\nReceive ctrl+c or other signal, quit shell.\n");
|
||||
exit(0);
|
||||
exitShell();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -587,10 +575,8 @@ int checkVersion() {
|
|||
}
|
||||
|
||||
// Global configurations
|
||||
SShellArguments args = {.host = NULL,
|
||||
#ifndef TD_WINDOWS
|
||||
.password = NULL,
|
||||
#endif
|
||||
SShellArguments args = {
|
||||
.host = NULL,
|
||||
.user = NULL,
|
||||
.database = NULL,
|
||||
.timezone = NULL,
|
||||
|
@ -604,35 +590,38 @@ SShellArguments args = {.host = NULL,
|
|||
.pktLen = 1000,
|
||||
.pktNum = 100,
|
||||
.pktType = "TCP",
|
||||
.netTestRole = NULL};
|
||||
.netTestRole = NULL,
|
||||
#ifndef TD_WINDOWS
|
||||
.password = NULL,
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* Main function.
|
||||
*/
|
||||
int main(int argc, char *argv[]) {
|
||||
/*setlocale(LC_ALL, "en_US.UTF-8"); */
|
||||
void shellDumpConfig() {
|
||||
if (!args.dump_config) return;
|
||||
|
||||
if (!checkVersion()) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
shellParseArgument(argc, argv, &args);
|
||||
taos_init();
|
||||
|
||||
if (args.dump_config) {
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
if (NULL == pCfg) {
|
||||
printf("TDengine read global config failed!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
cfgDumpCfg(pCfg, 0, 1);
|
||||
exit(0);
|
||||
exitShell();
|
||||
}
|
||||
|
||||
if (args.status || args.verbose) {
|
||||
void shellTestNetWork() {
|
||||
if (args.netTestRole && args.netTestRole[0] != 0) {
|
||||
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType);
|
||||
exitShell();
|
||||
}
|
||||
}
|
||||
|
||||
void shellCheckServerStatus() {
|
||||
if (!args.status && !args.verbose) return;
|
||||
char details[1024] = {0};
|
||||
|
||||
TSDB_SERVER_STATUS code = taos_check_server_status(args.host, args.port, details, args.verbose ? 1024 : 0);
|
||||
TSDB_SERVER_STATUS code;
|
||||
do {
|
||||
code = taos_check_server_status(args.host, args.port, details, args.verbose ? 1024 : 0);
|
||||
switch (code) {
|
||||
case TSDB_SRV_STATUS_UNAVAILABLE:
|
||||
printf("0: unavailable\n");
|
||||
|
@ -650,44 +639,54 @@ int main(int argc, char *argv[]) {
|
|||
printf("4: exiting\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (strlen(details) != 0) {
|
||||
printf("detail info:\n%s\n", details);
|
||||
printf("%s\n\n", details);
|
||||
}
|
||||
exit(0);
|
||||
if (code == TSDB_SRV_STATUS_NETWORK_OK) {
|
||||
taosMsleep(1000);
|
||||
}
|
||||
} while (code == TSDB_SRV_STATUS_NETWORK_OK);
|
||||
|
||||
exitShell();
|
||||
}
|
||||
|
||||
if (args.netTestRole && args.netTestRole[0] != 0) {
|
||||
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Initialize the shell */
|
||||
void shellExecute() {
|
||||
TAOS *con = shellInit(&args);
|
||||
if (con == NULL) {
|
||||
exit(EXIT_FAILURE);
|
||||
exitShell();
|
||||
}
|
||||
|
||||
if (tsem_init(&cancelSem, 0, 0) != 0) {
|
||||
printf("failed to create cancel semphore\n");
|
||||
exit(EXIT_FAILURE);
|
||||
exitShell();
|
||||
}
|
||||
|
||||
TdThread spid;
|
||||
taosThreadCreate(&spid, NULL, cancelHandler, NULL);
|
||||
|
||||
/* Interrupt handler. */
|
||||
taosSetSignal(SIGTERM, shellQueryInterruptHandler);
|
||||
taosSetSignal(SIGINT, shellQueryInterruptHandler);
|
||||
taosSetSignal(SIGHUP, shellQueryInterruptHandler);
|
||||
taosSetSignal(SIGABRT, shellQueryInterruptHandler);
|
||||
|
||||
/* Get grant information */
|
||||
shellGetGrantInfo(con);
|
||||
|
||||
/* Loop to query the input. */
|
||||
while (1) {
|
||||
taosThreadCreate(&pid, NULL, shellLoopQuery, con);
|
||||
taosThreadJoin(pid, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (!checkVersion()) exitShell();
|
||||
|
||||
shellParseArgument(argc, argv, &args);
|
||||
|
||||
taos_init();
|
||||
shellDumpConfig();
|
||||
shellCheckServerStatus();
|
||||
shellTestNetWork();
|
||||
shellExecute();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue