From owner-freebsd-current@FreeBSD.ORG Tue Mar 29 02:07:58 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1B3CB106564A; Tue, 29 Mar 2011 02:07:58 +0000 (UTC) (envelope-from doconnor@gsoft.com.au) Received: from cain.gsoft.com.au (unknown [IPv6:2001:44b8:7c07:5581:266:e1ff:fe0c:8f16]) by mx1.freebsd.org (Postfix) with ESMTP id 601288FC0A; Tue, 29 Mar 2011 02:07:57 +0000 (UTC) Received: from ur.gsoft.com.au (Ur.gsoft.com.au [203.31.81.44]) (authenticated bits=0) by cain.gsoft.com.au (8.14.4/8.14.3) with ESMTP id p2T27lJG096169 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Tue, 29 Mar 2011 12:37:47 +1030 (CST) (envelope-from doconnor@gsoft.com.au) Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: multipart/mixed; boundary=Apple-Mail-7-934719525 From: "Daniel O'Connor" In-Reply-To: <869E9396-2663-455F-B7B2-4FADCBA5BD1C@gsoft.com.au> Date: Tue, 29 Mar 2011 12:37:46 +1030 Message-Id: References: <4C1C73E8-7FAC-4039-B627-C244BA205A9F@gsoft.com.au> <4D906C3F.8040404@FreeBSD.org> <4D90EC44.9030209@infracaninophile.co.uk> <4D91208C.7080804@FreeBSD.org> <869E9396-2663-455F-B7B2-4FADCBA5BD1C@gsoft.com.au> To: "Daniel O'Connor" X-Mailer: Apple Mail (2.1082) X-Spam-Score: -2.51 () ALL_TRUSTED,BAYES_00,T_RP_MATCHES_RCVD X-Scanned-By: MIMEDefang 2.67 on 203.31.81.10 Cc: David Cornejo , Doug Barton , Matthew Seaman , freebsd-current@freebsd.org, Garrett Cooper Subject: Re: tzsetup disregards setting TZ to UTC X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2011 02:07:58 -0000 --Apple-Mail-7-934719525 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 29/03/2011, at 12:11, Daniel O'Connor wrote: >=20 > On 29/03/2011, at 11:06, Garrett Cooper wrote: >>> I made the same complaint recently in a semi-private forum, so = you're not >>> alone. :) I just haven't taken the time to figure out how best to = "fix" it. >>=20 >> I'll provide a patch that I wrote to 'fix' the original behavior >> when I get home (before Eitan pointed out this was by design). It's >> trivial (<15 lines IIRC). >> Fixing UTC to show up in the menu is not that difficult either, >> but it might talk a bit more monkeying around. >=20 > I think having UTC in the TZ menu would be the way to go, I will see = if I can generate a patch for it. See attached diff or = http://www.gsoft.com.au/~doconnor/tzsetup-utc-menu.diff -- Daniel O'Connor software and network engineer for Genesis Software - http://www.gsoft.com.au "The nice thing about standards is that there are so many of them to choose from." -- Andrew Tanenbaum GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C --Apple-Mail-7-934719525 Content-Disposition: attachment; filename=tzsetup-utc-menu.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="tzsetup-utc-menu.diff" Content-Transfer-Encoding: 7bit --- tzsetup.c.orig 2011-03-29 01:41:13.000000000 +0000 +++ tzsetup.c 2011-03-29 02:04:15.000000000 +0000 @@ -66,10 +66,13 @@ static char *chrootenv = NULL; static void usage(void); +static int confirm_zone(const char *filename); static int continent_country_menu(dialogMenuItem *); +static int install_zoneinfo_file(const char *zoneinfo_file); static int set_zone_multi(dialogMenuItem *); static int set_zone_whole_country(dialogMenuItem *); static int set_zone_menu(dialogMenuItem *); +static int set_zone_utc(void); struct continent { dialogMenuItem *menu; @@ -79,7 +82,7 @@ }; static struct continent africa, america, antarctica, arctic, asia, atlantic; -static struct continent australia, europe, indian, pacific; +static struct continent australia, europe, indian, pacific, utc; static struct continent_names { const char *name; @@ -94,7 +97,9 @@ { "Australia", &australia }, { "Europe", &europe }, { "Indian", &indian }, - { "Pacific", &pacific } + { "Pacific", &pacific }, + { "UTC", &utc } + }; static struct continent_items { @@ -110,7 +115,8 @@ { "7", "Australia" }, { "8", "Europe" }, { "9", "Indian Ocean" }, - { "0", "Pacific Ocean" } + { "0", "Pacific Ocean" }, + { "a", "UTC" } }; #define NCONTINENTS \ @@ -128,6 +134,9 @@ int menulen; int rv; + if (!strcmp(continent->title, "UTC")) + return set_zone_utc(); + /* Short cut -- if there's only one country, don't post a menu. */ if (contp->nitems == 1) return (contp->menu[0].fire(&contp->menu[0])); @@ -502,6 +511,15 @@ return (DITEM_LEAVE_MENU); } +int +set_zone_utc(void) +{ + if (!confirm_zone(NULL)) + return (DITEM_FAILURE | DITEM_RECREATE); + + return (install_zoneinfo_file(NULL)); +} + static int install_zoneinfo_file(const char *zoneinfo_file) { @@ -526,7 +544,7 @@ else snprintf(prompt, sizeof(prompt), "Creating symbolic link %s to %s", - path_localtime, zoneinfo_file); + path_localtime, zoneinfo_file == NULL ? "(UTC)" : zoneinfo_file); if (usedialog) dialog_notify(prompt); else @@ -534,6 +552,22 @@ #endif if (reallydoit) { + if (zoneinfo_file == NULL) { + if (unlink(path_localtime) < 0 && errno != ENOENT) { + snprintf(title, sizeof(title), "Error"); + snprintf(prompt, sizeof(prompt), + "Could not delete %s: %s", path_localtime, + strerror(errno)); + if (usedialog) + dialog_mesgbox(title, prompt, 8, 72); + else + fprintf(stderr, "%s\n", prompt); + + return (DITEM_FAILURE | DITEM_RECREATE); + } + return (DITEM_LEAVE_MENU); + } + if (copymode) { fd1 = open(zoneinfo_file, O_RDONLY, 0); if (fd1 < 0) { @@ -656,7 +690,11 @@ struct tm *tm; int rv; - setenv("TZ", filename, 1); + if (filename == NULL) + setenv("TZ", "UTC", 1); + else + setenv("TZ", filename, 1); + tzset(); tm = localtime(&t); --Apple-Mail-7-934719525 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail-7-934719525--