Merge pull request #27876 from taosdata/fix/TD-31870/os3

Fix/td 31870/os3
This commit is contained in:
Pan Wei 2024-09-14 11:24:31 +08:00 committed by GitHub
commit c32d8312bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 111 additions and 96 deletions

View File

@ -54,7 +54,7 @@ enum TdTimezone {
TdEastZone12 TdEastZone12
}; };
void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone); int32_t taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone);
int32_t taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone); int32_t taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -157,6 +157,7 @@ int32_t taosGetErrSize();
#define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138) #define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138)
#define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139) #define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139)
#define TSDB_CODE_UNSUPPORT_OS TAOS_DEF_ERROR_CODE(0, 0x013A) #define TSDB_CODE_UNSUPPORT_OS TAOS_DEF_ERROR_CODE(0, 0x013A)
#define TSDB_CODE_TIME_ERROR TAOS_DEF_ERROR_CODE(0, 0x013B)
//client //client
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200) #define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)

View File

@ -1712,7 +1712,10 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *
SArray *pArgs) { SArray *pArgs) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if (tsCfg == NULL) osDefaultInit(); if (tsCfg == NULL) code = osDefaultInit();
if (code != 0) {
(void)printf("failed to init os since %s\n", tstrerror(code));
}
SConfig *pCfg = NULL; SConfig *pCfg = NULL;
TAOS_CHECK_RETURN(cfgInit(&pCfg)); TAOS_CHECK_RETURN(cfgInit(&pCfg));

View File

@ -127,7 +127,10 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId); snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId);
float numCpuCores = 4; float numCpuCores = 4;
taosGetCpuCores(&numCpuCores, false); int32_t code = taosGetCpuCores(&numCpuCores, false);
if(code != 0) {
fnError("failed to get cpu cores, code:%d", code);
}
numCpuCores = TMAX(numCpuCores, 2); numCpuCores = TMAX(numCpuCores, 2);
snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores * 2); snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores * 2);

View File

@ -109,8 +109,8 @@ void taosRemoveDir(const char *dirname) {
} }
} }
(void)taosCloseDir(&pDir); TAOS_UNUSED(taosCloseDir(&pDir));
(void)rmdir(dirname); TAOS_UNUSED(rmdir(dirname));
// printf("dir:%s is removed\n", dirname); // printf("dir:%s is removed\n", dirname);
return; return;
@ -374,7 +374,7 @@ int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
bool taosIsDir(const char *dirname) { bool taosIsDir(const char *dirname) {
TdDirPtr pDir = taosOpenDir(dirname); TdDirPtr pDir = taosOpenDir(dirname);
if (pDir != NULL) { if (pDir != NULL) {
(void)taosCloseDir(&pDir); TAOS_SKIP_ERROR(taosCloseDir(&pDir));
return true; return true;
} }
return false; return false;

View File

@ -50,7 +50,10 @@ int32_t osDefaultInit() {
taosSeedRand(taosSafeRand()); taosSeedRand(taosSafeRand());
taosGetSystemLocale(tsLocale, tsCharset); taosGetSystemLocale(tsLocale, tsCharset);
taosGetSystemTimezone(tsTimezoneStr, &tsTimezone); code = taosGetSystemTimezone(tsTimezoneStr, &tsTimezone);
if(code != 0) {
return code;
}
if (strlen(tsTimezoneStr) > 0) { // ignore empty timezone if (strlen(tsTimezoneStr) > 0) { // ignore empty timezone
if ((code = taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone)) != TSDB_CODE_SUCCESS) if ((code = taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone)) != TSDB_CODE_SUCCESS)
return code; return code;

View File

@ -69,7 +69,7 @@ uint32_t taosSafeRand(void) {
if (len < 0) { if (len < 0) {
seed = (int)taosGetTimestampSec(); seed = (int)taosGetTimestampSec();
} }
(void)taosCloseFile(&pFile); TAOS_SKIP_ERROR(taosCloseFile(&pFile));
} }
return (uint32_t)seed; return (uint32_t)seed;

View File

@ -37,7 +37,7 @@ void taosMsleep(int32_t ms) {
#ifdef WINDOWS #ifdef WINDOWS
Sleep(ms); Sleep(ms);
#else #else
(void)usleep(ms * 1000); TAOS_SKIP_ERROR(usleep(ms * 1000));
#endif #endif
} }
@ -49,10 +49,15 @@ void taosUsleep(int32_t us) {
interval.QuadPart = (10 * us); interval.QuadPart = (10 * us);
timer = CreateWaitableTimer(NULL, TRUE, NULL); timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0); if (timer == NULL) {
WaitForSingleObject(timer, INFINITE); return;
CloseHandle(timer); }
if (!SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0)) {
return;
}
TAOS_SKIP_ERROR(WaitForSingleObject(timer, INFINITE));
TAOS_SKIP_ERROR(CloseHandle(timer));
#else #else
(void)usleep(us); TAOS_SKIP_ERROR(usleep(us));
#endif #endif
} }

View File

@ -120,7 +120,12 @@ int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t
int32_t taosCloseSocketNoCheck1(SocketFd fd) { int32_t taosCloseSocketNoCheck1(SocketFd fd) {
#ifdef WINDOWS #ifdef WINDOWS
return closesocket(fd); int ret = closesocket(fd);
if (ret == SOCKET_ERROR) {
int errorCode = WSAGetLastError();
return terrno = TAOS_SYSTEM_WINSOCKET_ERROR(errorCode);
}
return 0;
#else #else
int32_t code = close(fd); int32_t code = close(fd);
if (-1 == code) { if (-1 == code) {
@ -770,10 +775,7 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket));
if (pSocket == NULL) { if (pSocket == NULL) {
code = terrno; TAOS_SKIP_ERROR(taosCloseSocketNoCheck1(fd));
(void)taosCloseSocketNoCheck1(fd);
terrno = code;
return false; return false;
} }
pSocket->refId = 0; pSocket->refId = 0;
@ -782,22 +784,18 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
/* set REUSEADDR option, so the portnumber can be re-used */ /* set REUSEADDR option, so the portnumber can be re-used */
reuse = 1; reuse = 1;
if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) {
code = terrno; TAOS_SKIP_ERROR(taosCloseSocket(&pSocket));
(void)taosCloseSocket(&pSocket);
terrno = code;
return false; return false;
} }
/* bind socket to server address */ /* bind socket to server address */
if (-1 == bind(pSocket->fd, (struct sockaddr *)&serverAdd, sizeof(serverAdd))) { if (-1 == bind(pSocket->fd, (struct sockaddr *)&serverAdd, sizeof(serverAdd))) {
code = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
(void)taosCloseSocket(&pSocket); TAOS_SKIP_ERROR(taosCloseSocket(&pSocket));
terrno = code;
return false; return false;
} }
(void)taosCloseSocket(&pSocket); TAOS_SKIP_ERROR(taosCloseSocket(&pSocket));
return true; return true;
} }
@ -1160,9 +1158,8 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) {
#else // Linux like systems #else // Linux like systems
uint32_t conn_timeout_ms = timeout; uint32_t conn_timeout_ms = timeout;
if (-1 == setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *)&conn_timeout_ms, sizeof(conn_timeout_ms))) { if (-1 == setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *)&conn_timeout_ms, sizeof(conn_timeout_ms))) {
int32_t code = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
(void)taosCloseSocketNoCheck1(fd); TAOS_SKIP_ERROR(taosCloseSocketNoCheck1(fd));
terrno = code;
return -1; return -1;
} }
#endif #endif

View File

@ -191,10 +191,11 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
&cpuInfo->si, &cpuInfo->st, &cpuInfo->guest, &cpuInfo->guest_nice); &cpuInfo->si, &cpuInfo->st, &cpuInfo->guest, &cpuInfo->guest_nice);
if (EOF == code) { if (EOF == code) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
return terrno; return terrno;
} }
(void)taosCloseFile(&pFile); TAOS_SKIP_ERROR(taosCloseFile(&pFile));
#endif #endif
return 0; return 0;
@ -263,9 +264,9 @@ bool taosCheckSystemIsLittleEnd() {
void taosGetSystemInfo() { void taosGetSystemInfo() {
#ifdef WINDOWS #ifdef WINDOWS
taosGetCpuCores(&tsNumOfCores, false); TAOS_SKIP_ERROR(taosGetCpuCores(&tsNumOfCores, false));
taosGetTotalMemory(&tsTotalMemoryKB); TAOS_SKIP_ERROR(taosGetTotalMemory(&tsTotalMemoryKB));
taosGetCpuUsage(NULL, NULL); TAOS_SKIP_ERROR(taosGetCpuUsage(NULL, NULL));
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
long physical_pages = sysconf(_SC_PHYS_PAGES); long physical_pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGESIZE); long page_size = sysconf(_SC_PAGESIZE);
@ -274,10 +275,10 @@ void taosGetSystemInfo() {
tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN); tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN);
#else #else
taosGetProcIOnfos(); taosGetProcIOnfos();
(void)taosGetCpuCores(&tsNumOfCores, false); TAOS_SKIP_ERROR(taosGetCpuCores(&tsNumOfCores, false));
(void)taosGetTotalMemory(&tsTotalMemoryKB); TAOS_SKIP_ERROR(taosGetTotalMemory(&tsTotalMemoryKB));
(void)taosGetCpuUsage(NULL, NULL); TAOS_SKIP_ERROR(taosGetCpuUsage(NULL, NULL));
(void)taosGetCpuInstructions(&tsSSE42Supported, &tsAVXSupported, &tsAVX2Supported, &tsFMASupported, &tsAVX512Supported); TAOS_SKIP_ERROR(taosGetCpuInstructions(&tsSSE42Supported, &tsAVXSupported, &tsAVX2Supported, &tsFMASupported, &tsAVX512Supported));
#endif #endif
} }
@ -313,11 +314,11 @@ int32_t taosGetEmail(char *email, int32_t maxLen) {
if (taosReadFile(pFile, (void *)email, maxLen) < 0) { if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
int32_t code = terrno; int32_t code = terrno;
(void)taosCloseFile(&pFile); TAOS_SKIP_ERROR(taosCloseFile(&pFile));
return code; return code;
} }
(void)taosCloseFile(&pFile); TAOS_SKIP_ERROR(taosCloseFile(&pFile));
return 0; return 0;
#endif #endif
@ -748,7 +749,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
char tmp[10]; char tmp[10];
(void)sscanf(line, "%s %" PRId64, tmp, usedKB); (void)sscanf(line, "%s %" PRId64, tmp, usedKB);
(void)taosCloseFile(&pFile); TAOS_SKIP_ERROR(taosCloseFile(&pFile));
return 0; return 0;
#endif #endif
@ -1045,7 +1046,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
return terrno; return terrno;
} else { } else {
len = taosReadFile(pFile, uid, uidlen); len = taosReadFile(pFile, uid, uidlen);
(void)taosCloseFile(&pFile); TAOS_SKIP_ERROR(taosCloseFile(&pFile));
if (len < 0) { if (len < 0) {
return len; return len;
} }
@ -1087,7 +1088,7 @@ char *taosGetCmdlineByPID(int pid) {
cmdline[n] = 0; cmdline[n] = 0;
(void)taosCloseFile(&pFile); TAOS_SKIP_ERROR(taosCloseFile(&pFile));
} else { } else {
cmdline[0] = 0; cmdline[0] = 0;
} }

View File

@ -80,7 +80,7 @@ void taos_block_sigalrm(void) {
static void taosDeleteTimer(void *tharg) { static void taosDeleteTimer(void *tharg) {
timer_t *pTimer = tharg; timer_t *pTimer = tharg;
(void)timer_delete(*pTimer); TAOS_SKIP_ERROR(timer_delete(*pTimer));
} }
static TdThread timerThread; static TdThread timerThread;

View File

@ -811,7 +811,11 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
setenv("TZ", buf, 1); code = setenv("TZ", buf, 1);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
tzset(); tzset();
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR); int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
*tsTimezone = tz; *tsTimezone = tz;
@ -839,13 +843,17 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
return code; return code;
} }
void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) { int32_t taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
int32_t code = 0;
#ifdef WINDOWS #ifdef WINDOWS
char value[100]; char value[100];
char keyPath[100]; char keyPath[100];
DWORD bufferSize = sizeof(value); DWORD bufferSize = sizeof(value);
RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", "TimeZoneKeyName", LONG result = RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", "TimeZoneKeyName",
RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize); RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
if (result != ERROR_SUCCESS) {
return TAOS_SYSTEM_WINAPI_ERROR(result);
}
strcpy(outTimezoneStr, "not configured"); strcpy(outTimezoneStr, "not configured");
*tsTimezone = 0; *tsTimezone = 0;
if (bufferSize > 0) { if (bufferSize > 0) {
@ -854,7 +862,10 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
strcpy(outTimezoneStr, win_tz[i][1]); strcpy(outTimezoneStr, win_tz[i][1]);
bufferSize = sizeof(value); bufferSize = sizeof(value);
sprintf(keyPath, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s", value); sprintf(keyPath, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s", value);
RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize); result = RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
if (result != ERROR_SUCCESS) {
return TAOS_SYSTEM_WINAPI_ERROR(result);
}
if (bufferSize > 0) { if (bufferSize > 0) {
// value[4] = (value[4] == '+' ? '-' : '+'); // value[4] = (value[4] == '+' ? '-' : '+');
sprintf(outTimezoneStr, "%s (UTC, %c%c%c%c%c)", outTimezoneStr, value[4], value[5], value[6], value[8], sprintf(outTimezoneStr, "%s (UTC, %c%c%c%c%c)", outTimezoneStr, value[4], value[5], value[6], value[8],
@ -865,39 +876,28 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
} }
} }
} }
return 0;
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
char buf[4096] = {0}; char buf[4096] = {0};
char *tz = NULL; char *tz = NULL;
{ {
int n = readlink("/etc/localtime", buf, sizeof(buf)); int n = readlink("/etc/localtime", buf, sizeof(buf));
if (n < 0) { if (n < 0) {
printf("read /etc/localtime error, reason:%s\n", strerror(errno)); return TSDB_CODE_TIME_ERROR;
return;
} }
buf[n] = '\0'; buf[n] = '\0';
char *zi = strstr(buf, "zoneinfo"); char *zi = strstr(buf, "zoneinfo");
if (!zi) { if (!zi) {
printf("parsing /etc/localtime failed\n"); return TSDB_CODE_TIME_ERROR;
return;
} }
tz = zi + strlen("zoneinfo") + 1; tz = zi + strlen("zoneinfo") + 1;
// for (int i = n - 1; i >= 0; --i) { code = setenv("TZ", tz, 1);
// if (buf[i] == '/') { if (-1 == code) {
// if (tz) { terrno = TAOS_SYSTEM_ERROR(errno);
// tz = buf + i + 1; return terrno;
// break; }
// }
// tz = buf + i + 1;
// }
// }
// if (!tz || 0 == strchr(tz, '/')) {
// printf("parsing /etc/localtime failed\n");
// return;
// }
setenv("TZ", tz, 1);
tzset(); tzset();
} }
@ -908,7 +908,9 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
*/ */
time_t tx1 = taosGetTimestampSec(); time_t tx1 = taosGetTimestampSec();
struct tm tm1; struct tm tm1;
taosLocalTime(&tx1, &tm1, NULL); if (taosLocalTime(&tx1, &tm1, NULL) == NULL) {
return TSDB_CODE_TIME_ERROR;
}
daylight = tm1.tm_isdst; daylight = tm1.tm_isdst;
isdst_now = tm1.tm_isdst; isdst_now = tm1.tm_isdst;
@ -920,6 +922,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
*/ */
snprintf(outTimezoneStr, 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); -timezone / 3600);
return 0;
#else #else
char buf[4096] = {0}; char buf[4096] = {0};
@ -927,8 +930,6 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
{ {
int n = readlink("/etc/localtime", buf, sizeof(buf)-1); int n = readlink("/etc/localtime", buf, sizeof(buf)-1);
if (n < 0) { if (n < 0) {
(void)printf("read /etc/localtime error, reason:%s\n", strerror(errno));
if (taosCheckExistFile("/etc/timezone")) { if (taosCheckExistFile("/etc/timezone")) {
/* /*
* NOTE: do not remove it. * NOTE: do not remove it.
@ -937,7 +938,9 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
*/ */
time_t tx1 = taosGetTimestampSec(); time_t tx1 = taosGetTimestampSec();
struct tm tm1; struct tm tm1;
(void)taosLocalTime(&tx1, &tm1, NULL); if(taosLocalTime(&tx1, &tm1, NULL) == NULL) {
return TSDB_CODE_TIME_ERROR;
}
/* load time zone string from /etc/timezone */ /* load time zone string from /etc/timezone */
// FILE *f = fopen("/etc/timezone", "r"); // FILE *f = fopen("/etc/timezone", "r");
errno = 0; errno = 0;
@ -946,12 +949,11 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
if (pFile != NULL) { if (pFile != NULL) {
int len = taosReadFile(pFile, buf, 64); int len = taosReadFile(pFile, buf, 64);
if (len < 0) { if (len < 0) {
(void)taosCloseFile(&pFile); TAOS_UNUSED(taosCloseFile(&pFile));
(void)printf("read /etc/timezone error, reason:%s\n", strerror(errno)); return TSDB_CODE_TIME_ERROR;
return;
} }
(void)taosCloseFile(&pFile); TAOS_UNUSED(taosCloseFile(&pFile));
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = 0;
char *lineEnd = strstr(buf, "\n"); char *lineEnd = strstr(buf, "\n");
@ -961,7 +963,11 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
// for CentOS system, /etc/timezone does not exist. Ignore the TZ environment variables // for CentOS system, /etc/timezone does not exist. Ignore the TZ environment variables
if (strlen(buf) > 0) { if (strlen(buf) > 0) {
(void)setenv("TZ", buf, 1); code = setenv("TZ", buf, 1);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
} }
} }
// get and set default timezone // get and set default timezone
@ -986,34 +992,23 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
(void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", (void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-",
abs(tz)); abs(tz));
} else { } else {
(void)printf("There is not /etc/timezone.\n"); return TSDB_CODE_TIME_ERROR;
} }
return; return 0;
} }
buf[n] = '\0'; buf[n] = '\0';
char *zi = strstr(buf, "zoneinfo"); char *zi = strstr(buf, "zoneinfo");
if (!zi) { if (!zi) {
(void)printf("parsing /etc/localtime failed\n"); return TSDB_CODE_TIME_ERROR;
return;
} }
tz = zi + strlen("zoneinfo") + 1; tz = zi + strlen("zoneinfo") + 1;
// for (int i = n - 1; i >= 0; --i) { code = setenv("TZ", tz, 1);
// if (buf[i] == '/') { if (-1 == code) {
// if (tz) { terrno = TAOS_SYSTEM_ERROR(errno);
// tz = buf + i + 1; return terrno;
// break; }
// }
// tz = buf + i + 1;
// }
// }
// if (!tz || 0 == strchr(tz, '/')) {
// printf("parsing /etc/localtime failed");
// return;
// }
(void)setenv("TZ", tz, 1);
tzset(); tzset();
} }
@ -1024,7 +1019,9 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
*/ */
time_t tx1 = taosGetTimestampSec(); time_t tx1 = taosGetTimestampSec();
struct tm tm1; struct tm tm1;
(void)taosLocalTime(&tx1, &tm1, NULL); if(taosLocalTime(&tx1, &tm1, NULL) == NULL) {
return TSDB_CODE_TIME_ERROR;
}
isdst_now = tm1.tm_isdst; isdst_now = tm1.tm_isdst;
/* /*
@ -1035,5 +1032,6 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
*/ */
(void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0], (void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
-timezone / 3600); -timezone / 3600);
return 0;
#endif #endif
} }

View File

@ -112,6 +112,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_FAILED_TO_CONNECT_S3, "Failed to connect to
TAOS_DEFINE_ERROR(TSDB_CODE_MSG_PREPROCESSED, "Message has been processed in preprocess") TAOS_DEFINE_ERROR(TSDB_CODE_MSG_PREPROCESSED, "Message has been processed in preprocess")
TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_BUFFER, "Out of buffer") TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_BUFFER, "Out of buffer")
TAOS_DEFINE_ERROR(TSDB_CODE_INTERNAL_ERROR, "Internal error") TAOS_DEFINE_ERROR(TSDB_CODE_INTERNAL_ERROR, "Internal error")
TAOS_DEFINE_ERROR(TSDB_CODE_TIME_ERROR, "Internal error in time")
//client //client
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_OPERATION, "Invalid operation") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_OPERATION, "Invalid operation")

View File

@ -215,7 +215,10 @@ int32_t taosInitSlowLog() {
int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) { int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) {
if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0; if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0;
TAOS_CHECK_RETURN(osUpdate()); int32_t code = osUpdate();
if (code != 0) {
uError("failed to update os info, reason:%s", tstrerror(code));
}
TAOS_CHECK_RETURN(taosInitNormalLog(logName, maxFiles)); TAOS_CHECK_RETURN(taosInitNormalLog(logName, maxFiles));
if (tsc){ if (tsc){