Date: Tue, 29 Mar 2011 12:37:46 +1030 From: "Daniel O'Connor" <doconnor@gsoft.com.au> To: "Daniel O'Connor" <doconnor@gsoft.com.au> Cc: David Cornejo <dave@dogwood.com>, Doug Barton <dougb@freebsd.org>, Matthew Seaman <m.seaman@infracaninophile.co.uk>, freebsd-current@freebsd.org, Garrett Cooper <gcooper@freebsd.org> Subject: Re: tzsetup disregards setting TZ to UTC Message-ID: <EB0B73A0-6A9C-464E-B793-BA7771B059A4@gsoft.com.au> In-Reply-To: <869E9396-2663-455F-B7B2-4FADCBA5BD1C@gsoft.com.au> References: <4C1C73E8-7FAC-4039-B627-C244BA205A9F@gsoft.com.au> <AANLkTina75LmxFNctQEMtRmpU3dQEKaHYEAKZ7v1BaK7@mail.gmail.com> <AANLkTimuNmLysuGgnAtDa8Lfs-gwWJn0fzXC87v3PxWn@mail.gmail.com> <4D906C3F.8040404@FreeBSD.org> <4D90EC44.9030209@infracaninophile.co.uk> <AANLkTi=GXt5zwUr8BMjafdVwO-L-%2Bk_UZ4byyyN6nW98@mail.gmail.com> <4D91208C.7080804@FreeBSD.org> <AANLkTiker7sm2jURpVDaHg65jZu_Ki1e%2BMRiuWPOf59D@mail.gmail.com> <869E9396-2663-455F-B7B2-4FADCBA5BD1C@gsoft.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?EB0B73A0-6A9C-464E-B793-BA7771B059A4>