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

Commit3754113

Browse files
committed
Avoid choosing "localtime" or "posixrules" as TimeZone during initdb.
Some platforms create a file named "localtime" in the systemtimezone directory, making it a copy or link to the active timezone file. If Postgres is built with --with-system-tzdata, initdbwill see that file as an exact match to localtime(3)'s behavior,and it may decide that "localtime" is the most preferred spelling ofthe active zone. That's a very bad choice though, because it'sneither informative, nor portable, nor stable if someone changesthe system timezone setting. Extend the preference logic added bycommite3846a0 so that we will prefer any other zone file thatmatches localtime's behavior over "localtime".On the same logic, also discriminate against "posixrules", whichis another not-really-a-zone file that is often present in thetimezone directory. (Since we install "posixrules" but not"localtime", this change can affect the behavior of Postgreswith or without --with-system-tzdata.)Note that this change doesn't prevent anyone from choosing thesepseudo-zones if they really want to (i.e., by setting TZ for initdb,or modifying the timezone GUC later on). It just prevents initdbfrom preferring these zone names when there are multiple matches tolocaltime's behavior.Since we generally prefer to keep timezone-related behavior thesame in all branches, and since this is arguably a bug fix,back-patch to all supported branches.Discussion:https://postgr.es/m/CADT4RqCCnj6FKLisvT8tTPfTP4azPhhDFJqDF1JfBbOH5w4oyQ@mail.gmail.comDiscussion:https://postgr.es/m/27991.1560984458@sss.pgh.pa.us
1 parentb9d2c5c commit3754113

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

‎src/bin/initdb/findtimezone.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,22 +608,28 @@ check_system_link_file(const char *linkname, struct tztry *tt,
608608
/*
609609
* Given a timezone name, determine whether it should be preferred over other
610610
* names which are equally good matches. The output is arbitrary but we will
611-
* use 0 for "neutral" default preference.
612-
*
613-
* Ideally we'd prefer the zone.tab/zone1970.tab names, since in general those
614-
* are the ones offered to the user to select from. But for the moment, to
615-
* minimize changes in behaviour, simply prefer UTC over alternative spellings
616-
* such as UCT that otherwise cause confusion. The existing "shortest first"
617-
* rule would prefer "UTC" over "Etc/UTC" so keep that the same way (while
618-
* still preferring Etc/UTC over Etc/UCT).
611+
* use 0 for "neutral" default preference; larger values are more preferred.
619612
*/
620613
staticint
621614
zone_name_pref(constchar*zonename)
622615
{
616+
/*
617+
* Prefer UTC over alternatives such as UCT. Also prefer Etc/UTC over
618+
* Etc/UCT; but UTC is preferred to Etc/UTC.
619+
*/
623620
if (strcmp(zonename,"UTC")==0)
624621
return50;
625622
if (strcmp(zonename,"Etc/UTC")==0)
626623
return40;
624+
625+
/*
626+
* We don't want to pick "localtime" or "posixrules", unless we can find
627+
* no other name for the prevailing zone. Those aren't real zone names.
628+
*/
629+
if (strcmp(zonename,"localtime")==0||
630+
strcmp(zonename,"posixrules")==0)
631+
return-50;
632+
627633
return0;
628634
}
629635

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp