Merge pull request #12341 from taosdata/fix/ZhiqiangWang/fix-15436-Ubuntu-18.04-timezone-error

fix(os): Ubuntu 18.04 timezone error.
This commit is contained in:
Zhiqiang Wang 2022-05-11 15:57:04 +08:00 committed by GitHub
commit d3bd0dedcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 98 additions and 96 deletions

View File

@ -172,6 +172,13 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
-timezone / 3600); -timezone / 3600);
#else #else
char buf[4096] = {0};
char *tz = NULL;
{
int n = readlink("/etc/localtime", buf, sizeof(buf));
if (n < 0) {
printf("read /etc/localtime error, reason:%s", strerror(errno));
if (taosCheckExistFile("/etc/timezone")) { if (taosCheckExistFile("/etc/timezone")) {
/* /*
* NOTE: do not remove it. * NOTE: do not remove it.
@ -228,12 +235,8 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
*/ */
snprintf(outTimezoneStr, 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));
} else { } else {
char buf[4096] = {0}; printf("There is not /etc/timezone.\n");
char *tz = NULL; }
{
int n = readlink("/etc/localtime", buf, sizeof(buf));
if (n < 0) {
printf("read /etc/localtime error, reason:%s", strerror(errno));
return; return;
} }
buf[n] = '\0'; buf[n] = '\0';
@ -272,6 +275,5 @@ 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);
}
#endif #endif
} }