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

taosdata / TDengine / #4829

30 Oct 2025 09:25AM UTC coverage: 49.734% (-11.3%) from 61.071%
#4829

push

travis-ci

web-flow
Merge pull request #33435 from taosdata/3.0

merge 3.0

123072 of 323930 branches covered (37.99%)

Branch coverage included in aggregate %.

7 of 25 new or added lines in 3 files covered. (28.0%)

35232 existing lines in 327 files now uncovered.

172062 of 269495 relevant lines covered (63.85%)

70709785.06 hits per line

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

28.76
/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) {
30,142,752✔
24
  regex_t regex = {0};
30,142,752✔
25
  char    msgbuf[100] = {0};
30,142,752✔
26

27
  /* Compile regular expression */
28
  if (regcomp(&regex, reg, cflags) != 0) {
30,142,752!
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);
30,142,752✔
35
  if (!reti) {
30,142,752✔
36
    regfree(&regex);
2,035✔
37
    return true;
2,035✔
38
  } else if (reti == REG_NOMATCH) {
30,140,717!
39
    regfree(&regex);
30,140,717✔
40
    return false;
30,140,717✔
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() {
1,325,886✔
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;
1,325,886✔
69
}
70

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

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

80
void shellDumpConfig() {
27✔
81
  (void)osDefaultInit();
27✔
82

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

88
  cfgDumpCfg(taosGetCfg(), 1, true);
27✔
89

90
  fflush(stdout);
27✔
91
}
92

93
void shellCheckServerStatus() {
702✔
94
  TSDB_SERVER_STATUS code;
95

96
  do {
×
97
    char details[1024] = {0};
702✔
98
    code = taos_check_server_status(shell.args.host, shell.args.port, details, 1024);
702✔
99
    switch (code) {
702!
100
      case TSDB_SRV_STATUS_UNAVAILABLE:
225✔
101
        printf("0: unavailable\r\n");
225!
102
        break;
225✔
103
      case TSDB_SRV_STATUS_NETWORK_OK:
×
104
        printf("1: network ok\r\n");
×
105
        break;
×
106
      case TSDB_SRV_STATUS_SERVICE_OK:
477✔
107
        printf("2: service ok\r\n");
477!
108
        break;
477✔
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) {
702!
117
      printf("%s\r\n\r\n", details);
×
118
    }
119
    fflush(stdout);
702✔
120
    if (code == TSDB_SRV_STATUS_NETWORK_OK && shell.args.is_startup) {
702!
121
      taosMsleep(1000);
×
122
    } else {
123
      break;
124
    }
125
  } while (1);
126
}
702✔
127

UNCOV
128
void shellExit() {
×
UNCOV
129
  if (shell.conn != NULL) {
×
UNCOV
130
    taos_close(shell.conn);
×
UNCOV
131
    shell.conn = NULL;
×
132
  }
UNCOV
133
  shell.exit = true;
×
UNCOV
134
  taos_cleanup();
×
UNCOV
135
}
×
136

UNCOV
137
void trimStr(char *srcInfo, char *removeStr) {
×
UNCOV
138
    if (srcInfo == NULL || removeStr == NULL) return;
×
139

UNCOV
140
    int len = strlen(srcInfo);
×
UNCOV
141
    int new_len = len;
×
142
    
UNCOV
143
    int remove_len = strlen(removeStr);
×
144

UNCOV
145
    while (new_len > 0) {
×
UNCOV
146
        if (isspace(srcInfo[new_len - 1])) {
×
UNCOV
147
            srcInfo[--new_len] = '\0';
×
UNCOV
148
            continue;
×
149
        }
150
        
UNCOV
151
        if (new_len >= remove_len && strncmp(srcInfo + new_len - remove_len, removeStr, remove_len) == 0) {
×
UNCOV
152
            new_len -= remove_len;
×
UNCOV
153
            srcInfo[new_len] = '\0';
×
UNCOV
154
            continue;
×
155
        }
156
        
UNCOV
157
        break;
×
158
    }
159
}
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