diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2022-10-11 04:22:05 -0700 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2022-10-11 07:53:52 -0700 |
commit | 4fec99a2ba6034592d273d918402540d3d4fe772 (patch) | |
tree | 63944973d313dce8357b7142014b8c8eafdd4795 /sql | |
parent | e8101a4d033a59237d542f4bd0ae0b5323058e26 (diff) | |
download | mariadb-git-4fec99a2ba6034592d273d918402540d3d4fe772.tar.gz |
MDEV-29102 system_time_zone is incorrect on Windows when TZ is set
MDEV-19243 introduced a regression on Windows.
In (supposedly rare) case, where environment variable TZ was set,
@@system_time_zone no longer derives from TZ. Instead, it incorrecty
refers to system default time zone, eventhough UTC time conversion
takes TZ into account.
The fix is to restore TZ-aware handling (timezone name derives from
tzname), if TZ is set.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/mysqld.cc | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6e68876537f..8c70a0d3145 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4303,14 +4303,24 @@ static int init_common_variables() if (ignore_db_dirs_init()) exit(1); -#ifdef _WIN32 - get_win_tzname(system_time_zone, sizeof(system_time_zone)); -#elif defined(HAVE_TZNAME) struct tm tm_tmp; - localtime_r(&server_start_time,&tm_tmp); - const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]; - strmake_buf(system_time_zone, tz_name); -#endif /* HAVE_TZNAME */ + localtime_r(&server_start_time, &tm_tmp); + +#ifdef HAVE_TZNAME +#ifdef _WIN32 + /* + If env.variable TZ is set, derive timezone name from it. + Otherwise, use IANA tz name from get_win_tzname. + */ + if (!getenv("TZ")) + get_win_tzname(system_time_zone, sizeof(system_time_zone)); + else +#endif + { + const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]; + strmake_buf(system_time_zone, tz_name); + } +#endif /* We set SYSTEM time zone as reasonable default and |