2 * Copyright 1996 Massachusetts Institute of Technology
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose and without fee is hereby
6 * granted, provided that both the above copyright notice and this
7 * permission notice appear in all copies, that both the above
8 * copyright notice and this permission notice appear in all
9 * supporting documentation, and that the name of M.I.T. not be used
10 * in advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission. M.I.T. makes
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied
16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Second attempt at a `tzmenu' program, using the separate description
32 * files provided in newer tzdata releases.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
46 #include <sys/fcntl.h>
47 #include <sys/param.h>
48 #include <sys/queue.h>
50 #include <sys/sysctl.h>
53 #include <bsddialog.h>
57 #define _PATH_ZONETAB "/usr/share/zoneinfo/zone1970.tab"
58 #define _PATH_ISO3166 "/usr/share/misc/iso3166"
59 #define _PATH_ZONEINFO "/usr/share/zoneinfo"
60 #define _PATH_LOCALTIME "/etc/localtime"
61 #define _PATH_DB "/var/db/zoneinfo"
62 #define _PATH_WALL_CMOS_CLOCK "/etc/wall_cmos_clock"
65 #define SILLY_BUFFER_SIZE 2*PATH_MAX
67 #warning "Somebody needs to fix this to dynamically size this buffer."
68 #define SILLY_BUFFER_SIZE 2048
71 /* special return codes for `fire' actions */
72 #define DITEM_FAILURE 1
74 /* flags - returned in upper 16 bits of return status */
75 #define DITEM_LEAVE_MENU (1 << 16)
76 #define DITEM_RECREATE (1 << 18)
78 static char path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
79 path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN],
80 path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
82 static int reallydoit = 1;
83 static int reinstall = 0;
84 static char *chrootenv = NULL;
86 static void usage(void);
87 static int install_zoneinfo(const char *zoneinfo);
88 static void message_zoneinfo_file(const char *title, char *prompt);
89 static int install_zoneinfo_file(const char *zoneinfo_file);
92 static struct bsddialog_conf conf;
94 /* for use in describing more exotic behaviors */
95 typedef struct dialogMenuItem {
98 int (*fire)(struct dialogMenuItem *self);
103 xdialog_menu(char *title, char *cprompt, int item_no, dialogMenuItem *ditems)
105 int i, result, menurows, choice = 0;
106 struct bsddialog_menuitem *listitems;
108 /* initialize list items */
109 listitems = calloc(item_no + 1, sizeof(struct bsddialog_menuitem));
110 if (listitems == NULL)
111 errx(1, "Failed to allocate memory in xdialog_menu");
112 for (i = 0; i < item_no; i++) {
113 listitems[i].prefix = "";
114 listitems[i].depth = 0;
115 listitems[i].bottomdesc = "";
116 listitems[i].on = false;
117 listitems[i].name = ditems[i].prompt;
118 listitems[i].desc = ditems[i].title;
123 menurows = item_no < 16 ? item_no : 16;
124 result = bsddialog_menu(&conf, cprompt, BSDDIALOG_AUTOSIZE,
125 BSDDIALOG_AUTOSIZE, menurows, item_no, listitems, &choice);
131 if (ditems[choice].fire != NULL) {
134 status = ditems[choice].fire(ditems + choice);
135 if (status & DITEM_RECREATE) {
141 case BSDDIALOG_CANCEL:
151 static int usedialog = 1;
153 static int confirm_zone(const char *filename);
154 static int continent_country_menu(dialogMenuItem *);
155 static int set_zone_multi(dialogMenuItem *);
156 static int set_zone_whole_country(dialogMenuItem *);
157 static int set_zone_menu(dialogMenuItem *);
158 static int set_zone_utc(void);
161 dialogMenuItem *menu;
165 static struct continent africa, america, antarctica, asia, atlantic;
166 static struct continent australia, europe, indian, pacific, utc;
168 static struct continent_names {
170 struct continent *continent;
171 } continent_names[] = {
172 { "Africa", &africa },
173 { "America", &america },
174 { "Antarctica", &antarctica },
176 { "Atlantic", &atlantic },
177 { "Australia", &australia },
178 { "Europe", &europe },
179 { "Indian", &indian },
180 { "Pacific", &pacific },
184 static struct continent_items {
187 } continent_items[] = {
189 { "2", "America -- North and South" },
190 { "3", "Antarctica" },
192 { "5", "Atlantic Ocean" },
193 { "6", "Australia" },
195 { "8", "Indian Ocean" },
196 { "9", "Pacific Ocean" },
200 #define NCONTINENTS \
201 (int)((sizeof(continent_items)) / (sizeof(continent_items[0])))
202 static dialogMenuItem continents[NCONTINENTS];
204 #define OCEANP(x) ((x) == 4 || (x) == 7 || (x) == 8)
207 continent_country_menu(dialogMenuItem *continent)
209 char title[64], prompt[64];
210 struct continent *contp = continent->data;
211 int isocean = OCEANP(continent - continents);
214 if (strcmp(continent->title, "UTC") == 0)
215 return (set_zone_utc());
217 /* Short cut -- if there's only one country, don't post a menu. */
218 if (contp->nitems == 1)
219 return (contp->menu[0].fire(&contp->menu[0]));
221 /* It's amazing how much good grammar really matters... */
223 snprintf(title, sizeof(title), "Countries in %s",
225 snprintf(prompt, sizeof(prompt), "Select a country or region");
227 snprintf(title, sizeof(title), "Islands and groups in the %s",
229 snprintf(prompt, sizeof(prompt), "Select an island or group");
232 rv = xdialog_menu(title, prompt, contp->nitems, contp->menu);
233 return (rv == 0 ? DITEM_LEAVE_MENU : DITEM_RECREATE);
236 static struct continent *
237 find_continent(const char *name)
241 for (i = 0; i < NCONTINENTS; i++)
242 if (strcmp(name, continent_names[i].name) == 0)
243 return (continent_names[i].continent);
251 char *filename; /* use iff nzones < 0 */
252 struct continent *continent; /* use iff nzones < 0 */
253 TAILQ_HEAD(, zone) zones; /* use iff nzones > 0 */
254 dialogMenuItem *submenu; /* use iff nzones > 0 */
258 TAILQ_ENTRY(zone) link;
261 struct continent *continent;
265 * This is the easiest organization... we use ISO 3166 country codes,
266 * of the two-letter variety, so we just size this array to suit.
267 * Beats worrying about dynamic allocation.
269 #define NCOUNTRIES (26 * 26)
270 static struct country countries[NCOUNTRIES];
272 #define CODE2INT(s) ((s[0] - 'A') * 26 + (s[1] - 'A'))
275 * Read the ISO 3166 country code database in _PATH_ISO3166
276 * (/usr/share/misc/iso3166). On error, exit via err(3).
279 read_iso3166_table(void)
287 fp = fopen(path_iso3166, "r");
289 err(1, "%s", path_iso3166);
292 while ((s = fgetln(fp, &len)) != NULL) {
294 if (s[len - 1] != '\n')
295 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
297 if (s[0] == '#' || strspn(s, " \t") == len - 1)
300 /* Isolate the two-letter code. */
301 t = strsep(&s, "\t");
302 if (t == NULL || strlen(t) != 2)
303 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
304 if (t[0] < 'A' || t[0] > 'Z' || t[1] < 'A' || t[1] > 'Z')
305 errx(1, "%s:%d: invalid code `%s'", path_iso3166,
308 /* Now skip past the three-letter and numeric codes. */
309 name = strsep(&s, "\t"); /* 3-let */
310 if (name == NULL || strlen(name) != 3)
311 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
312 name = strsep(&s, "\t"); /* numeric */
313 if (name == NULL || strlen(name) != 3)
314 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
318 cp = &countries[CODE2INT(t)];
320 errx(1, "%s:%d: country code `%s' multiply defined: %s",
321 path_iso3166, lineno, t, cp->name);
322 cp->name = strdup(name);
323 if (cp->name == NULL)
324 errx(1, "malloc failed");
327 errx(1, "malloc failed");
334 add_zone_to_country(int lineno, const char *tlc, const char *descr,
335 const char *file, struct continent *cont)
340 if (tlc[0] < 'A' || tlc[0] > 'Z' || tlc[1] < 'A' || tlc[1] > 'Z')
341 errx(1, "%s:%d: country code `%s' invalid", path_zonetab,
344 cp = &countries[CODE2INT(tlc)];
346 errx(1, "%s:%d: country code `%s' unknown", path_zonetab,
351 errx(1, "%s:%d: conflicting zone definition",
352 path_zonetab, lineno);
354 zp = malloc(sizeof(*zp));
356 errx(1, "malloc(%zu)", sizeof(*zp));
359 TAILQ_INIT(&cp->zones);
361 zp->descr = strdup(descr);
362 if (zp->descr == NULL)
363 errx(1, "malloc failed");
364 zp->filename = strdup(file);
365 if (zp->filename == NULL)
366 errx(1, "malloc failed");
367 zp->continent = cont;
368 TAILQ_INSERT_TAIL(&cp->zones, zp, link);
372 errx(1, "%s:%d: zone must have description",
373 path_zonetab, lineno);
375 errx(1, "%s:%d: zone multiply defined",
376 path_zonetab, lineno);
378 cp->filename = strdup(file);
379 if (cp->filename == NULL)
380 errx(1, "malloc failed");
381 cp->continent = cont;
386 * This comparison function intentionally sorts all of the null-named
387 * ``countries''---i.e., the codes that don't correspond to a real
388 * country---to the end. Everything else is lexical by country name.
391 compare_countries(const void *xa, const void *xb)
393 const struct country *a = xa, *b = xb;
395 if (a->name == 0 && b->name == 0)
397 if (a->name == 0 && b->name != 0)
402 return (strcmp(a->name, b->name));
406 * This must be done AFTER all zone descriptions are read, since it breaks
413 qsort(countries, NCOUNTRIES, sizeof(countries[0]), compare_countries);
421 struct continent *cont;
423 char *line, *country_list, *tlc, *file, *descr, *p;
426 fp = fopen(path_zonetab, "r");
428 err(1, "%s", path_zonetab);
431 while ((line = fgetln(fp, &len)) != NULL) {
433 if (line[len - 1] != '\n')
434 errx(1, "%s:%d: invalid format", path_zonetab, lineno);
435 line[len - 1] = '\0';
439 country_list = strsep(&line, "\t");
440 /* coord = */ strsep(&line, "\t"); /* Unused */
441 file = strsep(&line, "\t");
442 /* get continent portion from continent/country */
443 p = strchr(file, '/');
445 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab,
447 contlen = p - file + 1; /* trailing nul */
448 if (contlen > sizeof(contbuf))
449 errx(1, "%s:%d: continent name in zone name `%s' too long",
450 path_zonetab, lineno, file);
451 strlcpy(contbuf, file, contlen);
452 cont = find_continent(contbuf);
454 errx(1, "%s:%d: invalid region `%s'", path_zonetab,
457 descr = (line != NULL && *line != '\0') ? line : NULL;
459 while (country_list != NULL) {
460 tlc = strsep(&country_list, ",");
461 if (strlen(tlc) != 2)
462 errx(1, "%s:%d: invalid country code `%s'",
463 path_zonetab, lineno, tlc);
464 add_zone_to_country(lineno, tlc, descr, file, cont);
474 struct zone *zp, *zp2;
475 struct continent *cont;
480 * First, count up all the countries in each continent/ocean.
481 * Be careful to count those countries which have multiple zones
482 * only once for each. NB: some countries are in multiple
485 for (cp = countries; cp->name; cp++) {
488 if (cp->nzones < 0) {
489 cp->continent->nitems++;
491 TAILQ_FOREACH(zp, &cp->zones, link) {
492 cont = zp->continent;
493 for (zp2 = TAILQ_FIRST(&cp->zones);
494 zp2->continent != cont;
495 zp2 = TAILQ_NEXT(zp2, link))
498 zp->continent->nitems++;
504 * Now allocate memory for the country menus and initialize
505 * continent menus. We set nitems back to zero so that we can
506 * use it for counting again when we actually build the menus.
508 memset(continents, 0, sizeof(continents));
509 for (i = 0; i < NCONTINENTS; i++) {
510 continent_names[i].continent->menu =
511 malloc(sizeof(dialogMenuItem) *
512 continent_names[i].continent->nitems);
513 if (continent_names[i].continent->menu == NULL)
514 errx(1, "malloc for continent menu");
515 continent_names[i].continent->nitems = 0;
516 continents[i].prompt = continent_items[i].prompt;
517 continents[i].title = continent_items[i].title;
518 continents[i].fire = continent_country_menu;
519 continents[i].data = continent_names[i].continent;
523 * Now that memory is allocated, create the menu items for
524 * each continent. For multiple-zone countries, also create
525 * the country's zone submenu.
527 for (cp = countries; cp->name; cp++) {
530 if (cp->nzones < 0) {
531 dmi = &cp->continent->menu[cp->continent->nitems];
532 memset(dmi, 0, sizeof(*dmi));
533 asprintf(&dmi->prompt, "%d", ++cp->continent->nitems);
534 dmi->title = cp->name;
535 dmi->fire = set_zone_whole_country;
538 cp->submenu = malloc(cp->nzones * sizeof(*dmi));
539 if (cp->submenu == 0)
540 errx(1, "malloc for submenu");
542 TAILQ_FOREACH(zp, &cp->zones, link) {
543 cont = zp->continent;
544 dmi = &cp->submenu[cp->nzones];
545 memset(dmi, 0, sizeof(*dmi));
546 asprintf(&dmi->prompt, "%d", ++cp->nzones);
547 dmi->title = zp->descr;
548 dmi->fire = set_zone_multi;
551 for (zp2 = TAILQ_FIRST(&cp->zones);
552 zp2->continent != cont;
553 zp2 = TAILQ_NEXT(zp2, link))
558 dmi = &cont->menu[cont->nitems];
559 memset(dmi, 0, sizeof(*dmi));
560 asprintf(&dmi->prompt, "%d", ++cont->nitems);
561 dmi->title = cp->name;
562 dmi->fire = set_zone_menu;
570 set_zone_menu(dialogMenuItem *dmi)
572 char title[64], prompt[64];
573 struct country *cp = dmi->data;
576 snprintf(title, sizeof(title), "%s Time Zones", cp->name);
577 snprintf(prompt, sizeof(prompt),
578 "Select a zone which observes the same time as your locality.");
579 rv = xdialog_menu(title, prompt, cp->nzones, cp->submenu);
580 return (rv != 0 ? DITEM_RECREATE : DITEM_LEAVE_MENU);
586 if (!confirm_zone("UTC"))
587 return (DITEM_FAILURE | DITEM_RECREATE);
589 return (install_zoneinfo("UTC"));
593 confirm_zone(const char *filename)
600 setenv("TZ", filename, 1);
604 snprintf(prompt, sizeof(prompt),
605 "Does the abbreviation `%s' look reasonable?", tm->tm_zone);
606 conf.title = "Confirmation";
607 rv = (bsddialog_yesno(&conf, prompt, 5, 72) == BSDDIALOG_YES);
612 set_zone_multi(dialogMenuItem *dmi)
614 struct zone *zp = dmi->data;
617 if (!confirm_zone(zp->filename))
618 return (DITEM_FAILURE | DITEM_RECREATE);
620 rv = install_zoneinfo(zp->filename);
625 set_zone_whole_country(dialogMenuItem *dmi)
627 struct country *cp = dmi->data;
630 if (!confirm_zone(cp->filename))
631 return (DITEM_FAILURE | DITEM_RECREATE);
633 rv = install_zoneinfo(cp->filename);
639 static void message_zoneinfo_file(const char *title, char *prompt)
641 #ifdef HAVE_BSDDIALOG
644 bsddialog_msgbox(&conf, prompt, 8, 72);
647 fprintf(stderr, "%s: %s\n", title, prompt);
651 install_zoneinfo_file(const char *zoneinfo_file)
654 char prompt[SILLY_BUFFER_SIZE];
657 int fd1, fd2, copymode;
659 if (lstat(path_localtime, &sb) < 0) {
660 /* Nothing there yet... */
662 } else if (S_ISLNK(sb.st_mode))
669 snprintf(prompt, sizeof(prompt),
670 "Copying %s to %s", zoneinfo_file, path_localtime);
672 snprintf(prompt, sizeof(prompt),
673 "Creating symbolic link %s to %s",
674 path_localtime, zoneinfo_file);
675 message_zoneinfo_file("Info", prompt);
680 fd1 = open(zoneinfo_file, O_RDONLY, 0);
682 snprintf(prompt, sizeof(prompt),
683 "Could not open %s: %s", zoneinfo_file,
685 message_zoneinfo_file("Error", prompt);
686 return (DITEM_FAILURE | DITEM_RECREATE);
689 if (unlink(path_localtime) < 0 && errno != ENOENT) {
690 snprintf(prompt, sizeof(prompt),
691 "Could not delete %s: %s",
692 path_localtime, strerror(errno));
693 message_zoneinfo_file("Error", prompt);
694 return (DITEM_FAILURE | DITEM_RECREATE);
697 fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
698 S_IRUSR | S_IRGRP | S_IROTH);
700 snprintf(prompt, sizeof(prompt),
701 "Could not open %s: %s",
702 path_localtime, strerror(errno));
703 message_zoneinfo_file("Error", prompt);
704 return (DITEM_FAILURE | DITEM_RECREATE);
707 while ((len = read(fd1, buf, sizeof(buf))) > 0)
708 if ((len = write(fd2, buf, len)) < 0)
712 snprintf(prompt, sizeof(prompt),
713 "Error copying %s to %s %s", zoneinfo_file,
714 path_localtime, strerror(errno));
715 message_zoneinfo_file("Error", prompt);
716 /* Better to leave none than a corrupt one. */
717 unlink(path_localtime);
718 return (DITEM_FAILURE | DITEM_RECREATE);
723 if (access(zoneinfo_file, R_OK) != 0) {
724 snprintf(prompt, sizeof(prompt),
725 "Cannot access %s: %s", zoneinfo_file,
727 message_zoneinfo_file("Error", prompt);
728 return (DITEM_FAILURE | DITEM_RECREATE);
730 if (unlink(path_localtime) < 0 && errno != ENOENT) {
731 snprintf(prompt, sizeof(prompt),
732 "Could not delete %s: %s",
733 path_localtime, strerror(errno));
734 message_zoneinfo_file("Error", prompt);
735 return (DITEM_FAILURE | DITEM_RECREATE);
737 if (symlink(zoneinfo_file, path_localtime) < 0) {
738 snprintf(prompt, sizeof(prompt),
739 "Cannot create symbolic link %s to %s: %s",
740 path_localtime, zoneinfo_file,
742 message_zoneinfo_file("Error", prompt);
743 return (DITEM_FAILURE | DITEM_RECREATE);
749 snprintf(prompt, sizeof(prompt),
750 "Copied timezone file from %s to %s",
751 zoneinfo_file, path_localtime);
753 snprintf(prompt, sizeof(prompt),
754 "Created symbolic link from %s to %s",
755 zoneinfo_file, path_localtime);
756 message_zoneinfo_file("Done", prompt);
760 return (DITEM_LEAVE_MENU);
764 install_zoneinfo(const char *zoneinfo)
768 char path_zoneinfo_file[MAXPATHLEN];
770 if ((size_t)snprintf(path_zoneinfo_file, sizeof(path_zoneinfo_file),
771 "%s/%s", path_zoneinfo, zoneinfo) >= sizeof(path_zoneinfo_file))
772 errx(1, "%s/%s name too long", path_zoneinfo, zoneinfo);
773 rv = install_zoneinfo_file(path_zoneinfo_file);
775 /* Save knowledge for later */
776 if (reallydoit && (rv & DITEM_FAILURE) == 0) {
777 if ((f = fopen(path_db, "w")) != NULL) {
778 fprintf(f, "%s\n", zoneinfo);
790 fprintf(stderr, "usage: tzsetup [-nrs] [-C chroot_directory]"
791 " [zoneinfo_file | zoneinfo_name]\n");
796 main(int argc, char **argv)
798 #ifdef HAVE_BSDDIALOG
803 char vm_guest[16] = "";
804 size_t len = sizeof(vm_guest);
808 #ifdef HAVE_BSDDIALOG
809 setlocale(LC_ALL, "");
812 /* Default skiputc to 1 for VM guests */
813 if (sysctlbyname("kern.vm_guest", vm_guest, &len, NULL, 0) == 0 &&
814 strcmp(vm_guest, "none") != 0)
817 while ((c = getopt(argc, argv, "C:nrs")) != -1) {
827 #ifdef HAVE_BSDDIALOG
839 if (argc - optind > 1)
842 if (chrootenv == NULL) {
843 strcpy(path_zonetab, _PATH_ZONETAB);
844 strcpy(path_iso3166, _PATH_ISO3166);
845 strcpy(path_zoneinfo, _PATH_ZONEINFO);
846 strcpy(path_localtime, _PATH_LOCALTIME);
847 strcpy(path_db, _PATH_DB);
848 strcpy(path_wall_cmos_clock, _PATH_WALL_CMOS_CLOCK);
850 sprintf(path_zonetab, "%s/%s", chrootenv, _PATH_ZONETAB);
851 sprintf(path_iso3166, "%s/%s", chrootenv, _PATH_ISO3166);
852 sprintf(path_zoneinfo, "%s/%s", chrootenv, _PATH_ZONEINFO);
853 sprintf(path_localtime, "%s/%s", chrootenv, _PATH_LOCALTIME);
854 sprintf(path_db, "%s/%s", chrootenv, _PATH_DB);
855 sprintf(path_wall_cmos_clock, "%s/%s", chrootenv,
856 _PATH_WALL_CMOS_CLOCK);
859 /* Override the user-supplied umask. */
860 (void)umask(S_IWGRP | S_IWOTH);
862 if (reinstall == 1) {
864 char zoneinfo[MAXPATHLEN];
866 if ((f = fopen(path_db, "r")) != NULL) {
867 if (fgets(zoneinfo, sizeof(zoneinfo), f) != NULL) {
868 zoneinfo[sizeof(zoneinfo) - 1] = 0;
869 if (strlen(zoneinfo) > 0) {
870 zoneinfo[strlen(zoneinfo) - 1] = 0;
871 rv = install_zoneinfo(zoneinfo);
872 exit(rv & ~DITEM_LEAVE_MENU);
874 errx(1, "Error reading %s.\n", path_db);
878 "Unable to determine earlier installed zoneinfo "
879 "name. Check %s", path_db);
881 errx(1, "Cannot open %s for reading. Does it exist?", path_db);
885 * If the arguments on the command-line do not specify a file,
886 * then interpret it as a zoneinfo name
888 if (optind == argc - 1) {
891 if (stat(argv[optind], &sb) != 0) {
892 #ifdef HAVE_BSDDIALOG
895 rv = install_zoneinfo(argv[optind]);
896 exit(rv & ~DITEM_LEAVE_MENU);
900 #ifdef HAVE_BSDDIALOG
902 read_iso3166_table();
907 bsddialog_initconf(&conf);
909 conf.auto_minwidth = 24;
910 conf.key.enable_esc = true;
912 if (bsddialog_init() == BSDDIALOG_ERROR)
913 errx(1, "Error bsddialog: %s\n", bsddialog_geterror());
916 snprintf(prompt, sizeof(prompt),
917 "Is this machine's CMOS clock set to UTC? "
918 "If it is set to local time,\n"
919 "or you don't know, please choose NO here!");
921 conf.title = "Select local or UTC (Greenwich Mean Time) clock";
922 if (bsddialog_yesno(&conf, prompt, 7, 73) == BSDDIALOG_YES) {
924 unlink(path_wall_cmos_clock);
927 fd = open(path_wall_cmos_clock,
928 O_WRONLY | O_CREAT | O_TRUNC,
929 S_IRUSR | S_IRGRP | S_IROTH);
933 path_wall_cmos_clock);
939 if (optind == argc - 1) {
940 snprintf(prompt, sizeof(prompt),
941 "\nUse the default `%s' zone?", argv[optind]);
942 conf.title = "Default timezone provided";
943 if (bsddialog_yesno(&conf, prompt, 7, 72) == BSDDIALOG_YES) {
944 rv = install_zoneinfo_file(argv[optind]);
946 exit(rv & ~DITEM_LEAVE_MENU);
949 xdialog_menu("Time Zone Selector", "Select a region", NCONTINENTS,