--- 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);