diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 5022cb7be80773460f42844af10cc17290de658b..97f84f82d7d9055f85e9b7fb0422af0f0409b466 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -130,7 +130,6 @@ void taosCfgDynamicOptions(const char *option, const char *value); void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary); struct SConfig *taosGetCfg(); -int32_t taosAddClientLogCfg(SConfig *pCfg); #ifdef __cplusplus } diff --git a/include/util/tconfig.h b/include/util/tconfig.h index 0e1d352f9a8b2cdc4ab9bffb728868738b8b9cac..012368d9cba4ce62cb11ca4d3bacad8724e574d5 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -32,6 +32,7 @@ typedef enum { CFG_STYPE_ENV_VAR, CFG_STYPE_APOLLO_URL, CFG_STYPE_ARG_LIST, + CFG_STYPE_TAOS_OPTIONS } ECfgSrcType; typedef enum { diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 865c3ead27ce59c29f7815d5ba4c9694056c458b..ad736fb195bc627aab06d5274435e8a1ad71a56b 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -307,164 +307,50 @@ int taos_init() { } int taos_options_imp(TSDB_OPTION option, const char *str) { -#if 0 - SGlobalCfg *cfg = NULL; + if (option != TSDB_OPTION_CONFIGDIR) { + taos_init(); // initialize global config + } else { + tstrncpy(configDir, str, PATH_MAX); + tscInfo("set cfg:%s to %s", configDir, str); + return 0; + } + + SConfig *pCfg = taosGetCfg(); + SConfigItem *pItem = NULL; switch (option) { case TSDB_OPTION_CONFIGDIR: - cfg = taosGetConfigOption("configDir"); - assert(cfg != NULL); - - if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - tstrncpy(configDir, str, TSDB_FILENAME_LEN); - cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - tscInfo("set config file directory:%s", str); - } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, - tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); - } + pItem = cfgGetItem(pCfg, "configDir"); break; - case TSDB_OPTION_SHELL_ACTIVITY_TIMER: - cfg = taosGetConfigOption("shellActivityTimer"); - assert(cfg != NULL); - - if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - tsShellActivityTimer = atoi(str); - if (tsShellActivityTimer < 1) tsShellActivityTimer = 1; - if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600; - cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - tscInfo("set shellActivityTimer:%d", tsShellActivityTimer); - } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, str, - tsCfgStatusStr[cfg->cfgStatus], *(int32_t *)cfg->ptr); - } + pItem = cfgGetItem(pCfg, "shellActivityTimer"); break; - - case TSDB_OPTION_LOCALE: { // set locale - cfg = taosGetConfigOption("locale"); - assert(cfg != NULL); - - size_t len = strlen(str); - if (len == 0 || len > TD_LOCALE_LEN) { - tscInfo("Invalid locale:%s, use default", str); - return -1; - } - - if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - char sep = '.'; - - if (strlen(tsLocale) == 0) { // locale does not set yet - char *defaultLocale = setlocale(LC_CTYPE, ""); - - // The locale of the current OS does not be set correctly, so the default locale cannot be acquired. - // The launch of current system will abort soon. - if (defaultLocale == NULL) { - tscError("failed to get default locale, please set the correct locale in current OS"); - return -1; - } - - tstrncpy(tsLocale, defaultLocale, TD_LOCALE_LEN); - } - - // set the user specified locale - char *locale = setlocale(LC_CTYPE, str); - - if (locale != NULL) { // failed to set the user specified locale - tscInfo("locale set, prev locale:%s, new locale:%s", tsLocale, locale); - cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - } else { // set the user specified locale failed, use default LC_CTYPE as current locale - locale = setlocale(LC_CTYPE, tsLocale); - tscInfo("failed to set locale:%s, current locale:%s", str, tsLocale); - } - - tstrncpy(tsLocale, locale, TD_LOCALE_LEN); - - char *charset = strrchr(tsLocale, sep); - if (charset != NULL) { - charset += 1; - - charset = taosCharsetReplace(charset); - - if (taosValidateEncodec(charset)) { - if (strlen(tsCharset) == 0) { - tscInfo("charset set:%s", charset); - } else { - tscInfo("charset changed from %s to %s", tsCharset, charset); - } - - tstrncpy(tsCharset, charset, TD_LOCALE_LEN); - cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - - } else { - tscInfo("charset:%s is not valid in locale, charset remains:%s", charset, tsCharset); - } - - taosMemoryFree(charset); - } else { // it may be windows system - tscInfo("charset remains:%s", tsCharset); - } - } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, - tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); - } + case TSDB_OPTION_LOCALE: + pItem = cfgGetItem(pCfg, "locale"); break; - } - - case TSDB_OPTION_CHARSET: { - /* set charset will override the value of charset, assigned during system locale changed */ - cfg = taosGetConfigOption("charset"); - assert(cfg != NULL); - - size_t len = strlen(str); - if (len == 0 || len > TD_LOCALE_LEN) { - tscInfo("failed to set charset:%s", str); - return -1; - } - - if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - if (taosValidateEncodec(str)) { - if (strlen(tsCharset) == 0) { - tscInfo("charset is set:%s", str); - } else { - tscInfo("charset changed from %s to %s", tsCharset, str); - } - - tstrncpy(tsCharset, str, TD_LOCALE_LEN); - cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - } else { - tscInfo("charset:%s not valid", str); - } - } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, - tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); - } - + case TSDB_OPTION_CHARSET: + pItem = cfgGetItem(pCfg, "charset"); break; - } - case TSDB_OPTION_TIMEZONE: - cfg = taosGetConfigOption("timezone"); - assert(cfg != NULL); - - if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - tstrncpy(tsTimezoneStr, str, TD_TIMEZONE_LEN); - tsSetTimeZone(); - cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - tscDebug("timezone set:%s, input:%s by taos_options", tsTimezoneStr, str); - } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, - tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); - } + pItem = cfgGetItem(pCfg, "timezone"); break; - default: - // TODO return the correct error code to client in the format for taos_errstr() - tscError("Invalid option %d", option); - return -1; + break; } -#endif - return 0; + + if (pItem == NULL) { + tscError("Invalid option %d", option); + return -1; + } + + int code = cfgSetItem(pCfg, pItem->name, str, CFG_STYPE_TAOS_OPTIONS); + if (code != 0) { + tscError("failed to set cfg:%s to %s since %s", pItem->name, str, terrstr()); + } else { + tscInfo("set cfg:%s to %s", pItem->name, str); + } + + return code; } /** diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 06a6b8317dba302c3528c7cae0aac26d315aab9f..9a0af24319c07241bd6c9cbfcdaa4872b76ba59e 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -472,6 +472,8 @@ const char *cfgStypeStr(ECfgSrcType type) { return "apollo_url"; case CFG_STYPE_ARG_LIST: return "arg_list"; + case CFG_STYPE_TAOS_OPTIONS: + return "taos_options"; default: return "invalid"; }