Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf807e34

Browse files
committed
Work around portability issue with newer versions of mktime().
Recent glibc versions have made mktime() fail if tm_isdst isinconsistent with the prevailing timezone; in particular it fails fortm_isdst = 1 when the zone is UTC. (This seems wildly inconsistentwith the POSIX-mandated treatment of "incorrect" values for the otherfields of struct tm, so if you ask me it's a bug, but I bet they'llsay it's intentional.) This has been observed to cause cosmeticproblems when pg_restore'ing an archive created in a differenttimezone.To fix, do mktime() using the field values from the archive, and ifthat fails try again with tm_isdst = -1. This will give a resultthat's off by the UTC-offset difference from the original zone, butthat was true before, too. It's not terribly critical since we don'tdo anything with the result except possibly print it. (Someday weshould flush this entire bit of logic and record a standard-formattimestamp in the archive instead. That's not okay for a back-patchedbug fix, though.)Also, guard our only other use of mktime() by having initdb'sbuild_time_t() set tm_isdst = -1 not 0. This case could only havean 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 supportedversions, 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
1 parent9d97c34 commitf807e34

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

‎src/bin/initdb/findtimezone.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ build_time_t(int year, int month, int day)
195195
tm.tm_mday=day;
196196
tm.tm_mon=month-1;
197197
tm.tm_year=year-1900;
198+
tm.tm_isdst=-1;
198199

199200
returnmktime(&tm);
200201
}

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,7 +3703,6 @@ ReadHead(ArchiveHandle *AH)
37033703
vmin,
37043704
vrev;
37053705
intfmt;
3706-
structtmcrtm;
37073706

37083707
/*
37093708
* If we haven't already read the header, do so.
@@ -3771,6 +3770,8 @@ ReadHead(ArchiveHandle *AH)
37713770

37723771
if (AH->version >=K_VERS_1_4)
37733772
{
3773+
structtmcrtm;
3774+
37743775
crtm.tm_sec=ReadInt(AH);
37753776
crtm.tm_min=ReadInt(AH);
37763777
crtm.tm_hour=ReadInt(AH);
@@ -3779,12 +3780,32 @@ ReadHead(ArchiveHandle *AH)
37793780
crtm.tm_year=ReadInt(AH);
37803781
crtm.tm_isdst=ReadInt(AH);
37813782

3782-
AH->archdbname=ReadStr(AH);
3783-
3783+
/*
3784+
* Newer versions of glibc have mktime() report failure if tm_isdst is
3785+
* inconsistent with the prevailing timezone, e.g. tm_isdst = 1 when
3786+
* TZ=UTC. This is problematic when restoring an archive under a
3787+
* different timezone setting. If we get a failure, try again with
3788+
* tm_isdst set to -1 ("don't know").
3789+
*
3790+
* XXX with or without this hack, we reconstruct createDate
3791+
* incorrectly when the prevailing timezone is different from
3792+
* pg_dump's. Next time we bump the archive version, we should flush
3793+
* this representation and store a plain seconds-since-the-Epoch
3794+
* timestamp instead.
3795+
*/
37843796
AH->createDate=mktime(&crtm);
3785-
37863797
if (AH->createDate== (time_t)-1)
3787-
pg_log_warning("invalid creation date in header");
3798+
{
3799+
crtm.tm_isdst=-1;
3800+
AH->createDate=mktime(&crtm);
3801+
if (AH->createDate== (time_t)-1)
3802+
pg_log_warning("invalid creation date in header");
3803+
}
3804+
}
3805+
3806+
if (AH->version >=K_VERS_1_4)
3807+
{
3808+
AH->archdbname=ReadStr(AH);
37883809
}
37893810

37903811
if (AH->version >=K_VERS_1_10)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp