Merge pull request #2739 from taosdata/bugfix/td-900
fix td-900: support both config dir & file
This commit is contained in:
commit
0fb871cc97
|
@ -308,38 +308,47 @@ bool taosReadGlobalCfg() {
|
||||||
|
|
||||||
sprintf(fileName, "%s/taos.cfg", configDir);
|
sprintf(fileName, "%s/taos.cfg", configDir);
|
||||||
FILE* fp = fopen(fileName, "r");
|
FILE* fp = fopen(fileName, "r");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t len = 1024;
|
size_t len = 1024;
|
||||||
line = calloc(1, len);
|
line = calloc(1, len);
|
||||||
|
|
||||||
if (fp != NULL) {
|
while (!feof(fp)) {
|
||||||
while (!feof(fp)) {
|
memset(line, 0, len);
|
||||||
memset(line, 0, len);
|
|
||||||
|
|
||||||
option = value = NULL;
|
option = value = NULL;
|
||||||
olen = vlen = 0;
|
olen = vlen = 0;
|
||||||
|
|
||||||
getline(&line, &len, fp);
|
getline(&line, &len, fp);
|
||||||
line[len - 1] = 0;
|
line[len - 1] = 0;
|
||||||
|
|
||||||
paGetToken(line, &option, &olen);
|
paGetToken(line, &option, &olen);
|
||||||
if (olen == 0) continue;
|
if (olen == 0) continue;
|
||||||
option[olen] = 0;
|
option[olen] = 0;
|
||||||
|
|
||||||
paGetToken(option + olen + 1, &value, &vlen);
|
paGetToken(option + olen + 1, &value, &vlen);
|
||||||
if (vlen == 0) continue;
|
if (vlen == 0) continue;
|
||||||
value[vlen] = 0;
|
value[vlen] = 0;
|
||||||
|
|
||||||
// For dataDir, the format is:
|
// For dataDir, the format is:
|
||||||
// dataDir /mnt/disk1 0
|
// dataDir /mnt/disk1 0
|
||||||
paGetToken(value + vlen + 1, &value1, &vlen1);
|
paGetToken(value + vlen + 1, &value1, &vlen1);
|
||||||
|
|
||||||
taosReadConfigOption(option, value);
|
taosReadConfigOption(option, value);
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
tfree(line);
|
tfree(line);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue