postgresql/src/bin
Tom Lane dd53b46c78 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
..
initdb Work around portability issue with newer versions of mktime(). 2021-06-13 14:32:42 -04:00
pg_archivecleanup Fix new warnings from GCC 7 2017-05-16 08:52:39 -04:00
pg_basebackup Translation updates 2020-11-09 12:47:52 +01:00
pg_config Translation updates 2020-11-09 12:47:52 +01:00
pg_controldata Translation updates 2020-08-10 15:34:18 +02:00
pg_ctl Translation updates 2020-11-09 12:47:52 +01:00
pg_dump Work around portability issue with newer versions of mktime(). 2021-06-13 14:32:42 -04:00
pg_resetxlog Translation updates 2020-08-10 15:34:18 +02:00
pg_rewind Translation updates 2021-02-08 18:10:23 +01:00
pg_test_fsync Switch pg_test_fsync to use binary mode on Windows 2020-07-16 15:53:09 +09:00
pg_test_timing Move pg_test_timing from contrib/ to src/bin/ 2015-04-20 21:30:12 -04:00
pg_upgrade Clean up cpluspluscheck violation. 2021-05-20 13:03:09 -04:00
pg_xlogdump pg_waldump: Fix bug in per-record statistics. 2021-03-23 09:55:49 +09:00
pgbench pgbench: Remove dead code 2021-01-28 12:50:40 -03:00
pgevent Update copyright for 2016 2016-01-02 13:33:40 -05:00
psql Fix inconsistencies in psql --help=commands 2021-06-09 16:26:11 +09:00
scripts Fix incautious handling of possibly-miscoded strings in client code. 2021-06-07 14:15:25 -04:00
Makefile Update copyright for 2016 2016-01-02 13:33:40 -05:00