• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3798

31 Mar 2025 10:39AM UTC coverage: 9.424% (-20.9%) from 30.372%
#3798

push

travis-ci

happyguoxy
test:add test cases

21549 of 307601 branches covered (7.01%)

Branch coverage included in aggregate %.

36084 of 303967 relevant lines covered (11.87%)

58620.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.73
/tools/shell/src/shellUtil.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _BSD_SOURCE
17
#define _GNU_SOURCE
18
#define _XOPEN_SOURCE
19
#define _DEFAULT_SOURCE
20

21
#include "shellInt.h"
22

23
bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) {
755✔
24
  regex_t regex = {0};
755✔
25
  char    msgbuf[100] = {0};
755✔
26

27
  /* Compile regular expression */
28
  if (regcomp(&regex, reg, cflags) != 0) {
755!
29
    fprintf(stderr, "Fail to compile regex");
×
30
    shellExit();
×
31
  }
32

33
  /* Execute regular expression */
34
  int32_t reti = regexec(&regex, s, 0, NULL, 0);
755✔
35
  if (!reti) {
755!
36
    regfree(&regex);
×
37
    return true;
×
38
  } else if (reti == REG_NOMATCH) {
755!
39
    regfree(&regex);
755✔
40
    return false;
755✔
41
  } else {
42
    regerror(reti, &regex, msgbuf, sizeof(msgbuf));
×
43
    fprintf(stderr, "Regex match failed: %s\r\n", msgbuf);
×
44
    regfree(&regex);
×
45
    shellExit();
×
46
  }
47

48
  return false;
×
49
}
50

51
int32_t shellCheckIntSize() {
4✔
52
  if (sizeof(int8_t) != 1) {
53
    printf("int8 size is %d(!= 1)\r\n", (int)sizeof(int8_t));
54
    return -1;
55
  }
56
  if (sizeof(int16_t) != 2) {
57
    printf("int16 size is %d(!= 2)\r\n", (int)sizeof(int16_t));
58
    return -1;
59
  }
60
  if (sizeof(int32_t) != 4) {
61
    printf("int32 size is %d(!= 4)\r\n", (int)sizeof(int32_t));
62
    return -1;
63
  }
64
  if (sizeof(int64_t) != 8) {
65
    printf("int64 size is %d(!= 8)\r\n", (int)sizeof(int64_t));
66
    return -1;
67
  }
68
  return 0;
4✔
69
}
70

71
void shellPrintVersion() { printf("%s\r\n", shell.info.programVersion); }
×
72

73
void shellGenerateAuth() {
×
74
  char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0};
×
75
  taosEncryptPass_c((uint8_t *)shell.args.password, strlen(shell.args.password), secretEncrypt);
×
76
  printf("%s\r\n", secretEncrypt);
×
77
  fflush(stdout);
×
78
}
×
79

80
void shellDumpConfig() {
×
81
  (void)osDefaultInit();
×
82

83
  if (taosInitCfg(configDirShell, NULL, NULL, NULL, NULL, 1) != 0) {
×
84
    fprintf(stderr, "failed to load cfg since %s [0x%08X]\n", terrstr(), terrno);
×
85
    return;
×
86
  }
87

88
  cfgDumpCfg(taosGetCfg(), 1, true);
×
89

90
  fflush(stdout);
×
91
}
92

93
void shellCheckServerStatus() {
×
94
  TSDB_SERVER_STATUS code;
95

96
  do {
×
97
    char details[1024] = {0};
×
98
    code = taos_check_server_status(shell.args.host, shell.args.port, details, 1024);
×
99
    switch (code) {
×
100
      case TSDB_SRV_STATUS_UNAVAILABLE:
×
101
        printf("0: unavailable\r\n");
×
102
        break;
×
103
      case TSDB_SRV_STATUS_NETWORK_OK:
×
104
        printf("1: network ok\r\n");
×
105
        break;
×
106
      case TSDB_SRV_STATUS_SERVICE_OK:
×
107
        printf("2: service ok\r\n");
×
108
        break;
×
109
      case TSDB_SRV_STATUS_SERVICE_DEGRADED:
×
110
        printf("3: service degraded\r\n");
×
111
        break;
×
112
      case TSDB_SRV_STATUS_EXTING:
×
113
        printf("4: exiting\r\n");
×
114
        break;
×
115
    }
116
    if (strlen(details) != 0) {
×
117
      printf("%s\r\n\r\n", details);
×
118
    }
119
    fflush(stdout);
×
120
    if (code == TSDB_SRV_STATUS_NETWORK_OK && shell.args.is_startup) {
×
121
      taosMsleep(1000);
×
122
    } else {
123
      break;
124
    }
125
  } while (1);
126
}
×
127

128
void shellExit() {
×
129
  if (shell.conn != NULL) {
×
130
    taos_close(shell.conn);
×
131
    shell.conn = NULL;
×
132
  }
133
  shell.exit = true;
×
134
  taos_cleanup();
×
135
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc