From c6fb4e928a6e3b1efeae9da89626e150981d07a2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 1 Mar 2022 17:34:55 +0800 Subject: [PATCH] Also start taosd when the config file does not exis --- include/os/osDir.h | 1 + include/util/tconfig.h | 2 +- source/common/src/tglobal.c | 22 ++++++++++++---------- source/os/src/osDir.c | 9 +++++++++ source/util/src/tconfig.c | 7 +++++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/include/os/osDir.h b/include/os/osDir.h index e328c42063..eda83ea0ea 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -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 } diff --git a/include/util/tconfig.h b/include/util/tconfig.h index 8275054a64..0e1d352f9a 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -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); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index db84f87b66..4202c1fe14 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -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; diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index c464073e5f..91ef97e66b 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -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 diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 8330c10ec7..84af091fb3 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -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); -- GitLab