提交 c6fb4e92 编写于 作者: S Shengliang Guan

Also start taosd when the config file does not exis

上级 9359fe21
......@@ -26,6 +26,7 @@ int32_t taosMkDir(const char *dirname);
void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
int32_t taosRealPath(char *dirname, int32_t maxlen);
bool taosIsDir(const char *dirname);
#ifdef __cplusplus
}
......
......@@ -82,7 +82,7 @@ typedef struct SConfig {
SConfig *cfgInit();
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void cfgCleanup(SConfig *pCfg);
int32_t cfgGetSize(SConfig *pCfg);
......
......@@ -177,24 +177,24 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
snprintf(cfgFile, sizeof(cfgFile), "%s" TD_DIRSEP "taos.cfg", cfgDir);
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
uError("failed to load from apollo url:%s since %s\n", apolloUrl, terrstr());
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
return -1;
}
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile) != 0) {
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgDir) != 0) {
uError("failed to load from config file:%s since %s\n", cfgFile, terrstr());
return -1;
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgDir) != 0) {
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile) != 0) {
uError("failed to load from config file:%s since %s", cfgFile, terrstr());
return 0;
}
}
if (cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile) != 0) {
uError("failed to load from env file:%s since %s\n", envFile, terrstr());
uError("failed to load from env file:%s since %s", envFile, terrstr());
return -1;
}
if (cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL) != 0) {
uError("failed to load from global env variables since %s\n", terrstr());
uError("failed to load from global env variables since %s", terrstr());
return -1;
}
......@@ -438,8 +438,10 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
if (pCfg == NULL) return -1;
if (tsc) {
tscEmbeddedInUtil = 0;
if (taosAddClientLogCfg(pCfg) != 0) return -1;
} else {
tscEmbeddedInUtil = 1;
if (taosAddClientLogCfg(pCfg) != 0) return -1;
if (taosAddServerLogCfg(pCfg) != 0) return -1;
}
......@@ -450,7 +452,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
return -1;
}
if (cfgLoadArray(pCfg, pArgs) != 0) {
if (cfgLoadFromArray(pCfg, pArgs) != 0) {
uError("failed to load cfg from array since %s", terrstr());
cfgCleanup(pCfg);
return -1;
......@@ -466,7 +468,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
if (taosInitLog(logname, logFileNum) != 0) {
printf("failed to init log file since %s\n", terrstr());
uError("failed to init log file since %s", terrstr());
cfgCleanup(pCfg);
return -1;
}
......@@ -497,7 +499,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
return -1;
}
if (cfgLoadArray(tsCfg, pArgs) != 0) {
if (cfgLoadFromArray(tsCfg, pArgs) != 0) {
uError("failed to load cfg from array since %s", terrstr());
cfgCleanup(tsCfg);
return -1;
......
......@@ -140,4 +140,13 @@ int32_t taosRealPath(char *dirname, int32_t maxlen) {
return 0;
}
bool taosIsDir(const char *dirname) {
DIR *dir = opendir(dirname);
if (dir != NULL) {
closedir(dir);
return true;
}
return false;
}
#endif
......@@ -60,7 +60,7 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
}
}
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs) {
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs) {
int32_t size = taosArrayGetSize(pArgs);
for (int32_t i = 0; i < size; ++i) {
SConfigPair *pPair = taosArrayGet(pArgs, i);
......@@ -608,7 +608,10 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
int32_t olen, vlen, vlen2, vlen3;
ssize_t _bytes = 0;
// FILE *fp = fopen(filepath, "r");
if (taosIsDir(filepath)) {
return -1;
}
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册