From ee6343379cd0fb98f7bb1f64b2ad5f5bf1a2832c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 7 Jul 2022 11:04:40 +0530 Subject: [PATCH] fix(query): fix timezone parsing for /usr/share/localtime TD-16413 TD-16441 --- source/os/src/osTimezone.c | 58 ++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/source/os/src/osTimezone.c b/source/os/src/osTimezone.c index 724f81c66c..2ce2033a00 100644 --- a/source/os/src/osTimezone.c +++ b/source/os/src/osTimezone.c @@ -857,19 +857,27 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) { return; } buf[n] = '\0'; - for (int i = n - 1; i >= 0; --i) { - if (buf[i] == '/') { - if (tz) { - tz = buf + i + 1; - break; - } - tz = buf + i + 1; - } - } - if (!tz || 0 == strchr(tz, '/')) { + + char *zi = strstr(buf, "zoneinfo"); + if (!zi) { printf("parsing /etc/localtime failed"); return; } + tz = zi + strlen("zoneinfo") + 1; + + //for (int i = n - 1; i >= 0; --i) { + // if (buf[i] == '/') { + // if (tz) { + // tz = buf + i + 1; + // break; + // } + // tz = buf + i + 1; + // } + //} + //if (!tz || 0 == strchr(tz, '/')) { + // printf("parsing /etc/localtime failed"); + // return; + //} setenv("TZ", tz, 1); tzset(); @@ -900,7 +908,7 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) { int n = readlink("/etc/localtime", buf, sizeof(buf)); if (n < 0) { printf("read /etc/localtime error, reason:%s", strerror(errno)); - + if (taosCheckExistFile("/etc/timezone")) { /* * NOTE: do not remove it. @@ -962,19 +970,27 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) { return; } buf[n] = '\0'; - for (int i = n - 1; i >= 0; --i) { - if (buf[i] == '/') { - if (tz) { - tz = buf + i + 1; - break; - } - tz = buf + i + 1; - } - } - if (!tz || 0 == strchr(tz, '/')) { + + char *zi = strstr(buf, "zoneinfo"); + if (!zi) { printf("parsing /etc/localtime failed"); return; } + tz = zi + strlen("zoneinfo") + 1; + + //for (int i = n - 1; i >= 0; --i) { + // if (buf[i] == '/') { + // if (tz) { + // tz = buf + i + 1; + // break; + // } + // tz = buf + i + 1; + // } + //} + //if (!tz || 0 == strchr(tz, '/')) { + // printf("parsing /etc/localtime failed"); + // return; + //} setenv("TZ", tz, 1); tzset(); -- GitLab