提交 c92b3ce2 编写于 作者: S Shengliang Guan

refactor(tools): refact shell codes

上级 bce784ab
...@@ -97,6 +97,7 @@ void shellGenerateAuth(); ...@@ -97,6 +97,7 @@ void shellGenerateAuth();
void shellDumpConfig(); void shellDumpConfig();
void shellCheckServerStatus(); void shellCheckServerStatus();
bool shellRegexMatch(const char* s, const char* reg, int32_t cflags); bool shellRegexMatch(const char* s, const char* reg, int32_t cflags);
void shellExit();
// shellNettest.c // shellNettest.c
void shellTestNetWork(); void shellTestNetWork();
......
...@@ -278,7 +278,7 @@ static struct argp shellArgp = {shellOptions, shellParseOpt, "", ""}; ...@@ -278,7 +278,7 @@ static struct argp shellArgp = {shellOptions, shellParseOpt, "", ""};
static void shellParseArgsInLinux(int argc, char *argv[]) { static void shellParseArgsInLinux(int argc, char *argv[]) {
argp_program_version = shell.info.programVersion; argp_program_version = shell.info.programVersion;
argp_parse(&shellArgp, argc, argv, 0, 0, NULL); argp_parse(&shellArgp, argc, argv, 0, 0, &shell.args);
} }
#endif #endif
......
...@@ -907,6 +907,8 @@ void *shellThreadLoop(void *arg) { ...@@ -907,6 +907,8 @@ void *shellThreadLoop(void *arg) {
} while (shellRunCommand(command) == 0); } while (shellRunCommand(command) == 0);
taosMemoryFreeClear(command); taosMemoryFreeClear(command);
// shellExit();
taosThreadCleanupPop(1); taosThreadCleanupPop(1);
return NULL; return NULL;
} }
......
...@@ -56,7 +56,8 @@ int main(int argc, char *argv[]) { ...@@ -56,7 +56,8 @@ int main(int argc, char *argv[]) {
return 0; 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(); shellTestNetWork();
taos_cleanup(); taos_cleanup();
return 0; return 0;
......
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
#include "shellInt.h" #include "shellInt.h"
bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) { bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) {
regex_t regex; regex_t regex = {0};
char msgbuf[100] = {0}; char msgbuf[100] = {0};
/* Compile regular expression */ /* Compile regular expression */
if (regcomp(&regex, reg, cflags) != 0) { if (regcomp(&regex, reg, cflags) != 0) {
fprintf(stderr, "Fail to compile regex"); fprintf(stderr, "Fail to compile regex");
return false; shellExit();
} }
/* Execute regular expression */ /* Execute regular expression */
...@@ -42,7 +42,7 @@ bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) { ...@@ -42,7 +42,7 @@ bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) {
regerror(reti, &regex, msgbuf, sizeof(msgbuf)); regerror(reti, &regex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s\n", msgbuf); fprintf(stderr, "Regex match failed: %s\n", msgbuf);
regfree(&regex); regfree(&regex);
return false; shellExit();
} }
return false; return false;
...@@ -114,3 +114,5 @@ void shellCheckServerStatus() { ...@@ -114,3 +114,5 @@ void shellCheckServerStatus() {
} }
} while (1); } while (1);
} }
void shellExit() { exit(EXIT_FAILURE); }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册