Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbuSf-0005af-KZ for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jun 2019 22:14:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hbuSe-0000NI-8K for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jun 2019 22:14:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbuSd-0000Eb-Sw for pgsql-hackers@lists.postgresql.org; Fri, 14 Jun 2019 22:14:16 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbuSa-0001Wj-S0 for pgsql-hackers@postgresql.org; Fri, 14 Jun 2019 22:14:14 +0000 Received: from [192.168.127.1] (port=63463 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1hbuSY-0005gh-3e; Fri, 14 Jun 2019 22:14:10 +0000 Received: from [127.0.0.1] (port=39552 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1hbuSX-000Ara-E9; Fri, 14 Jun 2019 22:14:09 +0000 From: Andrew Gierth To: Tom Lane Cc: Christoph Berg , PostgreSQL Hackers Subject: Re: UCT (Re: pgsql: Update time zone data files to tzdata release 2019a.) In-Reply-To: <875zp74zpf.fsf@news-spur.riddles.org.uk> (Andrew Gierth's message of "Fri, 14 Jun 2019 22:36:57 +0100") Message-ID: <871rzv4yes.fsf@news-spur.riddles.org.uk> References: <20190604085735.GD24018@msg.df7cb.de> <65800.1559662051@sss.pgh.pa.us> <20190605084735.GC15829@msg.df7cb.de> <24452.1560285699@sss.pgh.pa.us> <20190614095546.GA15107@msg.df7cb.de> <26948.1560517875@sss.pgh.pa.us> <87ef3w3u8a.fsf@news-spur.riddles.org.uk> <7114.1560539536@sss.pgh.pa.us> <875zp74zpf.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Fri, 14 Jun 2019 23:14:09 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=-=-= Content-Type: text/plain >>>>> "Andrew" == Andrew Gierth writes: >>>>> "Tom" == Tom Lane writes: >>> This isn't good enough, because it still picks "UCT" on a system >>> with no /etc/localtime and no TZ variable. Testing on HEAD as of >>> 3da73d683 (on FreeBSD, but it'll be the same anywhere else): Tom> [ shrug... ] Too bad. I doubt that that's a common situation anyway. Andrew> I'm also reminded that this applies also if the /etc/localtime Andrew> file is a _copy_ of the UTC zonefile rather than a symlink, Andrew> which is possibly even more common. And testing shows that if you select "UTC" when installing FreeBSD, you indeed get /etc/localtime as a copy not a symlink, and I've confirmed that initdb picks "UCT" in that case. So here is my current proposed fix. -- Andrew (irc:RhodiumToad) --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=utcpref.patch Content-Description: prefer UTC diff --git a/src/bin/initdb/findtimezone.c b/src/bin/initdb/findtimezone.c index 3477a08efd..f7c199a006 100644 --- a/src/bin/initdb/findtimezone.c +++ b/src/bin/initdb/findtimezone.c @@ -128,8 +128,11 @@ pg_load_tz(const char *name) * the C library's localtime() function. The database zone that matches * furthest into the past is the one to use. Often there will be several * zones with identical rankings (since the IANA database assigns multiple - * names to many zones). We break ties arbitrarily by preferring shorter, - * then alphabetically earlier zone names. + * names to many zones). We break ties by first checking for "preferred" + * names (such as "UTC"), and then arbitrarily by preferring shorter, then + * alphabetically earlier zone names. (If we did not explicitly prefer + * "UTC", we would get the alias name "UCT" instead due to alphabetic + * ordering.) * * Many modern systems use the IANA database, so if we can determine the * system's idea of which zone it is using and its behavior matches our zone @@ -602,6 +605,28 @@ check_system_link_file(const char *linkname, struct tztry *tt, #endif } +/* + * Given a timezone name, determine whether it should be preferred over other + * names which are equally good matches. The output is arbitrary but we will + * use 0 for "neutral" default preference. + * + * Ideally we'd prefer the zone.tab/zone1970.tab names, since in general those + * are the ones offered to the user to select from. But for the moment, to + * minimize changes in behaviour, simply prefer UTC over alternative spellings + * such as UCT that otherwise cause confusion. The existing "shortest first" + * rule would prefer "UTC" over "Etc/UTC" so keep that the same way (while + * still preferring Etc/UTC over Etc/UCT). + */ +static int +zone_name_pref(const char *zonename) +{ + if (strcmp(zonename, "UTC") == 0) + return 50; + if (strcmp(zonename, "Etc/UTC") == 0) + return 40; + return 0; +} + /* * Recursively scan the timezone database looking for the best match to * the system timezone behavior. @@ -674,7 +699,8 @@ scan_available_timezones(char *tzdir, char *tzdirsub, struct tztry *tt, else if (score == *bestscore) { /* Consider how to break a tie */ - if (strlen(tzdirsub) < strlen(bestzonename) || + if (zone_name_pref(tzdirsub) > zone_name_pref(bestzonename) || + strlen(tzdirsub) < strlen(bestzonename) || (strlen(tzdirsub) == strlen(bestzonename) && strcmp(tzdirsub, bestzonename) < 0)) strlcpy(bestzonename, tzdirsub, TZ_STRLEN_MAX + 1); --=-=-=--