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

#define _DEFAULT_SOURCE
#include "os.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#include "tsocket.h"
#include "tutil.h"

S
Shuduo Sang 已提交
26
SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}};
S
slguan 已提交
27 28
int32_t    tsGlobalConfigNum = 0;

wmmhello's avatar
wmmhello 已提交
29 30 31 32 33
#define ATOI_JUDGE if ( !value && strcmp(input_value, "0") != 0) { \
                      uError("atoi error, input value:%s",input_value); \
                      return false; \
                    }

S
slguan 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
static char *tsGlobalUnit[] = {
  " ", 
  "(%)", 
  "(GB)", 
  "(Mb)", 
  "(byte)", 
  "(s)", 
  "(ms)"
};

char *tsCfgStatusStr[] = {
  "none", 
  "system default", 
  "config file", 
  "taos_options", 
  "program argument list"
};

wmmhello's avatar
wmmhello 已提交
52
static bool taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) {
S
slguan 已提交
53
  float  value = (float)atof(input_value);
wmmhello's avatar
wmmhello 已提交
54
  ATOI_JUDGE
S
slguan 已提交
55 56 57 58
  float *option = (float *)cfg->ptr;
  if (value < cfg->minValue || value > cfg->maxValue) {
    uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f",
           cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
wmmhello's avatar
wmmhello 已提交
59
    return false;
S
slguan 已提交
60 61 62 63 64 65 66
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      *option = value;
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
      uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value,
            tsCfgStatusStr[cfg->cfgStatus], *option);
wmmhello's avatar
wmmhello 已提交
67
      return false;
S
slguan 已提交
68 69
    }
  }
wmmhello's avatar
wmmhello 已提交
70
  return true;
S
slguan 已提交
71 72
}

wmmhello's avatar
wmmhello 已提交
73
static bool taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) {
T
tickduan 已提交
74
  double  value = atof(input_value);
wmmhello's avatar
wmmhello 已提交
75
  ATOI_JUDGE
T
tickduan 已提交
76 77 78 79
  double *option = (double *)cfg->ptr;
  if (value < cfg->minValue || value > cfg->maxValue) {
    uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f",
           cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
wmmhello's avatar
wmmhello 已提交
80
    return false;
T
tickduan 已提交
81 82 83 84 85 86 87
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      *option = value;
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
      uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value,
            tsCfgStatusStr[cfg->cfgStatus], *option);
wmmhello's avatar
wmmhello 已提交
88
      return false;
T
tickduan 已提交
89 90
    }
  }
wmmhello's avatar
wmmhello 已提交
91
  return true;
T
tickduan 已提交
92 93 94
}


wmmhello's avatar
wmmhello 已提交
95
static bool taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
S
slguan 已提交
96
  int32_t  value = atoi(input_value);
wmmhello's avatar
wmmhello 已提交
97
  ATOI_JUDGE
S
slguan 已提交
98 99 100 101
  int32_t *option = (int32_t *)cfg->ptr;
  if (value < cfg->minValue || value > cfg->maxValue) {
    uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
           cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
wmmhello's avatar
wmmhello 已提交
102
    return false;
S
slguan 已提交
103 104 105 106 107
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      *option = value;
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
H
Hui Li 已提交
108
      uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
S
slguan 已提交
109
            tsCfgStatusStr[cfg->cfgStatus], *option);
wmmhello's avatar
wmmhello 已提交
110
      return false;
S
slguan 已提交
111 112
    }
  }
wmmhello's avatar
wmmhello 已提交
113
  return true;
S
slguan 已提交
114 115
}

wmmhello's avatar
wmmhello 已提交
116
static bool taosReadInt16Config(SGlobalCfg *cfg, char *input_value) {
S
slguan 已提交
117
  int32_t  value = atoi(input_value);
wmmhello's avatar
wmmhello 已提交
118
  ATOI_JUDGE
S
slguan 已提交
119 120 121 122
  int16_t *option = (int16_t *)cfg->ptr;
  if (value < cfg->minValue || value > cfg->maxValue) {
    uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
           cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
wmmhello's avatar
wmmhello 已提交
123
    return false;
S
slguan 已提交
124 125 126 127 128 129 130
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      *option = (int16_t)value;
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
      uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
            tsCfgStatusStr[cfg->cfgStatus], *option);
wmmhello's avatar
wmmhello 已提交
131
      return false;
S
slguan 已提交
132 133
    }
  }
wmmhello's avatar
wmmhello 已提交
134
  return true;
S
slguan 已提交
135 136
}

wmmhello's avatar
wmmhello 已提交
137
static bool taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) {
138
  int32_t  value = atoi(input_value);
wmmhello's avatar
wmmhello 已提交
139
  ATOI_JUDGE
140 141 142 143
  uint16_t *option = (uint16_t *)cfg->ptr;
  if (value < cfg->minValue || value > cfg->maxValue) {
    uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
           cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
wmmhello's avatar
wmmhello 已提交
144
    return false;
145 146 147 148 149 150 151
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      *option = (uint16_t)value;
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
      uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
            tsCfgStatusStr[cfg->cfgStatus], *option);
wmmhello's avatar
wmmhello 已提交
152
      return false;
153 154
    }
  }
wmmhello's avatar
wmmhello 已提交
155
  return true;
156 157
}

wmmhello's avatar
wmmhello 已提交
158
static bool taosReadInt8Config(SGlobalCfg *cfg, char *input_value) {
S
Shengliang Guan 已提交
159
  int32_t  value = atoi(input_value);
wmmhello's avatar
wmmhello 已提交
160
  ATOI_JUDGE
S
Shengliang Guan 已提交
161 162 163 164
  int8_t *option = (int8_t *)cfg->ptr;
  if (value < cfg->minValue || value > cfg->maxValue) {
    uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
           cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
wmmhello's avatar
wmmhello 已提交
165
    return false;
S
Shengliang Guan 已提交
166 167 168 169 170 171 172
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      *option = (int8_t)value;
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
      uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
            tsCfgStatusStr[cfg->cfgStatus], *option);
wmmhello's avatar
wmmhello 已提交
173
      return false;
S
Shengliang Guan 已提交
174 175
    }
  }
wmmhello's avatar
wmmhello 已提交
176
  return true;
S
Shengliang Guan 已提交
177 178
}

H
Hongze Cheng 已提交
179
static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
S
TD-1037  
Shengliang Guan 已提交
180
  int   length = (int)strlen(input_value);
S
slguan 已提交
181 182
  char *option = (char *)cfg->ptr;
  if (length <= 0 || length > cfg->ptrLength) {
S
TD-1767  
Shengliang Guan 已提交
183 184 185
    uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", cfg->option,
           input_value, cfg->ptrLength, option);
    return false;
S
slguan 已提交
186 187 188
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      wordexp_t full_path;
H
Hui Li 已提交
189 190 191
      if (0 != wordexp(input_value, &full_path, 0)) {
        printf("\nconfig dir: %s wordexp fail! reason:%s\n", input_value, strerror(errno));
        wordfree(&full_path);
S
TD-1767  
Shengliang Guan 已提交
192
        return false;
H
Hui Li 已提交
193
      }
S
TD-1767  
Shengliang Guan 已提交
194

S
slguan 已提交
195 196 197
      if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
        strcpy(option, full_path.we_wordv[0]);
      }
S
TD-1767  
Shengliang Guan 已提交
198

S
slguan 已提交
199 200
      wordfree(&full_path);

201
      char tmp[PATH_MAX] = {0};
S
TD-1207  
Shengliang Guan 已提交
202 203 204 205
      if (realpath(option, tmp) != NULL) {
        strcpy(option, tmp);
      }

S
Shengliang Guan 已提交
206
      int code = taosMkDir(option, 0755);
H
Hui Li 已提交
207 208
      if (code != 0) {
        terrno = TAOS_SYSTEM_ERROR(errno);
S
TD-1767  
Shengliang Guan 已提交
209 210 211
        uError("config option:%s, input value:%s, directory not exist, create fail:%s", cfg->option, input_value,
               strerror(errno));
        return false;
S
slguan 已提交
212 213 214 215 216 217 218
      }
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
      uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
            tsCfgStatusStr[cfg->cfgStatus], option);
    }
  }
S
TD-1767  
Shengliang Guan 已提交
219 220

  return true;
S
slguan 已提交
221 222
}

wmmhello's avatar
wmmhello 已提交
223
static bool taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) {
224
  uint32_t value = taosInetAddr(input_value);
S
slguan 已提交
225 226 227 228
  char *   option = (char *)cfg->ptr;
  if (value == INADDR_NONE) {
    uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s",
           cfg->option, input_value, option);
wmmhello's avatar
wmmhello 已提交
229
    return false;
S
slguan 已提交
230 231 232 233 234 235 236
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      strncpy(option, input_value, cfg->ptrLength);
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
      uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
            tsCfgStatusStr[cfg->cfgStatus], option);
wmmhello's avatar
wmmhello 已提交
237
      return false;
S
slguan 已提交
238 239
    }
  }
wmmhello's avatar
wmmhello 已提交
240
  return true;
S
slguan 已提交
241 242
}

wmmhello's avatar
wmmhello 已提交
243
static bool taosReadStringConfig(SGlobalCfg *cfg, char *input_value) {
S
TD-1037  
Shengliang Guan 已提交
244
  int   length = (int) strlen(input_value);
S
slguan 已提交
245 246 247 248
  char *option = (char *)cfg->ptr;
  if (length <= 0 || length > cfg->ptrLength) {
    uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s",
           cfg->option, input_value, cfg->ptrLength, option);
wmmhello's avatar
wmmhello 已提交
249
    return false;
S
slguan 已提交
250 251 252 253 254 255 256
  } else {
    if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
      strncpy(option, input_value, cfg->ptrLength);
      cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
    } else {
      uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
            tsCfgStatusStr[cfg->cfgStatus], option);
wmmhello's avatar
wmmhello 已提交
257
      return false;
S
slguan 已提交
258 259
    }
  }
wmmhello's avatar
wmmhello 已提交
260
  return true;
S
slguan 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
}

static void taosReadLogOption(char *option, char *value) {
  for (int i = 0; i < tsGlobalConfigNum; ++i) {
    SGlobalCfg *cfg = tsGlobalConfig + i;
    if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG) || !(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue;
    if (strcasecmp(cfg->option, option) != 0) continue;

    switch (cfg->valType) {
      case TAOS_CFG_VTYPE_INT32:
        taosReadInt32Config(cfg, value);
        if (strcasecmp(cfg->option, "debugFlag") == 0) {
          taosSetAllDebugFlag();
        }
        break;
      case TAOS_CFG_VTYPE_DIRECTORY:
        taosReadDirectoryConfig(cfg, value);
        break;
      default:
        break;
    }
    break;
  }
}

SGlobalCfg *taosGetConfigOption(const char *option) {
S
slguan 已提交
287
  taosInitGlobalCfg();
S
slguan 已提交
288 289 290 291 292 293 294 295
  for (int i = 0; i < tsGlobalConfigNum; ++i) {
    SGlobalCfg *cfg = tsGlobalConfig + i;
    if (strcasecmp(cfg->option, option) != 0) continue;
    return cfg;
  }
  return NULL;
}

wmmhello's avatar
wmmhello 已提交
296
bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3,
wmmhello's avatar
wmmhello 已提交
297
                          int8_t cfgStatus, int8_t sourceType) {
wmmhello's avatar
wmmhello 已提交
298
  bool ret = false;
S
slguan 已提交
299 300 301
  for (int i = 0; i < tsGlobalConfigNum; ++i) {
    SGlobalCfg *cfg = tsGlobalConfig + i;
    if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue;
wmmhello's avatar
wmmhello 已提交
302
    if (sourceType != 0 && !(cfg->cfgType & sourceType)) continue;
S
slguan 已提交
303 304 305
    if (strcasecmp(cfg->option, option) != 0) continue;

    switch (cfg->valType) {
S
Shengliang Guan 已提交
306
      case TAOS_CFG_VTYPE_INT8:
wmmhello's avatar
wmmhello 已提交
307 308
        ret = taosReadInt8Config(cfg, value);
        break;
S
slguan 已提交
309
      case TAOS_CFG_VTYPE_INT16:
wmmhello's avatar
wmmhello 已提交
310 311
        ret = taosReadInt16Config(cfg, value);
        break;
S
slguan 已提交
312
      case TAOS_CFG_VTYPE_INT32:
wmmhello's avatar
wmmhello 已提交
313 314
        ret = taosReadInt32Config(cfg, value);
        break;
315
      case TAOS_CFG_VTYPE_UINT16:
wmmhello's avatar
wmmhello 已提交
316 317
        ret = taosReadUInt16Config(cfg, value);
        break;
S
slguan 已提交
318
      case TAOS_CFG_VTYPE_FLOAT:
wmmhello's avatar
wmmhello 已提交
319 320
        ret = taosReadFloatConfig(cfg, value);
        break;
T
tickduan 已提交
321
      case TAOS_CFG_VTYPE_DOUBLE:
wmmhello's avatar
wmmhello 已提交
322 323
        ret = taosReadDoubleConfig(cfg, value);
        break;
S
slguan 已提交
324
      case TAOS_CFG_VTYPE_STRING:
wmmhello's avatar
wmmhello 已提交
325 326
        ret = taosReadStringConfig(cfg, value);
        break;
S
slguan 已提交
327
      case TAOS_CFG_VTYPE_IPSTR:
wmmhello's avatar
wmmhello 已提交
328 329
        ret = taosReadIpStrConfig(cfg, value);
        break;
S
slguan 已提交
330
      case TAOS_CFG_VTYPE_DIRECTORY:
wmmhello's avatar
wmmhello 已提交
331 332
        ret = taosReadDirectoryConfig(cfg, value);
        break;
S
TD-1767  
Shengliang Guan 已提交
333
      case TAOS_CFG_VTYPE_DATA_DIRCTORY:
S
TD-1767  
Shengliang Guan 已提交
334
        if (taosReadDirectoryConfig(cfg, value)) {
wmmhello's avatar
wmmhello 已提交
335
           taosReadDataDirCfg(value, value2, value3);
wmmhello's avatar
wmmhello 已提交
336
           ret = true;
S
TD-1767  
Shengliang Guan 已提交
337
        }
wmmhello's avatar
wmmhello 已提交
338 339
        ret = false;
        break;
S
slguan 已提交
340 341
      default:
        uError("config option:%s, input value:%s, can't be recognized", option, value);
wmmhello's avatar
wmmhello 已提交
342 343 344 345
        ret = false;
    }
    if(ret && cfgStatus == TAOS_CFG_CSTATUS_OPTION){
      cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
S
slguan 已提交
346 347
    }
  }
wmmhello's avatar
wmmhello 已提交
348
  return ret;
S
slguan 已提交
349 350 351 352 353 354 355 356 357 358 359 360 361
}

void taosInitConfigOption(SGlobalCfg cfg) {
  tsGlobalConfig[tsGlobalConfigNum++] = cfg;
}

void taosReadGlobalLogCfg() {
  FILE * fp;
  char * line, *option, *value;
  int    olen, vlen;
  char   fileName[PATH_MAX] = {0};

  wordexp_t full_path;
H
Hui Li 已提交
362 363 364 365 366 367
  if ( 0 != wordexp(configDir, &full_path, 0)) {
    printf("\nconfig file: %s wordexp fail! reason:%s\n", configDir, strerror(errno));
    wordfree(&full_path);
    return;
  }
  
H
Hui Li 已提交
368
  if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {    
B
Bomin Zhang 已提交
369
    if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) {
H
Hui Li 已提交
370 371 372 373
      printf("\nconfig file: %s path overflow max len %d, all variables are set to default\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1);
      wordfree(&full_path);
      return;
    }
S
slguan 已提交
374 375
    strcpy(configDir, full_path.we_wordv[0]);
  } else {
H
Hui Li 已提交
376
    #ifdef _TD_POWER_
H
Hui Li 已提交
377 378
    printf("configDir:%s not there, use default value: /etc/power", configDir);
    strcpy(configDir, "/etc/power");
379 380 381
	#elif (_TD_TQ_ == true)
    printf("configDir:%s not there, use default value: /etc/tq", configDir);
    strcpy(configDir, "/etc/tq");
382 383 384
	#elif (_TD_PRO_ == true)
    printf("configDir:%s not there, use default value: /etc/ProDB", configDir);
    strcpy(configDir, "/etc/ProDB");
H
Hui Li 已提交
385
    #else
S
slguan 已提交
386 387
    printf("configDir:%s not there, use default value: /etc/taos", configDir);
    strcpy(configDir, "/etc/taos");
H
Hui Li 已提交
388
    #endif
S
slguan 已提交
389 390 391
  }
  wordfree(&full_path);

392
  taosReadLogOption("logDir", tsLogDir);
S
slguan 已提交
393 394 395 396 397 398 399
  
  sprintf(fileName, "%s/taos.cfg", configDir);
  fp = fopen(fileName, "r");
  if (fp == NULL) {
    printf("\nconfig file:%s not found, all variables are set to default\n", fileName);
    return;
  }
400 401

  ssize_t _bytes = 0;
S
slguan 已提交
402 403 404 405 406 407 408 409 410
  size_t len = 1024;
  line = calloc(1, len);
  
  while (!feof(fp)) {
    memset(line, 0, len);
    
    option = value = NULL;
    olen = vlen = 0;

411 412 413 414 415 416
    _bytes = tgetline(&line, &len, fp);
    if (_bytes < 0)
    {
      break;
    }

S
slguan 已提交
417
    line[len - 1] = 0;
418

S
slguan 已提交
419 420 421 422 423 424 425 426 427 428 429
    paGetToken(line, &option, &olen);
    if (olen == 0) continue;
    option[olen] = 0;

    paGetToken(option + olen + 1, &value, &vlen);
    if (vlen == 0) continue;
    value[vlen] = 0;

    taosReadLogOption(option, value);
  }

S
TD-1848  
Shengliang Guan 已提交
430
  tfree(line);
S
slguan 已提交
431 432 433 434
  fclose(fp);
}

