postgresql/src/bin/initdb
Tom Lane f807e3410f Work around portability issue with newer versions of mktime().
Recent glibc versions have made mktime() fail if tm_isdst is
inconsistent with the prevailing timezone; in particular it fails for
tm_isdst = 1 when the zone is UTC.  (This seems wildly inconsistent
with the POSIX-mandated treatment of "incorrect" values for the other
fields of struct tm, so if you ask me it's a bug, but I bet they'll
say it's intentional.)  This has been observed to cause cosmetic
problems when pg_restore'ing an archive created in a different
timezone.

To fix, do mktime() using the field values from the archive, and if
that fails try again with tm_isdst = -1.  This will give a result
that's off by the UTC-offset difference from the original zone, but
that was true before, too.  It's not terribly critical since we don't
do anything with the result except possibly print it.  (Someday we
should flush this entire bit of logic and record a standard-format
timestamp in the archive instead.  That's not okay for a back-patched
bug fix, though.)

Also, guard our only other use of mktime() by having initdb's
build_time_t() set tm_isdst = -1 not 0.  This case could only have
an issue in zones that are DST year-round; but I think some do exist,
or could in future.

Per report from Wells Oliver.  Back-patch to all supported
versions, since any of them might need to run with a newer glibc.

Discussion: https://postgr.es/m/CAOC+FBWDhDHO7G-i1_n_hjRzCnUeFO+H-Czi1y10mFhRWpBrew@mail.gmail.com
2021-06-13 14:32:42 -04:00
..
po Translation updates 2021-05-17 14:30:27 +02:00
t Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
.gitignore Move wchar.c and encnames.c to src/common/. 2020-01-16 15:58:55 -05:00
findtimezone.c Work around portability issue with newer versions of mktime(). 2021-06-13 14:32:42 -04:00
initdb.c Split function definitions out of system_views.sql into a new file. 2021-04-16 18:37:02 -04:00
Makefile Update copyright for 2021 2021-01-02 13:06:25 -05:00
nls.mk Translation updates 2021-05-10 14:36:21 +02:00