diff --git a/CMakeLists.txt b/CMakeLists.txt index e1fbd54be337eb625fa1c1a95dead88c83887c50..0436f5b25923927edaa7568ba57c7b948446f8b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project( ) if (NOT DEFINED TD_SOURCE_DIR) - set( TD_SOURCE_DIR ${CMAKE_SOURCE_DIR} ) + set( TD_SOURCE_DIR ${PROJECT_SOURCE_DIR} ) endif() set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake") diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index e94de3cbca574de71c8bcefc4b52173922c05a98..17a9257c499c6a1efd24fb23b47a9e9835ad7ade 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -1,7 +1,7 @@ PROJECT(TDengine) IF (TD_LINUX) - INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc) + INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc) AUX_SOURCE_DIRECTORY(. SRC) ADD_EXECUTABLE(demo apitest.c) TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread ) @@ -13,7 +13,7 @@ IF (TD_LINUX) TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua) ENDIF () IF (TD_DARWIN) - INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc) + INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc) AUX_SOURCE_DIRECTORY(. SRC) ADD_EXECUTABLE(demo demo.c) TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 72f67665ba066b46057c8a0f3195f49f89e9a794..fc3d575317a5e8e68657d967b6d2e2afa3458d13 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -123,9 +123,9 @@ extern SDiskCfg tsDiskCfg[]; #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) -int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, - const char *apolloUrl, SArray *pArgs, bool tsc); -int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc); +int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, + char *apolloUrl, SArray *pArgs, bool tsc); +int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc); void taosCleanupCfg(); void taosCfgDynamicOptions(const char *option, const char *value); void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary); diff --git a/include/util/tconfig.h b/include/util/tconfig.h index 012368d9cba4ce62cb11ca4d3bacad8724e574d5..06fa9fd9aaf351f59b761a57cc96a4f3529ecf91 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -30,6 +30,7 @@ typedef enum { CFG_STYPE_CFG_FILE, CFG_STYPE_ENV_FILE, CFG_STYPE_ENV_VAR, + CFG_STYPE_ENV_CMD, CFG_STYPE_APOLLO_URL, CFG_STYPE_ARG_LIST, CFG_STYPE_TAOS_OPTIONS @@ -82,7 +83,7 @@ typedef struct SConfig { } SConfig; SConfig *cfgInit(); -int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr); +int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr); int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair void cfgCleanup(SConfig *pCfg); @@ -105,6 +106,8 @@ const char *cfgDtypeStr(ECfgDataType type); void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump); +int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl); + #ifdef __cplusplus } #endif diff --git a/include/util/tenv.h b/include/util/tenv.h new file mode 100644 index 0000000000000000000000000000000000000000..1410e23f9062be06fe45d38dbe5399a7db7bc444 --- /dev/null +++ b/include/util/tenv.h @@ -0,0 +1,33 @@ + +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_ENV_H_ +#define _TD_ENV_H_ + +#include "os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen); +int32_t taosEnvToCfg(const char *envStr, char *cfgStr); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_ENV_H_*/ diff --git a/include/util/tjson.h b/include/util/tjson.h index 286a7e65fcd4780a653df5a61fc1d5de21253b62..d23f7b402ea142ea9118f57f6274983d78c5a72a 100644 --- a/include/util/tjson.h +++ b/include/util/tjson.h @@ -49,6 +49,8 @@ int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem); int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem); SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName); +int32_t tjsonGetObjectName(const SJson* pJson, char** pName); +int32_t tjsonGetObjectValueString(const SJson* pJson, char** pStringValue); int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal); int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal); int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal); @@ -81,6 +83,7 @@ char* tjsonToUnformattedString(const SJson* pJson); SJson* tjsonParse(const char* pStr); bool tjsonValidateJson(const char* pJson); +const char* tjsonGetError(); #ifdef __cplusplus } diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 9a34334466d34cee74115f4735d15979215772ea..596c3d3fbf7fbc1ad975fea4eb88a02cd0ae7ab5 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -254,12 +254,12 @@ void taos_init_imp(void) { deltaToUtcInitOnce(); - if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) { + if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) { tscInitRes = -1; return; } - if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) { tscInitRes = -1; return; } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 33999ea14cc901c579a46e8f8cdddd7046dabfd6..bbf14b2fdc42ac889a9183eb90981ab217590564 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -220,7 +220,7 @@ struct SConfig *taosGetCfg() { return tsCfg; } -static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) { +static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) { char cfgDir[PATH_MAX] = {0}; char cfgFile[PATH_MAX + 100] = {0}; @@ -231,6 +231,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e tstrncpy(cfgFile, cfgDir, sizeof(cfgDir)); } + if (apolloUrl == NULL || apolloUrl[0] == '\0') cfgGetApollUrl(envCmd, envFile, apolloUrl); + if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) { uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr()); return -1; @@ -251,6 +253,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e return -1; } + if (cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd) != 0) { + uError("failed to load from cmd env variables since %s", terrstr()); + return -1; + } + return 0; } @@ -325,8 +332,8 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) { if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1; if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1; if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1; - if (cfgAddInt64(pCfg, "totalMemory(KB)", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "pageSizeKB", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1; + if (cfgAddInt64(pCfg, "totalMemoryKB", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1; if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1; if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1; if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1; @@ -572,8 +579,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { return 0; } -int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, - const char *apolloUrl, SArray *pArgs, bool tsc) { +int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, + char *apolloUrl, SArray *pArgs, bool tsc) { osDefaultInit(); SConfig *pCfg = cfgInit(); @@ -588,7 +595,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi if (taosAddServerLogCfg(pCfg) != 0) return -1; } - if (taosLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) { + if (taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) { uError("failed to load cfg since %s", terrstr()); cfgCleanup(pCfg); return -1; @@ -625,7 +632,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi return 0; } -int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) { +int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) { if (tsCfg != NULL) return 0; tsCfg = cfgInit(); @@ -640,7 +647,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU } taosAddSystemCfg(tsCfg); - if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) { + if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) { uError("failed to load cfg since %s", terrstr()); cfgCleanup(tsCfg); tsCfg = NULL; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 4b01c540f7e6019240aa3eff0ab547705420275e..43237e6e6c04efaa00f9536db802350d768571ed 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -24,6 +24,7 @@ static struct { bool printVersion; char envFile[PATH_MAX]; char apolloUrl[PATH_MAX]; + const char **envCmd; SArray *pArgs; // SConfigPair SDnode *pDnode; EDndNodeType ntype; @@ -56,6 +57,9 @@ static void dmSetSignalHandle() { } static int32_t dmParseArgs(int32_t argc, char const *argv[]) { + int32_t cmdEnvIndex = 0; + global.envCmd = taosMemoryMalloc(argc-1); + memset(global.envCmd, 0, argc-1); for (int32_t i = 1; i < argc; ++i) { if (strcmp(argv[i], "-c") == 0) { if (i < argc - 1) { @@ -70,7 +74,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { } } else if (strcmp(argv[i], "-a") == 0) { tstrncpy(global.apolloUrl, argv[++i], PATH_MAX); - } else if (strcmp(argv[i], "-e") == 0) { + } else if (strcmp(argv[i], "-E") == 0) { tstrncpy(global.envFile, argv[++i], PATH_MAX); } else if (strcmp(argv[i], "-n") == 0) { global.ntype = atoi(argv[++i]); @@ -84,6 +88,9 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { global.dumpConfig = true; } else if (strcmp(argv[i], "-V") == 0) { global.printVersion = true; + } else if (strcmp(argv[i], "-e") == 0) { + global.envCmd[cmdEnvIndex] = argv[++i]; + cmdEnvIndex++; } else { } } @@ -129,7 +136,7 @@ static SDnodeOpt dmGetOpt() { static int32_t dmInitLog() { char logName[12] = {0}; snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype)); - return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); + return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0); } static void dmSetProcInfo(int32_t argc, char **argv) { @@ -168,6 +175,10 @@ static int32_t dmRunDnode() { return code; } +static void taosCleanupArgs() { + if (global.envCmd != NULL) taosMemoryFree(global.envCmd); +} + int main(int argc, char const *argv[]) { if (!taosCheckSystemIsSmallEnd()) { printf("failed to start since on non-small-end machines\n"); @@ -176,26 +187,31 @@ int main(int argc, char const *argv[]) { if (dmParseArgs(argc, argv) != 0) { printf("failed to start since parse args error\n"); + taosCleanupArgs(); return -1; } if (global.generateGrant) { dmGenerateGrant(); + taosCleanupArgs(); return 0; } if (global.printVersion) { dmPrintVersion(); + taosCleanupArgs(); return 0; } if (dmInitLog() != 0) { - dError("failed to start since init log error"); + printf("failed to start since init log error"); + taosCleanupArgs(); return -1; } - if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) { + if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) { dError("failed to start since read config error"); + taosCleanupArgs(); return -1; } @@ -203,9 +219,11 @@ int main(int argc, char const *argv[]) { dmDumpCfg(); taosCleanupCfg(); taosCloseLog(); + taosCleanupArgs(); return 0; } dmSetProcInfo(argc, (char **)argv); + taosCleanupArgs(); return dmRunDnode(); } diff --git a/source/dnode/mgmt/interface/src/dmFile.c b/source/dnode/mgmt/interface/src/dmFile.c index e9117939d72ca5c094d7fe6066cb1843d4efaeed..38acf169be47f51c96cbb0339f58b4b964c3d382 100644 --- a/source/dnode/mgmt/interface/src/dmFile.c +++ b/source/dnode/mgmt/interface/src/dmFile.c @@ -124,7 +124,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to lock file:%s since %s", filepath, terrstr()); + dError("failed to open file:%s since %s", filepath, terrstr()); return NULL; } diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index e4c4cb4893c57255439fe1ba90438708591fa638..11bbd6442ce8e02906f79b4aef1ab779df3bf006 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -548,7 +548,7 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) { static int32_t udfdInitLog() { char logName[12] = {0}; snprintf(logName, sizeof(logName), "%slog", "udfd"); - return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0); + return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0); } void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) { @@ -656,7 +656,7 @@ int main(int argc, char *argv[]) { return -1; } - if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) { fnError("failed to start since read config error"); return -1; } diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index 8e5eac538e9bac83534e3ad5143482e008f51d91..a8d6fbd7152a76f13d06fea6ef42e13acc57e25c 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -31,13 +31,13 @@ static int32_t parseArgs(int32_t argc, char *argv[]) { static int32_t initLog() { char logName[12] = {0}; snprintf(logName, sizeof(logName), "%slog", "udfc"); - return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0); + return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0); } int main(int argc, char *argv[]) { parseArgs(argc, argv); initLog(); - if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) { fnError("failed to start since read config error"); return -1; } diff --git a/source/libs/sync/CMakeLists.txt b/source/libs/sync/CMakeLists.txt index cb196acc02e49c7e3aa85a1d522515d69ebf33ef..551849c6f29f3def8b275877aba28f7048ea1793 100644 --- a/source/libs/sync/CMakeLists.txt +++ b/source/libs/sync/CMakeLists.txt @@ -11,7 +11,7 @@ target_link_libraries( target_include_directories( sync - PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync" + PUBLIC "${TD_SOURCE_DIR}/include/libs/sync" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index 3319a73fcf9e4c197706081c4dbee4f7e8a98ffc..8afe9ff2a724d031531bbf5fd5c867673a00c46b 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -199,197 +199,197 @@ target_sources(syncApplyMsgTest target_include_directories(syncTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncEnvTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingTimerTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOTickQTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOTickPingTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOSendMsgTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOClientTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOServerTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRaftStoreTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncEnqTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIndexTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncInitTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncUtilTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncVotesGrantedTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncVotesRespondTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIndexMgrTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncLogStoreTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncEntryTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRequestVoteTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRequestVoteReplyTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncAppendEntriesTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncAppendEntriesReplyTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncClientRequestTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncTimeoutTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingReplyTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRpcMsgTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingTimerTest2 PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingSelfTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncElectTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncEncodeTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncWriteTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncReplicateTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRefTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncLogStoreCheck PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRaftCfgTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRespMgrTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncSnapshotTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncApplyMsgTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 699a7aa080fdc5e581555b7193fe257473330995..5ab349be4cb6157ff50a74608105cfb520c580ac 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -18,6 +18,9 @@ #include "taoserror.h" #include "tlog.h" #include "tutil.h" +#include "tenv.h" +#include "cJSON.h" +#include "tjson.h" #define CFG_NAME_PRINT_LEN 24 #define CFG_SRC_PRINT_LEN 12 @@ -25,6 +28,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath); int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath); int32_t cfgLoadFromEnvVar(SConfig *pConfig); +int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd); int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url); int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype); @@ -45,7 +49,7 @@ SConfig *cfgInit() { return pCfg; } -int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { +int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr) { switch (cfgType) { case CFG_STYPE_CFG_FILE: return cfgLoadFromCfgFile(pCfg, sourceStr); @@ -55,6 +59,8 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { return cfgLoadFromEnvVar(pCfg); case CFG_STYPE_APOLLO_URL: return cfgLoadFromApollUrl(pCfg, sourceStr); + case CFG_STYPE_ENV_CMD: + return cfgLoadFromEnvCmd(pCfg, (const char **)sourceStr); default: return -1; } @@ -463,6 +469,8 @@ const char *cfgStypeStr(ECfgSrcType type) { return "arg_list"; case CFG_STYPE_TAOS_OPTIONS: return "taos_options"; + case CFG_STYPE_ENV_CMD: + return "env_cmd"; default: return "invalid"; } @@ -584,12 +592,154 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { } int32_t cfgLoadFromEnvVar(SConfig *pConfig) { - uDebug("load from env variables not implemented yet"); + char *line = NULL, *name, *value, *value2, *value3; + int32_t olen, vlen, vlen2, vlen3; + ssize_t _bytes = 0; + TdCmdPtr pCmd = taosOpenCmd("set"); + if (pCmd == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + while (!taosEOFCmd(pCmd)) { + name = value = value2 = value3 = NULL; + olen = vlen = vlen2 = vlen3 = 0; + + _bytes = taosGetLineCmd(pCmd, &line); + if (_bytes < 0) { + break; + } + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; + taosEnvToCfg(line, line); + + paGetToken(line, &name, &olen); + if (olen == 0) continue; + name[olen] = 0; + + paGetToken(name + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + paGetToken(value + vlen + 1, &value2, &vlen2); + if (vlen2 != 0) { + value2[vlen2] = 0; + paGetToken(value2 + vlen2 + 1, &value3, &vlen3); + if (vlen3 != 0) value3[vlen3] = 0; + } + + cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_VAR); + if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) { + cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_VAR); + } + } + + taosCloseCmd(&pCmd); + if (line != NULL) taosMemoryFreeClear(line); + + uInfo("load from env variables cfg success"); return 0; } -int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) { - uDebug("load from env file not implemented yet"); +int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) { + char *buf, *name, *value, *value2, *value3; + int32_t olen, vlen, vlen2, vlen3; + int32_t index = 0; + if (envCmd == NULL) return 0; + while (envCmd[index]!=NULL) { + buf = taosMemoryMalloc(strlen(envCmd[index])); + taosEnvToCfg(envCmd[index], buf); + index++; + + name = value = value2 = value3 = NULL; + olen = vlen = vlen2 = vlen3 = 0; + + paGetToken(buf, &name, &olen); + if (olen == 0) continue; + name[olen] = 0; + + paGetToken(name + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + paGetToken(value + vlen + 1, &value2, &vlen2); + if (vlen2 != 0) { + value2[vlen2] = 0; + paGetToken(value2 + vlen2 + 1, &value3, &vlen3); + if (vlen3 != 0) value3[vlen3] = 0; + } + + cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_CMD); + if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) { + cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_CMD); + } + + taosMemoryFree(buf); + } + + uInfo("load from env cmd cfg success"); + return 0; +} + +int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { + char *line = NULL, *name, *value, *value2, *value3; + int32_t olen, vlen, vlen2, vlen3; + ssize_t _bytes = 0; + + const char *filepath = ".env"; + if (envFile != NULL && strlen(envFile)>0) { + if (!taosCheckExistFile(envFile)) { + uError("fial to load env file: %s", envFile); + return -1; + } + filepath = envFile; + }else { + if (!taosCheckExistFile(filepath)) { + uInfo("fial to load env file: %s", filepath); + return 0; + } + } + + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); + if (pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + while (!taosEOFFile(pFile)) { + name = value = value2 = value3 = NULL; + olen = vlen = vlen2 = vlen3 = 0; + + _bytes = taosGetLineFile(pFile, &line); + if (_bytes <= 0) { + break; + } + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; + taosEnvToCfg(line, line); + + paGetToken(line, &name, &olen); + if (olen == 0) continue; + name[olen] = 0; + + paGetToken(name + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + paGetToken(value + vlen + 1, &value2, &vlen2); + if (vlen2 != 0) { + value2[vlen2] = 0; + paGetToken(value2 + vlen2 + 1, &value3, &vlen3); + if (vlen3 != 0) value3[vlen3] = 0; + } + + cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_FILE); + if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) { + cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_FILE); + } + } + + taosCloseFile(&pFile); + if (line != NULL) taosMemoryFreeClear(line); + + uInfo("load from env cfg file %s success", filepath); return 0; } @@ -617,11 +767,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { olen = vlen = vlen2 = vlen3 = 0; _bytes = taosGetLineFile(pFile, &line); - if (_bytes < 0) { + if (_bytes <= 0) { break; } - line[_bytes - 1] = 0; + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; paGetToken(line, &name, &olen); if (olen == 0) continue; @@ -659,6 +809,193 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { } int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { - uDebug("load from apoll url not implemented yet"); + char *cfgLineBuf = NULL, *name, *value, *value2, *value3; + int32_t olen, vlen, vlen2, vlen3; + if (url == NULL || strlen(url) == 0) { + uInfo("fail to load apoll url"); + return 0; + } + + char *p = strchr(url, ':'); + if (p == NULL) { + uError("fail to load apoll url: %s, unknown format", url); + return -1; + } + p++; + + if (bcmp(url, "jsonFile", 8) == 0) { + char *filepath = p; + if (!taosCheckExistFile(filepath)) { + uError("fial to load json file: %s", filepath); + return -1; + } + + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); + if (pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END); + char *buf = taosMemoryMalloc(fileSize); + taosLSeekFile(pFile, 0, SEEK_SET); + if(taosReadFile(pFile, buf, fileSize) <= 0) { + taosCloseFile(&pFile); + uError("load json file error: %s", filepath); + return -1; + } + taosCloseFile(&pFile); + SJson* pJson = tjsonParse(buf); + if (NULL == pJson) { + const char *jsonParseError = tjsonGetError(); + if (jsonParseError != NULL) { + uError("load json file parse error: %s", jsonParseError); + } + return -1; + } + taosMemoryFreeClear(buf); + + int32_t jsonArraySize = tjsonGetArraySize(pJson); + for(int32_t i = 0; i < jsonArraySize; i++) { + cJSON* item = tjsonGetArrayItem(pJson, i); + if (item == NULL) break; + char *itemName = NULL, *itemValueString = NULL; + tjsonGetObjectName(item, &itemName); + tjsonGetObjectName(item, &itemName); + tjsonGetObjectValueString(item, &itemValueString); + if (itemValueString != NULL && itemName != NULL) { + size_t itemNameLen = strlen(itemName); + size_t itemValueStringLen = strlen(itemValueString); + cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2); + memcpy(cfgLineBuf, itemName, itemNameLen); + cfgLineBuf[itemNameLen] = ' '; + memcpy(&cfgLineBuf[itemNameLen+1], itemValueString, itemValueStringLen); + cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0'; + + paGetToken(cfgLineBuf, &name, &olen); + if (olen == 0) continue; + name[olen] = 0; + + paGetToken(name + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + paGetToken(value + vlen + 1, &value2, &vlen2); + if (vlen2 != 0) { + value2[vlen2] = 0; + paGetToken(value2 + vlen2 + 1, &value3, &vlen3); + if (vlen3 != 0) value3[vlen3] = 0; + } + printf("%s(%d) %s name=%s, value=%s\n", __FILE__, __LINE__,__func__,name, value); + cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL); + if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) { + cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_APOLLO_URL); + } + } + } + tjsonDelete(pJson); + + // } else if (bcmp(url, "jsonUrl", 7) == 0) { + // } else if (bcmp(url, "etcdUrl", 7) == 0) { + } else { + uError("Unsupported url: %s", url); + return -1; + } + + uInfo("load from apoll url not implemented yet"); return 0; } + +int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl) { + int32_t index = 0; + if (envCmd == NULL) return 0; + while (envCmd[index]!=NULL) { + if (bcmp(envCmd[index], "TAOS_APOLL_URL", 14) == 0) { + char *p = strchr(envCmd[index], '='); + if (p != NULL) { + p++; + if (*p == '\'') { + p++; + p[strlen(p)-1] = '\0'; + } + memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); + uInfo("get apollo url from env cmd success"); + return 0; + } + } + index++; + } + + char *line = NULL; + ssize_t _bytes = 0; + TdCmdPtr pCmd = taosOpenCmd("set"); + if (pCmd != NULL) { + while (!taosEOFCmd(pCmd)) { + _bytes = taosGetLineCmd(pCmd, &line); + if (_bytes < 0) { + break; + } + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; + if (bcmp(line, "TAOS_APOLL_URL", 14) == 0) { + char *p = strchr(line, '='); + if (p != NULL) { + p++; + if (*p == '\'') { + p++; + p[strlen(p)-1] = '\0'; + } + memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); + uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl); + taosCloseCmd(&pCmd); + if (line != NULL) taosMemoryFreeClear(line); + return 0; + } + } + } + taosCloseCmd(&pCmd); + if (line != NULL) taosMemoryFreeClear(line); + } + + const char *filepath = ".env"; + if (envFile != NULL && strlen(envFile)>0) { + if (!taosCheckExistFile(envFile)) { + uError("fial to load env file: %s", envFile); + return -1; + } + filepath = envFile; + }else { + if (!taosCheckExistFile(filepath)) { + uInfo("fial to load env file: %s", filepath); + return 0; + } + } + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); + if (pFile != NULL) { + while (!taosEOFFile(pFile)) { + _bytes = taosGetLineFile(pFile, &line); + if (_bytes <= 0) { + break; + } + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; + if (bcmp(line, "TAOS_APOLL_URL", 14) == 0) { + char *p = strchr(line, '='); + if (p != NULL) { + p++; + if (*p == '\'') { + p++; + p[strlen(p)-1] = '\0'; + } + memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); + taosCloseFile(&pFile); + if (line != NULL) taosMemoryFreeClear(line); + uInfo("get apollo url from env file success"); + return 0; + } + } + } + taosCloseFile(&pFile); + if (line != NULL) taosMemoryFreeClear(line); + } + + uInfo("fail get apollo url from cmd env file"); + return -1; +} \ No newline at end of file diff --git a/source/util/src/tenv.c b/source/util/src/tenv.c new file mode 100644 index 0000000000000000000000000000000000000000..e717e82c5b27bb9911364571538cf8f6863098b8 --- /dev/null +++ b/source/util/src/tenv.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "tenv.h" +#include "tconfig.h" + +static char toLowChar(char c) { return (c > 'Z' || c < 'A' ? c : (c - 'A' + 'a')); } + +int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen) { + if (envNameStr == NULL || cfgNameStr == NULL) return -1; + char *p = cfgNameStr; + if (envNameStr[0] != 'T' || envNameStr[1] != 'A' || envNameStr[2] != 'O' || envNameStr[3] != 'S' || + envNameStr[4] != '_') { + // if(p != envNameStr) strncpy(p, envNameStr, cfgNameMaxLen - 1); + // p[cfgNameMaxLen - 1] = '\0'; + // return strlen(cfgNameStr); + cfgNameStr[0] = '\0'; + return -1; + } + envNameStr += 5; + if (*envNameStr != '\0') { + *p = toLowChar(*envNameStr); + p++; + envNameStr++; + } + + for (size_t i = 1; i < cfgNameMaxLen && *envNameStr != '\0'; i++) { + if (*envNameStr == '_') { + envNameStr++; + *p = *envNameStr; + if (*envNameStr == '\0') break; + } else { + *p = toLowChar(*envNameStr); + } + p++; + envNameStr++; + } + + *p = '\0'; + return strlen(cfgNameStr); +} + +int32_t taosEnvToCfg(const char *envStr, char *cfgStr) { + if (envStr == NULL && cfgStr == NULL) { + return -1; + } + if (cfgStr != envStr) strcpy(cfgStr, envStr); + char *p = strchr(cfgStr, '='); + + if (p != NULL) { + char buf[CFG_NAME_MAX_LEN]; + if (*(p+1) == '\'') { + *(p+1)= ' '; + char *pEnd = &cfgStr[strlen(cfgStr)-1]; + if (*pEnd == '\'') *pEnd = '\0'; + } + *p = '\0'; + int32_t cfgNameLen = taosEnvNameToCfgName(cfgStr, buf, CFG_NAME_MAX_LEN); + if (cfgNameLen > 0) { + memcpy(cfgStr, buf, cfgNameLen); + memset(&cfgStr[cfgNameLen], ' ', p - cfgStr - cfgNameLen + 1); + } + } + return strlen(cfgStr); +} \ No newline at end of file diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 0b9727e0bf666b660000d4a0a57b72a6eff65fcd..558c2258f46239e94e6eebbd1acae9081284c16c 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -144,6 +144,22 @@ char* tjsonToUnformattedString(const SJson* pJson) { return cJSON_PrintUnformatt SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) { return cJSON_GetObjectItem(pJson, pName); } +int32_t tjsonGetObjectName(const SJson* pJson, char** pName) { + *pName = ((cJSON*)pJson)->string; + if (NULL == *pName) { + return TSDB_CODE_FAILED; + } + return TSDB_CODE_SUCCESS; +} + +int32_t tjsonGetObjectValueString(const SJson* pJson, char** pValueString) { + *pValueString = ((cJSON*)pJson)->valuestring; + if (NULL == *pValueString) { + return TSDB_CODE_FAILED; + } + return TSDB_CODE_SUCCESS; +} + int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal) { char* p = cJSON_GetStringValue(tjsonGetObjectItem((cJSON*)pJson, pName)); if (NULL == p) { @@ -309,4 +325,6 @@ bool tjsonValidateJson(const char *jIn) { } } return true; -} \ No newline at end of file +} + +const char* tjsonGetError() { return cJSON_GetErrorPtr(); } \ No newline at end of file diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index d98f9f677d33eff7517c97ecfe9f2ab9538dd4e5..3c52d52d504852528874716a2237ad671e27cef4 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -31,7 +31,7 @@ ENDIF() # TARGET_LINK_LIBRARIES(trefTest util common) #ENDIF () -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc) # freelistTest add_executable(freelistTest "") diff --git a/source/util/test/cfgTest.cpp b/source/util/test/cfgTest.cpp index 712fb2d09a240037e99fd144a5030bb670ef606a..cd13ebe8ae3a07db3cd75ec39df3f5795566d1dc 100644 --- a/source/util/test/cfgTest.cpp +++ b/source/util/test/cfgTest.cpp @@ -32,6 +32,7 @@ TEST_F(CfgTest, 01_Str) { EXPECT_STREQ(cfgStypeStr(CFG_STYPE_CFG_FILE), "cfg_file"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_FILE), "env_file"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var"); + EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_CMD), "env_cmd"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_APOLLO_URL), "apollo_url"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ARG_LIST), "arg_list"); EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid"); diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index 5bbcceada5591454c6dcb639d6ee22112baf6073..69f15a164ef78fb750c5386683f0eb66f24d0b7e 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -28,8 +28,8 @@ char simScriptDir[PATH_MAX] = {0}; extern bool simExecSuccess; int32_t simInitCfg() { - taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, 1); - taosInitCfg(configDir, NULL, NULL, NULL, 1); + taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, NULL, 1); + taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1); SConfig *pCfg = taosGetCfg(); simDebugFlag = cfgGetItem(pCfg, "simDebugFlag")->i32; diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 3b22b3085211cc4fd99f00d84359305f17f0edd1..284693795ee471ad2d631758970c3033dc8e0c6c 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -3,7 +3,7 @@ aux_source_directory(src SHELL_SRC) add_executable(shell ${SHELL_SRC}) target_link_libraries( shell - PUBLIC taos_static + PUBLIC taos PRIVATE os common transport util ) target_include_directories(