bool taosReadGlobalCfg() {
S
TD-1767  
Shengliang Guan 已提交
435 436
  char * line, *option, *value, *value2, *value3;
  int    olen, vlen, vlen2, vlen3;
S
slguan 已提交
437 438 439 440
  char   fileName[PATH_MAX] = {0};

  sprintf(fileName, "%s/taos.cfg", configDir);
  FILE* fp = fopen(fileName, "r");
441 442 443 444 445 446 447 448 449 450 451
  if (fp == NULL) {
    struct stat s;
    if (stat(configDir, &s) != 0 || (!S_ISREG(s.st_mode) && !S_ISLNK(s.st_mode))) {
      //return true to follow behavior before file support
      return true;
    }
    fp = fopen(configDir, "r");
    if (fp == NULL) {
      return false;
    }
  }
452 453

  ssize_t _bytes = 0;
S
slguan 已提交
454 455 456
  size_t len = 1024;
  line = calloc(1, len);
  
457 458
  while (!feof(fp)) {
    memset(line, 0, len);
S
slguan 已提交
459

S
TD-1767  
Shengliang Guan 已提交
460 461
    option = value = value2 = value3 = NULL;
    olen = vlen = vlen2 = vlen3 = 0;
S
slguan 已提交
462

463 464 465 466 467 468
    _bytes = tgetline(&line, &len, fp);
    if (_bytes < 0)
    {
      break;
    }

469 470 471 472 473
    line[len - 1] = 0;
    
    paGetToken(line, &option, &olen);
    if (olen == 0) continue;
    option[olen] = 0;
S
slguan 已提交
474

475 476 477
    paGetToken(option + olen + 1, &value, &vlen);
    if (vlen == 0) continue;
    value[vlen] = 0;
S
slguan 已提交
478

S
TD-1767  
Shengliang Guan 已提交
479
    paGetToken(value + vlen + 1, &value2, &vlen2);
S
TD-1767  
Shengliang Guan 已提交
480 481 482 483 484
    if (vlen2 != 0) {
      value2[vlen2] = 0;
      paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
      if (vlen3 != 0) value3[vlen3] = 0;
    }
S
TD-1767  
Shengliang Guan 已提交
485

wmmhello's avatar
wmmhello 已提交
486
    taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE, 0);
S
slguan 已提交
487 488
  }

489 490
  fclose(fp);

S
TD-1848  
Shengliang Guan 已提交
491
  tfree(line);
S
TD-1663  
Shengliang Guan 已提交
492

S
TD-1663  
Shengliang Guan 已提交
493 494 495
  if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
    taosSetAllDebugFlag();
  }
S
TD-1663  
Shengliang Guan 已提交
496

S
slguan 已提交
497 498 499 500
  return true;
}

