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.
This commit is contained in:
Vladislav Vaintroub 2022-10-11 04:22:05 -07:00
parent e8101a4d03
commit 4fec99a2ba

View file

@ -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