From b6fb79dc0dd43518442ef0a02ca71e5e905b495a Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 22 Jul 2020 14:32:36 +0800 Subject: [PATCH] fix td-900: support both config dir & file --- src/util/src/tconfig.c | 53 ++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 74acb7ce35..d561e8ba5f 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -308,38 +308,47 @@ bool taosReadGlobalCfg() { sprintf(fileName, "%s/taos.cfg", configDir); 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; line = calloc(1, len); - if (fp != NULL) { - while (!feof(fp)) { - memset(line, 0, len); - - option = value = NULL; - olen = vlen = 0; + while (!feof(fp)) { + memset(line, 0, len); - getline(&line, &len, fp); - line[len - 1] = 0; - - paGetToken(line, &option, &olen); - if (olen == 0) continue; - option[olen] = 0; + option = value = NULL; + olen = vlen = 0; - paGetToken(option + olen + 1, &value, &vlen); - if (vlen == 0) continue; - value[vlen] = 0; + getline(&line, &len, fp); + line[len - 1] = 0; + + paGetToken(line, &option, &olen); + if (olen == 0) continue; + option[olen] = 0; - // For dataDir, the format is: - // dataDir /mnt/disk1 0 - paGetToken(value + vlen + 1, &value1, &vlen1); - - taosReadConfigOption(option, value); - } + paGetToken(option + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; - fclose(fp); + // For dataDir, the format is: + // dataDir /mnt/disk1 0 + paGetToken(value + vlen + 1, &value1, &vlen1); + + taosReadConfigOption(option, value); } + fclose(fp); + tfree(line); return true; -- GitLab