refactor(tools): refact shell codes

This commit is contained in:
Shengliang Guan 2022-04-21 21:29:21 +08:00
parent bce784ab51
commit c92b3ce226
5 changed files with 11 additions and 5 deletions

View File

@ -97,6 +97,7 @@ void shellGenerateAuth();
void shellDumpConfig();
void shellCheckServerStatus();
bool shellRegexMatch(const char* s, const char* reg, int32_t cflags);
void shellExit();
// shellNettest.c
void shellTestNetWork();

View File

@ -278,7 +278,7 @@ static struct argp shellArgp = {shellOptions, shellParseOpt, "", ""};
static void shellParseArgsInLinux(int argc, char *argv[]) {
argp_program_version = shell.info.programVersion;
argp_parse(&shellArgp, argc, argv, 0, 0, NULL);
argp_parse(&shellArgp, argc, argv, 0, 0, &shell.args);
}
#endif

View File

@ -907,6 +907,8 @@ void *shellThreadLoop(void *arg) {
} while (shellRunCommand(command) == 0);
taosMemoryFreeClear(command);
// shellExit();
taosThreadCleanupPop(1);
return NULL;
}

View File

@ -56,7 +56,8 @@ int main(int argc, char *argv[]) {
return 0;
}
if (strcmp(shell.args.netrole, "client") == 0 || strcmp(shell.args.netrole, "server") == 0) {
if (shell.args.netrole != NULL &&
(strcmp(shell.args.netrole, "client") == 0 || strcmp(shell.args.netrole, "server")) == 0) {
shellTestNetWork();
taos_cleanup();
return 0;

View File

@ -21,13 +21,13 @@
#include "shellInt.h"
bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) {
regex_t regex;
regex_t regex = {0};
char msgbuf[100] = {0};
/* Compile regular expression */
if (regcomp(&regex, reg, cflags) != 0) {
fprintf(stderr, "Fail to compile regex");
return false;
shellExit();
}
/* Execute regular expression */
@ -42,7 +42,7 @@ bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) {
regerror(reti, &regex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s\n", msgbuf);
regfree(&regex);
return false;
shellExit();
}
return false;
@ -114,3 +114,5 @@ void shellCheckServerStatus() {
}
} while (1);
}
void shellExit() { exit(EXIT_FAILURE); }