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>
56 #define _PATH_ZONETAB "/usr/share/zoneinfo/zone.tab"
57 #define _PATH_ISO3166 "/usr/share/misc/iso3166"
58 #define _PATH_ZONEINFO "/usr/share/zoneinfo"
59 #define _PATH_LOCALTIME "/etc/localtime"
60 #define _PATH_DB "/var/db/zoneinfo"
61 #define _PATH_WALL_CMOS_CLOCK "/etc/wall_cmos_clock"
64 #define SILLY_BUFFER_SIZE 2*PATH_MAX
66 #warning "Somebody needs to fix this to dynamically size this buffer."
67 #define SILLY_BUFFER_SIZE 2048
70 /* special return codes for `fire' actions */
71 #define DITEM_FAILURE 1
73 /* flags - returned in upper 16 bits of return status */
74 #define DITEM_LEAVE_MENU (1 << 16)
75 #define DITEM_RECREATE (1 << 18)
77 static char path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
78 path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN],
79 path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
81 static int reallydoit = 1;
82 static int reinstall = 0;
83 static char *chrootenv = NULL;
85 static void usage(void);
86 static int install_zoneinfo(const char *zoneinfo);
87 static int install_zoneinfo_file(const char *zoneinfo_file);
90 /* for use in describing more exotic behaviors */
91 typedef struct dialogMenuItem {
94 int (*fire)(struct dialogMenuItem *self);
99 xdialog_count_rows(const char *p)
103 while ((p = strchr(p, '\n')) != NULL) {
110 return (rows ? rows : 1);
114 xdialog_count_columns(const char *p)
120 for (; (q = strchr(p, '\n')) != NULL; p = q + 1) {
122 max_len = MAX(max_len, len);
126 max_len = MAX(max_len, len);
131 xdialog_menu(const char *title, const char *cprompt, int height, int width,
132 int menu_height, int item_no, dialogMenuItem *ditems)
134 int i, result, choice = 0;
135 DIALOG_LISTITEM *listitems;
136 DIALOG_VARS save_vars;
138 dlg_save_vars(&save_vars);
140 /* initialize list items */
141 listitems = dlg_calloc(DIALOG_LISTITEM, item_no + 1);
142 assert_ptr(listitems, "xdialog_menu");
143 for (i = 0; i < item_no; i++) {
144 listitems[i].name = ditems[i].prompt;
145 listitems[i].text = ditems[i].title;
148 /* calculate height */
150 height = xdialog_count_rows(cprompt) + menu_height + 4 + 2;
154 /* calculate width */
158 for (i = 0; i < item_no; i++) {
161 l = strlen(listitems[i].name);
162 for (j = 0; j < item_no; j++) {
163 int k = strlen(listitems[j].text);
164 tag_x = MAX(tag_x, l + k + 2);
167 width = MAX(xdialog_count_columns(cprompt), title != NULL ?
168 xdialog_count_columns(title) : 0);
169 width = MAX(width, tag_x + 4) + 4;
171 width = MAX(width, 24);
176 dialog_vars.default_item = listitems[choice].name;
177 result = dlg_menu(title, cprompt, height, width,
178 menu_height, item_no, listitems, &choice, NULL);
184 if (ditems[choice].fire != NULL) {
187 status = ditems[choice].fire(ditems + choice);
188 if (status & DITEM_RECREATE) {
195 case DLG_EXIT_CANCEL:
202 dlg_restore_vars(&save_vars);
206 static int usedialog = 1;
208 static int confirm_zone(const char *filename);
209 static int continent_country_menu(dialogMenuItem *);
210 static int set_zone_multi(dialogMenuItem *);
211 static int set_zone_whole_country(dialogMenuItem *);
212 static int set_zone_menu(dialogMenuItem *);
213 static int set_zone_utc(void);
216 dialogMenuItem *menu;
220 static struct continent africa, america, antarctica, arctic, asia, atlantic;
221 static struct continent australia, europe, indian, pacific, utc;
223 static struct continent_names {
225 struct continent *continent;
226 } continent_names[] = {
227 { "Africa", &africa },
228 { "America", &america },
229 { "Antarctica", &antarctica },
230 { "Arctic", &arctic },
232 { "Atlantic", &atlantic },
233 { "Australia", &australia },
234 { "Europe", &europe },
235 { "Indian", &indian },
236 { "Pacific", &pacific },
240 static struct continent_items {
243 } continent_items[] = {
245 { "2", "America -- North and South" },
246 { "3", "Antarctica" },
247 { "4", "Arctic Ocean" },
249 { "6", "Atlantic Ocean" },
250 { "7", "Australia" },
252 { "9", "Indian Ocean" },
253 { "0", "Pacific Ocean" },
257 #define NCONTINENTS \
258 (int)((sizeof(continent_items)) / (sizeof(continent_items[0])))
259 static dialogMenuItem continents[NCONTINENTS];
261 #define OCEANP(x) ((x) == 3 || (x) == 5 || (x) == 8 || (x) == 9)
264 continent_country_menu(dialogMenuItem *continent)
266 char title[64], prompt[64];
267 struct continent *contp = continent->data;
268 int isocean = OCEANP(continent - continents);
272 if (strcmp(continent->title, "UTC") == 0)
273 return (set_zone_utc());
275 /* Short cut -- if there's only one country, don't post a menu. */
276 if (contp->nitems == 1)
277 return (contp->menu[0].fire(&contp->menu[0]));
279 /* It's amazing how much good grammar really matters... */
281 snprintf(title, sizeof(title), "Countries in %s",
283 snprintf(prompt, sizeof(prompt), "Select a country or region");
285 snprintf(title, sizeof(title), "Islands and groups in the %s",
287 snprintf(prompt, sizeof(prompt), "Select an island or group");
290 menulen = contp->nitems < 16 ? contp->nitems : 16;
291 rv = xdialog_menu(title, prompt, -1, -1, menulen, contp->nitems,
294 return (DITEM_LEAVE_MENU);
295 return (DITEM_RECREATE);
298 static struct continent *
299 find_continent(const char *name)
303 for (i = 0; i < NCONTINENTS; i++)
304 if (strcmp(name, continent_names[i].name) == 0)
305 return (continent_names[i].continent);
313 char *filename; /* use iff nzones < 0 */
314 struct continent *continent; /* use iff nzones < 0 */
315 TAILQ_HEAD(, zone) zones; /* use iff nzones > 0 */
316 dialogMenuItem *submenu; /* use iff nzones > 0 */
320 TAILQ_ENTRY(zone) link;
323 struct continent *continent;
327 * This is the easiest organization... we use ISO 3166 country codes,
328 * of the two-letter variety, so we just size this array to suit.
329 * Beats worrying about dynamic allocation.
331 #define NCOUNTRIES (26 * 26)
332 static struct country countries[NCOUNTRIES];
334 #define CODE2INT(s) ((s[0] - 'A') * 26 + (s[1] - 'A'))
337 * Read the ISO 3166 country code database in _PATH_ISO3166
338 * (/usr/share/misc/iso3166). On error, exit via err(3).
341 read_iso3166_table(void)
349 fp = fopen(path_iso3166, "r");
351 err(1, "%s", path_iso3166);
354 while ((s = fgetln(fp, &len)) != NULL) {
356 if (s[len - 1] != '\n')
357 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
359 if (s[0] == '#' || strspn(s, " \t") == len - 1)
362 /* Isolate the two-letter code. */
363 t = strsep(&s, "\t");
364 if (t == NULL || strlen(t) != 2)
365 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
366 if (t[0] < 'A' || t[0] > 'Z' || t[1] < 'A' || t[1] > 'Z')
367 errx(1, "%s:%d: invalid code `%s'", path_iso3166,
370 /* Now skip past the three-letter and numeric codes. */
371 name = strsep(&s, "\t"); /* 3-let */
372 if (name == NULL || strlen(name) != 3)
373 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
374 name = strsep(&s, "\t"); /* numeric */
375 if (name == NULL || strlen(name) != 3)
376 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
380 cp = &countries[CODE2INT(t)];
382 errx(1, "%s:%d: country code `%s' multiply defined: %s",
383 path_iso3166, lineno, t, cp->name);
384 cp->name = strdup(name);
385 if (cp->name == NULL)
386 errx(1, "malloc failed");
389 errx(1, "malloc failed");
396 add_zone_to_country(int lineno, const char *tlc, const char *descr,
397 const char *file, struct continent *cont)
402 if (tlc[0] < 'A' || tlc[0] > 'Z' || tlc[1] < 'A' || tlc[1] > 'Z')
403 errx(1, "%s:%d: country code `%s' invalid", path_zonetab,
406 cp = &countries[CODE2INT(tlc)];
408 errx(1, "%s:%d: country code `%s' unknown", path_zonetab,
413 errx(1, "%s:%d: conflicting zone definition",
414 path_zonetab, lineno);
416 zp = malloc(sizeof(*zp));
418 errx(1, "malloc(%zu)", sizeof(*zp));
421 TAILQ_INIT(&cp->zones);
423 zp->descr = strdup(descr);
424 if (zp->descr == NULL)
425 errx(1, "malloc failed");
426 zp->filename = strdup(file);
427 if (zp->filename == NULL)
428 errx(1, "malloc failed");
429 zp->continent = cont;
430 TAILQ_INSERT_TAIL(&cp->zones, zp, link);
434 errx(1, "%s:%d: zone must have description",
435 path_zonetab, lineno);
437 errx(1, "%s:%d: zone multiply defined",
438 path_zonetab, lineno);
440 cp->filename = strdup(file);
441 if (cp->filename == NULL)
442 errx(1, "malloc failed");
443 cp->continent = cont;
448 * This comparison function intentionally sorts all of the null-named
449 * ``countries''---i.e., the codes that don't correspond to a real
450 * country---to the end. Everything else is lexical by country name.
453 compare_countries(const void *xa, const void *xb)
455 const struct country *a = xa, *b = xb;
457 if (a->name == 0 && b->name == 0)
459 if (a->name == 0 && b->name != 0)
464 return (strcmp(a->name, b->name));
468 * This must be done AFTER all zone descriptions are read, since it breaks
475 qsort(countries, NCOUNTRIES, sizeof(countries[0]), compare_countries);
483 struct continent *cont;
485 char *line, *tlc, *file, *descr, *p;
488 fp = fopen(path_zonetab, "r");
490 err(1, "%s", path_zonetab);
493 while ((line = fgetln(fp, &len)) != NULL) {
495 if (line[len - 1] != '\n')
496 errx(1, "%s:%d: invalid format", path_zonetab, lineno);
497 line[len - 1] = '\0';
501 tlc = strsep(&line, "\t");
502 if (strlen(tlc) != 2)
503 errx(1, "%s:%d: invalid country code `%s'",
504 path_zonetab, lineno, tlc);
505 /* coord = */ strsep(&line, "\t"); /* Unused */
506 file = strsep(&line, "\t");
507 p = strchr(file, '/');
509 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab,
512 strncat(contbuf, file, p - file);
513 cont = find_continent(contbuf);
515 errx(1, "%s:%d: invalid region `%s'", path_zonetab,
518 descr = (line != NULL && *line != '\0') ? line : NULL;
520 add_zone_to_country(lineno, tlc, descr, file, cont);
529 struct zone *zp, *zp2;
530 struct continent *cont;
535 * First, count up all the countries in each continent/ocean.
536 * Be careful to count those countries which have multiple zones
537 * only once for each. NB: some countries are in multiple
540 for (cp = countries; cp->name; cp++) {
543 if (cp->nzones < 0) {
544 cp->continent->nitems++;
546 TAILQ_FOREACH(zp, &cp->zones, link) {
547 cont = zp->continent;
548 for (zp2 = TAILQ_FIRST(&cp->zones);
549 zp2->continent != cont;
550 zp2 = TAILQ_NEXT(zp2, link))
553 zp->continent->nitems++;
559 * Now allocate memory for the country menus and initialize
560 * continent menus. We set nitems back to zero so that we can
561 * use it for counting again when we actually build the menus.
563 memset(continents, 0, sizeof(continents));
564 for (i = 0; i < NCONTINENTS; i++) {
565 continent_names[i].continent->menu =
566 malloc(sizeof(dialogMenuItem) *
567 continent_names[i].continent->nitems);
568 if (continent_names[i].continent->menu == NULL)
569 errx(1, "malloc for continent menu");
570 continent_names[i].continent->nitems = 0;
571 continents[i].prompt = continent_items[i].prompt;
572 continents[i].title = continent_items[i].title;
573 continents[i].fire = continent_country_menu;
574 continents[i].data = continent_names[i].continent;
578 * Now that memory is allocated, create the menu items for
579 * each continent. For multiple-zone countries, also create
580 * the country's zone submenu.
582 for (cp = countries; cp->name; cp++) {
585 if (cp->nzones < 0) {
586 dmi = &cp->continent->menu[cp->continent->nitems];
587 memset(dmi, 0, sizeof(*dmi));
588 asprintf(&dmi->prompt, "%d", ++cp->continent->nitems);
589 dmi->title = cp->name;
590 dmi->fire = set_zone_whole_country;
593 cp->submenu = malloc(cp->nzones * sizeof(*dmi));
594 if (cp->submenu == 0)
595 errx(1, "malloc for submenu");
597 TAILQ_FOREACH(zp, &cp->zones, link) {
598 cont = zp->continent;
599 dmi = &cp->submenu[cp->nzones];
600 memset(dmi, 0, sizeof(*dmi));
601 asprintf(&dmi->prompt, "%d", ++cp->nzones);
602 dmi->title = zp->descr;
603 dmi->fire = set_zone_multi;
606 for (zp2 = TAILQ_FIRST(&cp->zones);
607 zp2->continent != cont;
608 zp2 = TAILQ_NEXT(zp2, link))
613 dmi = &cont->menu[cont->nitems];
614 memset(dmi, 0, sizeof(*dmi));
615 asprintf(&dmi->prompt, "%d", ++cont->nitems);
616 dmi->title = cp->name;
617 dmi->fire = set_zone_menu;
625 set_zone_menu(dialogMenuItem *dmi)
627 char title[64], prompt[64];
628 struct country *cp = dmi->data;
632 snprintf(title, sizeof(title), "%s Time Zones", cp->name);
633 snprintf(prompt, sizeof(prompt),
634 "Select a zone which observes the same time as your locality.");
635 menulen = cp->nzones < 16 ? cp->nzones : 16;
636 rv = xdialog_menu(title, prompt, -1, -1, menulen, cp->nzones,
639 return (DITEM_RECREATE);
640 return (DITEM_LEAVE_MENU);
646 if (!confirm_zone("UTC"))
647 return (DITEM_FAILURE | DITEM_RECREATE);
649 return (install_zoneinfo("UTC"));
653 confirm_zone(const char *filename)
655 char title[64], prompt[64];
660 setenv("TZ", filename, 1);
664 snprintf(title, sizeof(title), "Confirmation");
665 snprintf(prompt, sizeof(prompt),
666 "Does the abbreviation `%s' look reasonable?", tm->tm_zone);
667 rv = !dialog_yesno(title, prompt, 5, 72);
672 set_zone_multi(dialogMenuItem *dmi)
674 struct zone *zp = dmi->data;
677 if (!confirm_zone(zp->filename))
678 return (DITEM_FAILURE | DITEM_RECREATE);
680 rv = install_zoneinfo(zp->filename);
685 set_zone_whole_country(dialogMenuItem *dmi)
687 struct country *cp = dmi->data;
690 if (!confirm_zone(cp->filename))
691 return (DITEM_FAILURE | DITEM_RECREATE);
693 rv = install_zoneinfo(cp->filename);
700 install_zoneinfo_file(const char *zoneinfo_file)
703 char title[64], prompt[SILLY_BUFFER_SIZE];
706 int fd1, fd2, copymode;
708 if (lstat(path_localtime, &sb) < 0) {
709 /* Nothing there yet... */
711 } else if (S_ISLNK(sb.st_mode))
717 snprintf(title, sizeof(title), "Info");
719 snprintf(prompt, sizeof(prompt),
720 "Copying %s to %s", zoneinfo_file, path_localtime);
722 snprintf(prompt, sizeof(prompt),
723 "Creating symbolic link %s to %s",
724 path_localtime, zoneinfo_file);
727 dialog_msgbox(title, prompt, 8, 72, 1);
730 fprintf(stderr, "%s\n", prompt);
735 fd1 = open(zoneinfo_file, O_RDONLY, 0);
737 snprintf(title, sizeof(title), "Error");
738 snprintf(prompt, sizeof(prompt),
739 "Could not open %s: %s", zoneinfo_file,
743 dialog_msgbox(title, prompt, 8, 72, 1);
746 fprintf(stderr, "%s\n", prompt);
747 return (DITEM_FAILURE | DITEM_RECREATE);
750 if (unlink(path_localtime) < 0 && errno != ENOENT) {
751 snprintf(prompt, sizeof(prompt),
752 "Could not delete %s: %s",
753 path_localtime, strerror(errno));
756 snprintf(title, sizeof(title), "Error");
757 dialog_msgbox(title, prompt, 8, 72, 1);
760 fprintf(stderr, "%s\n", prompt);
761 return (DITEM_FAILURE | DITEM_RECREATE);
764 fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
765 S_IRUSR | S_IRGRP | S_IROTH);
767 snprintf(title, sizeof(title), "Error");
768 snprintf(prompt, sizeof(prompt),
769 "Could not open %s: %s",
770 path_localtime, strerror(errno));
773 dialog_msgbox(title, prompt, 8, 72, 1);
776 fprintf(stderr, "%s\n", prompt);
777 return (DITEM_FAILURE | DITEM_RECREATE);
780 while ((len = read(fd1, buf, sizeof(buf))) > 0)
781 if ((len = write(fd2, buf, len)) < 0)
785 snprintf(title, sizeof(title), "Error");
786 snprintf(prompt, sizeof(prompt),
787 "Error copying %s to %s %s", zoneinfo_file,
788 path_localtime, strerror(errno));
791 dialog_msgbox(title, prompt, 8, 72, 1);
794 fprintf(stderr, "%s\n", prompt);
795 /* Better to leave none than a corrupt one. */
796 unlink(path_localtime);
797 return (DITEM_FAILURE | DITEM_RECREATE);
802 if (access(zoneinfo_file, R_OK) != 0) {
803 snprintf(title, sizeof(title), "Error");
804 snprintf(prompt, sizeof(prompt),
805 "Cannot access %s: %s", zoneinfo_file,
809 dialog_msgbox(title, prompt, 8, 72, 1);
812 fprintf(stderr, "%s\n", prompt);
813 return (DITEM_FAILURE | DITEM_RECREATE);
815 if (unlink(path_localtime) < 0 && errno != ENOENT) {
816 snprintf(prompt, sizeof(prompt),
817 "Could not delete %s: %s",
818 path_localtime, strerror(errno));
821 snprintf(title, sizeof(title), "Error");
822 dialog_msgbox(title, prompt, 8, 72, 1);
825 fprintf(stderr, "%s\n", prompt);
826 return (DITEM_FAILURE | DITEM_RECREATE);
828 if (symlink(zoneinfo_file, path_localtime) < 0) {
829 snprintf(title, sizeof(title), "Error");
830 snprintf(prompt, sizeof(prompt),
831 "Cannot create symbolic link %s to %s: %s",
832 path_localtime, zoneinfo_file,
836 dialog_msgbox(title, prompt, 8, 72, 1);
839 fprintf(stderr, "%s\n", prompt);
840 return (DITEM_FAILURE | DITEM_RECREATE);
845 snprintf(title, sizeof(title), "Done");
847 snprintf(prompt, sizeof(prompt),
848 "Copied timezone file from %s to %s",
849 zoneinfo_file, path_localtime);
851 snprintf(prompt, sizeof(prompt),
852 "Created symbolic link from %s to %s",
853 zoneinfo_file, path_localtime);
856 dialog_msgbox(title, prompt, 8, 72, 1);
859 fprintf(stderr, "%s\n", prompt);
863 return (DITEM_LEAVE_MENU);
867 install_zoneinfo(const char *zoneinfo)
871 char path_zoneinfo_file[MAXPATHLEN];
873 if ((size_t)snprintf(path_zoneinfo_file, sizeof(path_zoneinfo_file),
874 "%s/%s", path_zoneinfo, zoneinfo) >= sizeof(path_zoneinfo_file))
875 errx(1, "%s/%s name too long", path_zoneinfo, zoneinfo);
876 rv = install_zoneinfo_file(path_zoneinfo_file);
878 /* Save knowledge for later */
879 if (reallydoit && (rv & DITEM_FAILURE) == 0) {
880 if ((f = fopen(path_db, "w")) != NULL) {
881 fprintf(f, "%s\n", zoneinfo);
893 fprintf(stderr, "usage: tzsetup [-nrs] [-C chroot_directory]"
894 " [zoneinfo_file | zoneinfo_name]\n");
899 main(int argc, char **argv)
902 char title[64], prompt[128];
906 char vm_guest[16] = "";
907 size_t len = sizeof(vm_guest);
911 /* Default skiputc to 1 for VM guests */
912 if (sysctlbyname("kern.vm_guest", vm_guest, &len, NULL, 0) == 0 &&
913 strcmp(vm_guest, "none") != 0)
916 while ((c = getopt(argc, argv, "C:nrs")) != -1) {
938 if (argc - optind > 1)
941 if (chrootenv == NULL) {
942 strcpy(path_zonetab, _PATH_ZONETAB);
943 strcpy(path_iso3166, _PATH_ISO3166);
944 strcpy(path_zoneinfo, _PATH_ZONEINFO);
945 strcpy(path_localtime, _PATH_LOCALTIME);
946 strcpy(path_db, _PATH_DB);
947 strcpy(path_wall_cmos_clock, _PATH_WALL_CMOS_CLOCK);
949 sprintf(path_zonetab, "%s/%s", chrootenv, _PATH_ZONETAB);
950 sprintf(path_iso3166, "%s/%s", chrootenv, _PATH_ISO3166);
951 sprintf(path_zoneinfo, "%s/%s", chrootenv, _PATH_ZONEINFO);
952 sprintf(path_localtime, "%s/%s", chrootenv, _PATH_LOCALTIME);
953 sprintf(path_db, "%s/%s", chrootenv, _PATH_DB);
954 sprintf(path_wall_cmos_clock, "%s/%s", chrootenv,
955 _PATH_WALL_CMOS_CLOCK);
958 /* Override the user-supplied umask. */
959 (void)umask(S_IWGRP | S_IWOTH);
961 if (reinstall == 1) {
963 char zoneinfo[MAXPATHLEN];
965 if ((f = fopen(path_db, "r")) != NULL) {
966 if (fgets(zoneinfo, sizeof(zoneinfo), f) != NULL) {
967 zoneinfo[sizeof(zoneinfo) - 1] = 0;
968 if (strlen(zoneinfo) > 0) {
969 zoneinfo[strlen(zoneinfo) - 1] = 0;
970 rv = install_zoneinfo(zoneinfo);
971 exit(rv & ~DITEM_LEAVE_MENU);
973 errx(1, "Error reading %s.\n", path_db);
977 "Unable to determine earlier installed zoneinfo "
978 "name. Check %s", path_db);
980 errx(1, "Cannot open %s for reading. Does it exist?", path_db);
984 * If the arguments on the command-line do not specify a file,
985 * then interpret it as a zoneinfo name
987 if (optind == argc - 1) {
990 if (stat(argv[optind], &sb) != 0) {
994 rv = install_zoneinfo(argv[optind]);
995 exit(rv & ~DITEM_LEAVE_MENU);
1001 read_iso3166_table();
1006 init_dialog(stdin, stdout);
1008 DIALOG_VARS save_vars;
1011 snprintf(title, sizeof(title),
1012 "Select local or UTC (Greenwich Mean Time) clock");
1013 snprintf(prompt, sizeof(prompt),
1014 "Is this machine's CMOS clock set to UTC? "
1015 "If it is set to local time,\n"
1016 "or you don't know, please choose NO here!");
1017 dlg_save_vars(&save_vars);
1018 #if !defined(__sparc64__)
1019 dialog_vars.defaultno = TRUE;
1021 yesno = dialog_yesno(title, prompt, 7, 73);
1022 dlg_restore_vars(&save_vars);
1025 unlink(path_wall_cmos_clock);
1028 fd = open(path_wall_cmos_clock,
1029 O_WRONLY | O_CREAT | O_TRUNC,
1030 S_IRUSR | S_IRGRP | S_IROTH);
1034 path_wall_cmos_clock);
1041 if (optind == argc - 1) {
1042 snprintf(title, sizeof(title), "Default timezone provided");
1043 snprintf(prompt, sizeof(prompt),
1044 "\nUse the default `%s' zone?", argv[optind]);
1045 if (!dialog_yesno(title, prompt, 7, 72)) {
1046 rv = install_zoneinfo_file(argv[optind]);
1049 exit(rv & ~DITEM_LEAVE_MENU);
1053 snprintf(title, sizeof(title), "Time Zone Selector");
1054 snprintf(prompt, sizeof(prompt), "Select a region");
1055 xdialog_menu(title, prompt, -1, -1, NCONTINENTS, NCONTINENTS,