void taosPrintGlobalCfg() {
501 502
  uInfo("   taos config & system info:");
  uInfo("==================================");
S
slguan 已提交
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517

  for (int i = 0; i < tsGlobalConfigNum; ++i) {
    SGlobalCfg *cfg = tsGlobalConfig + i;
    if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
    if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
    
    int optionLen = (int)strlen(cfg->option);
    int blankLen = TSDB_CFG_PRINT_LEN - optionLen;
    blankLen = blankLen < 0 ? 0 : blankLen;

    char blank[TSDB_CFG_PRINT_LEN];
    memset(blank, ' ', TSDB_CFG_PRINT_LEN);
    blank[blankLen] = 0;

    switch (cfg->valType) {
S
Shengliang Guan 已提交
518 519 520
      case TAOS_CFG_VTYPE_INT8:
        uInfo(" %s:%s%d%s", cfg->option, blank, *((int8_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
        break;
S
slguan 已提交
521
      case TAOS_CFG_VTYPE_INT16:
522
        uInfo(" %s:%s%d%s", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
S
slguan 已提交
523 524
        break;
      case TAOS_CFG_VTYPE_INT32:
525
        uInfo(" %s:%s%d%s", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
S
slguan 已提交
526
        break;
527 528 529
      case TAOS_CFG_VTYPE_UINT16:
        uInfo(" %s:%s%d%s", cfg->option, blank, *((uint16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
        break;
S
slguan 已提交
530
      case TAOS_CFG_VTYPE_FLOAT:
531
        uInfo(" %s:%s%f%s", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
S
slguan 已提交
532
        break;
T
tickduan 已提交
533 534 535
      case TAOS_CFG_VTYPE_DOUBLE:
        uInfo(" %s:%s%f%s", cfg->option, blank, *((double *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
        break;
S
slguan 已提交
536 537 538
      case TAOS_CFG_VTYPE_STRING:
      case TAOS_CFG_VTYPE_IPSTR:
      case TAOS_CFG_VTYPE_DIRECTORY:
539
        uInfo(" %s:%s%s%s", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]);
S
slguan 已提交
540 541 542 543 544 545 546
        break;
      default:
        break;
    }
  }

  taosPrintOsInfo();
S
TD-1767  
Shengliang Guan 已提交
547 548
  taosPrintDataDirCfg();
  uInfo("==================================");
S
slguan 已提交
549
}
S
stephenkgu 已提交
550 551 552 553 554 555 556 557 558 559 560

static void taosDumpCfg(SGlobalCfg *cfg) {
    int optionLen = (int)strlen(cfg->option);
    int blankLen = TSDB_CFG_PRINT_LEN - optionLen;
    blankLen = blankLen < 0 ? 0 : blankLen;

    char blank[TSDB_CFG_PRINT_LEN];
    memset(blank, ' ', TSDB_CFG_PRINT_LEN);
    blank[blankLen] = 0;

    switch (cfg->valType) {
S
Shengliang Guan 已提交
561 562 563
      case TAOS_CFG_VTYPE_INT8:
        printf(" %s:%s%d%s\n", cfg->option, blank, *((int8_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
        break;
S
stephenkgu 已提交
564 565 566 567 568 569
      case TAOS_CFG_VTYPE_INT16:
        printf(" %s:%s%d%s\n", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
        break;
      case TAOS_CFG_VTYPE_INT32:
        printf(" %s:%s%d%s\n", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
        break;
570 571 572
      case TAOS_CFG_VTYPE_UINT16:
        printf(" %s:%s%d%s\n", cfg->option, blank, *((uint16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
        break;
S
stephenkgu 已提交
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
      case TAOS_CFG_VTYPE_FLOAT:
        printf(" %s:%s%f%s\n", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
        break;
      case TAOS_CFG_VTYPE_STRING:
      case TAOS_CFG_VTYPE_IPSTR:
      case TAOS_CFG_VTYPE_DIRECTORY:
        printf(" %s:%s%s%s\n", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]);
        break;
      default:
        break;
    }
}

void taosDumpGlobalCfg() {
  printf("taos global config:\n");
  printf("==================================\n");
  for (int i = 0; i < tsGlobalConfigNum; ++i) {
    SGlobalCfg *cfg = tsGlobalConfig + i;
    if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
    if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
    if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW)) continue;

    taosDumpCfg(cfg);
  }

  printf("\ntaos local config:\n");
  printf("==================================\n");

  for (int i = 0; i < tsGlobalConfigNum; ++i) {
    SGlobalCfg *cfg = tsGlobalConfig + i;
    if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
    if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
    if (cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW) continue;

    taosDumpCfg(cfg);
  }
Z
Zhiyu Yang 已提交
609
}