diff --git a/include/os/os.h b/include/os/os.h index b05bfab6d02b5bdd8e1c7fe8be8ad39f10feed5b..e7ce7d09eafffcb51c5582829788af7417e7fbcb 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -75,7 +75,6 @@ extern "C" { #include "osDef.h" #include "osDir.h" #include "osEndian.h" -#include "osEnv.h" #include "osFile.h" #include "osLocale.h" #include "osLz4.h" @@ -93,8 +92,9 @@ extern "C" { #include "osTime.h" #include "osTimer.h" #include "osTimezone.h" +#include "osEnv.h" -void osInit(); +void osDefaultInit(); #ifdef __cplusplus } diff --git a/include/os/osEnv.h b/include/os/osEnv.h index ebf4c360dd7c5c65672d70248b060960517a5ff4..14d50858b77d23836091eed1508e755a12cd74fe 100644 --- a/include/os/osEnv.h +++ b/include/os/osEnv.h @@ -22,17 +22,18 @@ extern "C" { #endif -extern char tsOsName[]; -extern char tsTimezone[]; -extern char tsCharset[]; -extern char tsLocale[]; -extern int8_t tsDaylight; -extern bool tsEnableCoreFile; -extern int64_t tsPageSizeKB; -extern int64_t tsOpenMax; -extern int64_t tsStreamMax; -extern float tsNumOfCores; -extern int64_t tsTotalMemoryKB; +extern char tsOsName[]; +extern char tsTimezoneStr[]; +extern enum TdTimezone tsTimezone; +extern char tsCharset[]; +extern char tsLocale[]; +extern int8_t tsDaylight; +extern bool tsEnableCoreFile; +extern int64_t tsPageSizeKB; +extern int64_t tsOpenMax; +extern int64_t tsStreamMax; +extern float tsNumOfCores; +extern int64_t tsTotalMemoryKB; extern char configDir[]; extern char tsDataDir[]; @@ -43,11 +44,12 @@ extern SDiskSpace tsDataSpace; extern SDiskSpace tsLogSpace; extern SDiskSpace tsTempSpace; -void osInit(); +void osDefaultInit(); void osUpdate(); void osCleanup(); bool osLogSpaceAvailable(); void osSetTimezone(const char *timezone); +void osSetSystemLocale(const char *inLocale, const char *inCharSet); #ifdef __cplusplus } diff --git a/include/os/osTimezone.h b/include/os/osTimezone.h index c8df8c3f3d50ec1a105d23214bb9579731e0db9f..c259587264706fb7372e2a2ba566c10121b78525 100644 --- a/include/os/osTimezone.h +++ b/include/os/osTimezone.h @@ -26,8 +26,37 @@ extern "C" { #define tzset TZSET_FUNC_TAOS_FORBID #endif -void taosGetSystemTimezone(char *outTimezone); -void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight); +enum TdTimezone +{ + TdWestZone12=-12, + TdWestZone11, + TdWestZone10, + TdWestZone9, + TdWestZone8, + TdWestZone7, + TdWestZone6, + TdWestZone5, + TdWestZone4, + TdWestZone3, + TdWestZone2, + TdWestZone1, + TdZeroZero, + TdEastZone1, + TdEastZone2, + TdEastZone3, + TdEastZone4, + TdEastZone5, + TdEastZone6, + TdEastZone7, + TdEastZone8, + TdEastZone9, + TdEastZone10, + TdEastZone11, + TdEastZone12 +}; + +void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone); +void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone); #ifdef __cplusplus } diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index d9dcadbff0995edb2289d1cd03c45ec48aafb038..8e67703ce56d5cf1fad9150f001d4c8e63947913 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -408,10 +408,10 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { assert(cfg != NULL); if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - tstrncpy(tsTimezone, str, TD_TIMEZONE_LEN); + tstrncpy(tsTimezoneStr, str, TD_TIMEZONE_LEN); tsSetTimeZone(); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, str); + 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); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index a1bef49cc6661705b7f51d400a9d553d45c4a3c9..efd790ade8c143dd40b5cb9b0bfe749e0f57b06f 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -303,7 +303,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { static int32_t taosAddSystemCfg(SConfig *pCfg) { SysNameInfo info = taosGetSysNameInfo(); - if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1; + if (cfgAddTimezone(pCfg, "timezone", tsTimezoneStr) != 0) return -1; if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1; if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1; if (cfgAddBool(pCfg, "enableCoreFile", 1, 1) != 0) return -1; @@ -431,12 +431,13 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { static void taosSetSystemCfg(SConfig *pCfg) { SConfigItem *pItem = cfgGetItem(pCfg, "timezone"); osSetTimezone(pItem->str); - uDebug("timezone format changed from %s to %s", pItem->str, tsTimezone); - cfgSetItem(pCfg, "timezone", tsTimezone, pItem->stype); + uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr); + cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype); const char *locale = cfgGetItem(pCfg, "locale")->str; const char *charset = cfgGetItem(pCfg, "charset")->str; taosSetSystemLocale(locale, charset); + osSetSystemLocale(locale, charset); bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval; taosSetConsoleEcho(enableCore); @@ -483,7 +484,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) { - osInit(); + osDefaultInit(); SConfig *pCfg = cfgInit(); if (pCfg == NULL) return -1; diff --git a/source/dnode/mgmt/dnode/src/dmMsg.c b/source/dnode/mgmt/dnode/src/dmMsg.c index 836817e772a4a64fd541ca7e565d28b198143c9f..eb4e843c55e9f94a35c448ec5b4adae5022c3ef4 100644 --- a/source/dnode/mgmt/dnode/src/dmMsg.c +++ b/source/dnode/mgmt/dnode/src/dmMsg.c @@ -36,7 +36,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { req.clusterCfg.checkTime = 0; char timestr[32] = "1970-01-01 00:00:00.00"; (void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); - memcpy(req.clusterCfg.timezone, tsTimezone, TD_TIMEZONE_LEN); + memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN); memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); taosRUnLockLatch(&pMgmt->latch); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 55414124606b6f526300d94d2575e14ecbb5332f..314e70db9bb5352aba585380b03e632d139a355b 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -277,8 +277,8 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) { return DND_REASON_STATUS_INTERVAL_NOT_MATCH; } - if ((0 != strcasecmp(pCfg->timezone, tsTimezone)) && (pMnode->checkTime != pCfg->checkTime)) { - mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezone, + if ((0 != strcasecmp(pCfg->timezone, tsTimezoneStr)) && (pMnode->checkTime != pCfg->checkTime)) { + mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezoneStr, pCfg->checkTime, pMnode->checkTime); return DND_REASON_TIME_ZONE_NOT_MATCH; } @@ -677,7 +677,7 @@ static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, char *data, i totalRows++; cfgOpts[totalRows] = "timezone"; - snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezone); + snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezoneStr); totalRows++; cfgOpts[totalRows] = "locale"; diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index e0be9ed89a239cc29fa6f741af785fc4d8266d25..a14828cc22d0c65a55d453bf9d700cf0529506e3 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -176,7 +176,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } // record current timezone of server side - tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezone, TD_TIMEZONE_LEN); + tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) { // TODO: handle error diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index 61b2593bc6c3115f0d5f89c92e593082ad05fcf2..4847bbf2fee8abcc3834cc776ec70a4581e6b5d9 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -18,30 +18,31 @@ extern void taosWinSocketInit(); -char configDir[PATH_MAX] = {0}; -char tsDataDir[PATH_MAX] = {0}; -char tsLogDir[PATH_MAX] = {0}; -char tsTempDir[PATH_MAX] = {0}; -SDiskSpace tsDataSpace = {0}; -SDiskSpace tsLogSpace = {0}; -SDiskSpace tsTempSpace = {0}; -char tsOsName[16] = {0}; -char tsTimezone[TD_TIMEZONE_LEN] = {0}; -char tsLocale[TD_LOCALE_LEN] = {0}; -char tsCharset[TD_CHARSET_LEN] = {0}; -int8_t tsDaylight = 0; -bool tsEnableCoreFile = 0; -int64_t tsPageSizeKB = 0; -int64_t tsOpenMax = 0; -int64_t tsStreamMax = 0; -float tsNumOfCores = 0; -int64_t tsTotalMemoryKB = 0; - -void osInit() { +char configDir[PATH_MAX] = {0}; +char tsDataDir[PATH_MAX] = {0}; +char tsLogDir[PATH_MAX] = {0}; +char tsTempDir[PATH_MAX] = {0}; +SDiskSpace tsDataSpace = {0}; +SDiskSpace tsLogSpace = {0}; +SDiskSpace tsTempSpace = {0}; +char tsOsName[16] = {0}; +char tsTimezoneStr[TD_TIMEZONE_LEN] = {0}; +enum TdTimezone tsTimezone = TdZeroZero; +char tsLocale[TD_LOCALE_LEN] = {0}; +char tsCharset[TD_CHARSET_LEN] = {0}; +int8_t tsDaylight = 0; +bool tsEnableCoreFile = 0; +int64_t tsPageSizeKB = 0; +int64_t tsOpenMax = 0; +int64_t tsStreamMax = 0; +float tsNumOfCores = 0; +int64_t tsTotalMemoryKB = 0; + +void osDefaultInit() { taosSeedRand(taosSafeRand()); taosGetSystemLocale(tsLocale, tsCharset); - taosGetSystemTimezone(tsTimezone); - taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight); + taosGetSystemTimezone(tsTimezoneStr, &tsTimezone); + taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone); taosGetSystemInfo(); // deadlock in query @@ -105,4 +106,9 @@ void osCleanup() {} bool osLogSpaceAvailable() { return tsLogSpace.reserved <= tsLogSpace.size.avail; } -void osSetTimezone(const char *timezone) { taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight); } +void osSetTimezone(const char *timezone) { taosSetSystemTimezone(timezone, tsTimezoneStr, &tsDaylight, &tsTimezone); } + +void osSetSystemLocale(const char *inLocale, const char *inCharSet) { + memcpy(tsLocale, inLocale, strlen(inLocale) + 1); + memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1); +} diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 3f47e475c36b90f59a5c4eddcefa537adaa5bf69..1adf9f9bf3f9f8c362e512391e6825b2a1e50172 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -16,8 +16,6 @@ #define ALLOW_FORBID_FUNC #include "os.h" -#define USE_TD_MEMORY - #define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S') #define TD_MEMORY_STACK_TRACE_DEPTH 10 @@ -47,16 +45,16 @@ int32_t taosBackTrace(void **buffer, int32_t size) { int32_t frame = 0; void **ebp; void **ret = NULL; - unsigned long long func_frame_distance = 0; + size_t func_frame_distance = 0; if (buffer != NULL && size > 0) { ebp = taosGetEbp(); - func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp; + func_frame_distance = (size_t)*ebp - (size_t)ebp; while (ebp && frame < size && (func_frame_distance < (1ULL << 24)) // assume function ebp more than 16M && (func_frame_distance > 0)) { ret = ebp + 1; buffer[frame++] = *ret; ebp = (void **)(*ebp); - func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp; + func_frame_distance = (size_t)*ebp - (size_t)ebp; } } return frame; diff --git a/source/os/src/osTimezone.c b/source/os/src/osTimezone.c index bdafa63d643b0a44be0bd1bfdbc7ed53540a584b..dc23eaae1a946f1a42a23ed9a28acce097b5b2c2 100644 --- a/source/os/src/osTimezone.c +++ b/source/os/src/osTimezone.c @@ -46,12 +46,22 @@ #include #endif -void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight) { - if (inTimezone == NULL || inTimezone[0] == 0) return; +void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight, enum TdTimezone *tsTimezone) { + if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) return; + + char *buf = taosMemoryMalloc(strlen(inTimezoneStr) + 1); + buf[strlen(inTimezoneStr)] = 0; + for (int32_t i = 0; i < strlen(inTimezoneStr); i++) { + if(inTimezoneStr[i]==' ' || inTimezoneStr[i]=='(') { + buf[i] = 0; + break; + } + buf[i] = inTimezoneStr[i]; + } #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) char winStr[TD_LOCALE_LEN * 2]; - sprintf(winStr, "TZ=%s", inTimezone); + sprintf(winStr, "TZ=%s", buf); putenv(winStr); tzset(); * get CURRENT time zone. @@ -70,44 +80,48 @@ void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *ou #endif int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR); + *tsTimezone = tz; tz += daylight; /* * format: * (CST, +0800) * (BST, +0100) */ - sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); + sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); *outDaylight = daylight; #elif defined(_TD_DARWIN_64) - setenv("TZ", inTimezone, 1); + setenv("TZ", buf, 1); tzset(); int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR); + *tsTimezone = tz; tz += daylight; - sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); + sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); *outDaylight = daylight; #else - setenv("TZ", inTimezone, 1); + setenv("TZ", buf, 1); tzset(); int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR); + *tsTimezone = tz; tz += daylight; - sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); + sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); *outDaylight = daylight; #endif + taosMemoryFree(buf); } -void taosGetSystemTimezone(char *outTimezone) { +void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) { #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) char *tz = getenv("TZ"); if (tz == NULL || strlen(tz) == 0) { - strcpy(outTimezone, "not configured"); + strcpy(outTimezoneStr, "not configured"); } else { - strcpy(outTimezone, tz); + strcpy(outTimezoneStr, tz); } #elif defined(_TD_DARWIN_64) @@ -153,7 +167,7 @@ void taosGetSystemTimezone(char *outTimezone) { * Asia/Shanghai (CST, +0800) * Europe/London (BST, +0100) */ - snprintf(outTimezone, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0], + snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0], -timezone / 3600); #else @@ -168,13 +182,14 @@ void taosGetSystemTimezone(char *outTimezone) { /* load time zone string from /etc/timezone */ // FILE *f = fopen("/etc/timezone", "r"); + errno = 0; TdFilePtr pFile = taosOpenFile("/etc/timezone", TD_FILE_READ); char buf[68] = {0}; if (pFile != NULL) { int len = taosReadFile(pFile, buf, 64); if (len < 64 && taosGetErrorFile(pFile)) { taosCloseFile(&pFile); - // printf("read /etc/timezone error, reason:%s", strerror(errno)); + printf("read /etc/timezone error, reason:%s", strerror(errno)); return; } @@ -202,6 +217,7 @@ void taosGetSystemTimezone(char *outTimezone) { * otherwise is GMT+00:00 */ int32_t tz = (-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR; + *tsTimezone = tz; tz += daylight; /* @@ -210,7 +226,7 @@ void taosGetSystemTimezone(char *outTimezone) { * Asia/Shanghai (CST, +0800) * Europe/London (BST, +0100) */ - snprintf(outTimezone, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); + snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); #endif }