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>
53 #define _PATH_ZONETAB "/usr/share/zoneinfo/zone.tab"
54 #define _PATH_ISO3166 "/usr/share/misc/iso3166"
55 #define _PATH_ZONEINFO "/usr/share/zoneinfo"
56 #define _PATH_LOCALTIME "/etc/localtime"
57 #define _PATH_DB "/var/db/zoneinfo"
58 #define _PATH_WALL_CMOS_CLOCK "/etc/wall_cmos_clock"
61 #define SILLY_BUFFER_SIZE 2*PATH_MAX
63 #warning "Somebody needs to fix this to dynamically size this buffer."
64 #define SILLY_BUFFER_SIZE 2048
67 /* special return codes for `fire' actions */
68 #define DITEM_FAILURE 1
70 /* flags - returned in upper 16 bits of return status */
71 #define DITEM_LEAVE_MENU (1 << 16)
72 #define DITEM_RECREATE (1 << 18)
74 /* for use in describing more exotic behaviors */
75 typedef struct dialogMenuItem {
78 int (*fire)(struct dialogMenuItem *self);
83 xdialog_count_rows(const char *p)
87 while ((p = strchr(p, '\n')) != NULL) {
94 return rows ? rows : 1;
98 xdialog_count_columns(const char *p)
104 for (; (q = strchr(p, '\n')) != NULL; p = q + 1) {
106 max_len = MAX(max_len, len);
110 max_len = MAX(max_len, len);
115 xdialog_menu(const char *title, const char *cprompt, int height, int width,
116 int menu_height, int item_no, dialogMenuItem *ditems)
118 int i, result, choice = 0;
119 DIALOG_LISTITEM *listitems;
120 DIALOG_VARS save_vars;
122 dlg_save_vars(&save_vars);
124 /* initialize list items */
125 listitems = dlg_calloc(DIALOG_LISTITEM, item_no + 1);
126 assert_ptr(listitems, "xdialog_menu");
127 for (i = 0; i < item_no; i++) {
128 listitems[i].name = ditems[i].prompt;
129 listitems[i].text = ditems[i].title;
132 /* calculate height */
134 height = xdialog_count_rows(cprompt) + menu_height + 4 + 2;
138 /* calculate width */
142 for (i = 0; i < item_no; i++) {
145 l = strlen(listitems[i].name);
146 for (j = 0; j < item_no; j++) {
147 int k = strlen(listitems[j].text);
148 tag_x = MAX(tag_x, l + k + 2);
151 width = MAX(xdialog_count_columns(cprompt), title != NULL ? xdialog_count_columns(title) : 0);
152 width = MAX(width, tag_x + 4) + 4;
154 width = MAX(width, 24);
159 dialog_vars.default_item = listitems[choice].name;
160 result = dlg_menu(title, cprompt, height, width,
161 menu_height, item_no, listitems, &choice, NULL);
167 if (ditems[choice].fire != NULL) {
170 status = ditems[choice].fire(ditems + choice);
171 if (status & DITEM_RECREATE) {
178 case DLG_EXIT_CANCEL:
185 dlg_restore_vars(&save_vars);
189 static char path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
190 path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN],
191 path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
193 static int reallydoit = 1;
194 static int reinstall = 0;
195 static int usedialog = 1;
196 static char *chrootenv = NULL;
198 static void usage(void);
199 static int confirm_zone(const char *filename);
200 static int continent_country_menu(dialogMenuItem *);
201 static int install_zoneinfo_file(const char *zoneinfo_file);
202 static int set_zone_multi(dialogMenuItem *);
203 static int set_zone_whole_country(dialogMenuItem *);
204 static int set_zone_menu(dialogMenuItem *);
205 static int set_zone_utc(void);
208 dialogMenuItem *menu;
212 static struct continent africa, america, antarctica, arctic, asia, atlantic;
213 static struct continent australia, europe, indian, pacific, utc;
215 static struct continent_names {
217 struct continent *continent;
218 } continent_names[] = {
219 { "Africa", &africa },
220 { "America", &america },
221 { "Antarctica", &antarctica },
222 { "Arctic", &arctic },
224 { "Atlantic", &atlantic },
225 { "Australia", &australia },
226 { "Europe", &europe },
227 { "Indian", &indian },
228 { "Pacific", &pacific },
232 static struct continent_items {
235 } continent_items[] = {
237 { "2", "America -- North and South" },
238 { "3", "Antarctica" },
239 { "4", "Arctic Ocean" },
241 { "6", "Atlantic Ocean" },
242 { "7", "Australia" },
244 { "9", "Indian Ocean" },
245 { "0", "Pacific Ocean" },
249 #define NCONTINENTS \
250 (int)((sizeof(continent_items)) / (sizeof(continent_items[0])))
251 static dialogMenuItem continents[NCONTINENTS];
253 #define OCEANP(x) ((x) == 3 || (x) == 5 || (x) == 8 || (x) == 9)
256 continent_country_menu(dialogMenuItem *continent)
258 char title[64], prompt[64];
259 struct continent *contp = continent->data;
260 int isocean = OCEANP(continent - continents);
264 if (strcmp(continent->title, "UTC") == 0)
265 return set_zone_utc();
267 /* Short cut -- if there's only one country, don't post a menu. */
268 if (contp->nitems == 1)
269 return (contp->menu[0].fire(&contp->menu[0]));
271 /* It's amazing how much good grammar really matters... */
273 snprintf(title, sizeof(title), "Countries in %s",
275 snprintf(prompt, sizeof(prompt), "Select a country or region");
277 snprintf(title, sizeof(title), "Islands and groups in the %s",
279 snprintf(prompt, sizeof(prompt), "Select an island or group");
282 menulen = contp->nitems < 16 ? contp->nitems : 16;
283 rv = xdialog_menu(title, prompt, -1, -1, menulen, contp->nitems,
286 return (DITEM_LEAVE_MENU);
287 return (DITEM_RECREATE);
290 static struct continent *
291 find_continent(const char *name)
295 for (i = 0; i < NCONTINENTS; i++)
296 if (strcmp(name, continent_names[i].name) == 0)
297 return (continent_names[i].continent);
305 char *filename; /* use iff nzones < 0 */
306 struct continent *continent; /* use iff nzones < 0 */
307 TAILQ_HEAD(, zone) zones; /* use iff nzones > 0 */
308 dialogMenuItem *submenu; /* use iff nzones > 0 */
312 TAILQ_ENTRY(zone) link;
315 struct continent *continent;
319 * This is the easiest organization... we use ISO 3166 country codes,
320 * of the two-letter variety, so we just size this array to suit.
321 * Beats worrying about dynamic allocation.
323 #define NCOUNTRIES (26 * 26)
324 static struct country countries[NCOUNTRIES];
326 #define CODE2INT(s) ((s[0] - 'A') * 26 + (s[1] - 'A'))
329 * Read the ISO 3166 country code database in _PATH_ISO3166
330 * (/usr/share/misc/iso3166). On error, exit via err(3).
333 read_iso3166_table(void)
341 fp = fopen(path_iso3166, "r");
343 err(1, "%s", path_iso3166);
346 while ((s = fgetln(fp, &len)) != 0) {
348 if (s[len - 1] != '\n')
349 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
351 if (s[0] == '#' || strspn(s, " \t") == len - 1)
354 /* Isolate the two-letter code. */
355 t = strsep(&s, "\t");
356 if (t == 0 || strlen(t) != 2)
357 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
358 if (t[0] < 'A' || t[0] > 'Z' || t[1] < 'A' || t[1] > 'Z')
359 errx(1, "%s:%d: invalid code `%s'", path_iso3166,
362 /* Now skip past the three-letter and numeric codes. */
363 name = strsep(&s, "\t"); /* 3-let */
364 if (name == 0 || strlen(name) != 3)
365 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
366 name = strsep(&s, "\t"); /* numeric */
367 if (name == 0 || strlen(name) != 3)
368 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
372 cp = &countries[CODE2INT(t)];
374 errx(1, "%s:%d: country code `%s' multiply defined: %s",
375 path_iso3166, lineno, t, cp->name);
376 cp->name = strdup(name);
377 if (cp->name == NULL)
378 errx(1, "malloc failed");
381 errx(1, "malloc failed");
388 add_zone_to_country(int lineno, const char *tlc, const char *descr,
389 const char *file, struct continent *cont)
394 if (tlc[0] < 'A' || tlc[0] > 'Z' || tlc[1] < 'A' || tlc[1] > 'Z')
395 errx(1, "%s:%d: country code `%s' invalid", path_zonetab,
398 cp = &countries[CODE2INT(tlc)];
400 errx(1, "%s:%d: country code `%s' unknown", path_zonetab,
405 errx(1, "%s:%d: conflicting zone definition",
406 path_zonetab, lineno);
408 zp = malloc(sizeof(*zp));
410 errx(1, "malloc(%zu)", sizeof(*zp));
413 TAILQ_INIT(&cp->zones);
415 zp->descr = strdup(descr);
416 if (zp->descr == NULL)
417 errx(1, "malloc failed");
418 zp->filename = strdup(file);
419 if (zp->filename == NULL)
420 errx(1, "malloc failed");
421 zp->continent = cont;
422 TAILQ_INSERT_TAIL(&cp->zones, zp, link);
426 errx(1, "%s:%d: zone must have description",
427 path_zonetab, lineno);
429 errx(1, "%s:%d: zone multiply defined",
430 path_zonetab, lineno);
432 cp->filename = strdup(file);
433 if (cp->filename == NULL)
434 errx(1, "malloc failed");
435 cp->continent = cont;
440 * This comparison function intentionally sorts all of the null-named
441 * ``countries''---i.e., the codes that don't correspond to a real
442 * country---to the end. Everything else is lexical by country name.
445 compare_countries(const void *xa, const void *xb)
447 const struct country *a = xa, *b = xb;
449 if (a->name == 0 && b->name == 0)
451 if (a->name == 0 && b->name != 0)
456 return (strcmp(a->name, b->name));
460 * This must be done AFTER all zone descriptions are read, since it breaks
467 qsort(countries, NCOUNTRIES, sizeof(countries[0]), compare_countries);
475 struct continent *cont;
477 char *line, *tlc, *coord, *file, *descr, *p;
480 fp = fopen(path_zonetab, "r");
482 err(1, "%s", path_zonetab);
485 while ((line = fgetln(fp, &len)) != 0) {
487 if (line[len - 1] != '\n')
488 errx(1, "%s:%d: invalid format", path_zonetab, lineno);
489 line[len - 1] = '\0';
493 tlc = strsep(&line, "\t");
494 if (strlen(tlc) != 2)
495 errx(1, "%s:%d: invalid country code `%s'",
496 path_zonetab, lineno, tlc);
497 coord = strsep(&line, "\t"); /* Unused */
498 file = strsep(&line, "\t");
499 p = strchr(file, '/');
501 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab,
504 strncat(contbuf, file, p - file);
505 cont = find_continent(contbuf);
507 errx(1, "%s:%d: invalid region `%s'", path_zonetab,
510 descr = (line != NULL && *line != '\0') ? line : NULL;
512 add_zone_to_country(lineno, tlc, descr, file, cont);
521 struct zone *zp, *zp2;
522 struct continent *cont;
527 * First, count up all the countries in each continent/ocean.
528 * Be careful to count those countries which have multiple zones
529 * only once for each. NB: some countries are in multiple
532 for (cp = countries; cp->name; cp++) {
535 if (cp->nzones < 0) {
536 cp->continent->nitems++;
538 TAILQ_FOREACH(zp, &cp->zones, link) {
539 cont = zp->continent;
540 for (zp2 = TAILQ_FIRST(&cp->zones);
541 zp2->continent != cont;
542 zp2 = TAILQ_NEXT(zp2, link))
545 zp->continent->nitems++;
551 * Now allocate memory for the country menus and initialize
552 * continent menus. We set nitems back to zero so that we can
553 * use it for counting again when we actually build the menus.
555 memset(continents, 0, sizeof(continents));
556 for (i = 0; i < NCONTINENTS; i++) {
557 continent_names[i].continent->menu =
558 malloc(sizeof(dialogMenuItem) *
559 continent_names[i].continent->nitems);
560 if (continent_names[i].continent->menu == 0)
561 errx(1, "malloc for continent menu");
562 continent_names[i].continent->nitems = 0;
563 continents[i].prompt = continent_items[i].prompt;
564 continents[i].title = continent_items[i].title;
565 continents[i].fire = continent_country_menu;
566 continents[i].data = continent_names[i].continent;
570 * Now that memory is allocated, create the menu items for
571 * each continent. For multiple-zone countries, also create
572 * the country's zone submenu.
574 for (cp = countries; cp->name; cp++) {
577 if (cp->nzones < 0) {
578 dmi = &cp->continent->menu[cp->continent->nitems];
579 memset(dmi, 0, sizeof(*dmi));
580 asprintf(&dmi->prompt, "%d", ++cp->continent->nitems);
581 dmi->title = cp->name;
582 dmi->fire = set_zone_whole_country;
585 cp->submenu = malloc(cp->nzones * sizeof(*dmi));
586 if (cp->submenu == 0)
587 errx(1, "malloc for submenu");
589 TAILQ_FOREACH(zp, &cp->zones, link) {
590 cont = zp->continent;
591 dmi = &cp->submenu[cp->nzones];
592 memset(dmi, 0, sizeof(*dmi));
593 asprintf(&dmi->prompt, "%d", ++cp->nzones);
594 dmi->title = zp->descr;
595 dmi->fire = set_zone_multi;
598 for (zp2 = TAILQ_FIRST(&cp->zones);
599 zp2->continent != cont;
600 zp2 = TAILQ_NEXT(zp2, link))
605 dmi = &cont->menu[cont->nitems];
606 memset(dmi, 0, sizeof(*dmi));
607 asprintf(&dmi->prompt, "%d", ++cont->nitems);
608 dmi->title = cp->name;
609 dmi->fire = set_zone_menu;
617 set_zone_menu(dialogMenuItem *dmi)
619 char title[64], prompt[64];
620 struct country *cp = dmi->data;
624 snprintf(title, sizeof(title), "%s Time Zones", cp->name);
625 snprintf(prompt, sizeof(prompt),
626 "Select a zone which observes the same time as your locality.");
627 menulen = cp->nzones < 16 ? cp->nzones : 16;
628 rv = xdialog_menu(title, prompt, -1, -1, menulen, cp->nzones,
631 return (DITEM_RECREATE);
632 return (DITEM_LEAVE_MENU);
638 if (!confirm_zone(NULL))
639 return (DITEM_FAILURE | DITEM_RECREATE);
641 return (install_zoneinfo_file(NULL));
645 install_zoneinfo_file(const char *zoneinfo_file)
648 char title[64], prompt[SILLY_BUFFER_SIZE];
651 int fd1, fd2, copymode;
653 if (lstat(path_localtime, &sb) < 0) {
654 /* Nothing there yet... */
656 } else if (S_ISLNK(sb.st_mode))
662 snprintf(title, sizeof(title), "Info");
663 if (zoneinfo_file == NULL)
664 snprintf(prompt, sizeof(prompt),
665 "Removing %s", path_localtime);
667 snprintf(prompt, sizeof(prompt),
668 "Copying %s to %s", zoneinfo_file, path_localtime);
670 snprintf(prompt, sizeof(prompt),
671 "Creating symbolic link %s to %s",
672 path_localtime, zoneinfo_file);
674 dialog_msgbox(title, prompt, 8, 72, 1);
676 fprintf(stderr, "%s\n", prompt);
680 if (zoneinfo_file == NULL) {
681 if (unlink(path_localtime) < 0 && errno != ENOENT) {
682 snprintf(title, sizeof(title), "Error");
683 snprintf(prompt, sizeof(prompt),
684 "Could not delete %s: %s", path_localtime,
687 dialog_msgbox(title, prompt, 8, 72, 1);
689 fprintf(stderr, "%s\n", prompt);
691 return (DITEM_FAILURE | DITEM_RECREATE);
693 if (unlink(path_db) < 0 && errno != ENOENT) {
694 snprintf(title, sizeof(title), "Error");
695 snprintf(prompt, sizeof(prompt),
696 "Could not delete %s: %s", path_db,
699 dialog_msgbox(title, prompt, 8, 72, 1);
701 fprintf(stderr, "%s\n", prompt);
703 return (DITEM_FAILURE | DITEM_RECREATE);
706 snprintf(title, sizeof(title), "Done");
707 snprintf(prompt, sizeof(prompt),
708 "Removed %s", path_localtime);
710 dialog_msgbox(title, prompt, 8, 72, 1);
712 fprintf(stderr, "%s\n", prompt);
714 return (DITEM_LEAVE_MENU);
718 fd1 = open(zoneinfo_file, O_RDONLY, 0);
720 snprintf(title, sizeof(title), "Error");
721 snprintf(prompt, sizeof(prompt),
722 "Could not open %s: %s", zoneinfo_file,
725 dialog_msgbox(title, prompt, 8, 72, 1);
727 fprintf(stderr, "%s\n", prompt);
728 return (DITEM_FAILURE | DITEM_RECREATE);
731 if (unlink(path_localtime) < 0 && errno != ENOENT) {
732 snprintf(prompt, sizeof(prompt),
733 "Could not unlink %s: %s",
734 path_localtime, strerror(errno));
736 snprintf(title, sizeof(title), "Error");
737 dialog_msgbox(title, prompt, 8, 72, 1);
739 fprintf(stderr, "%s\n", prompt);
740 return (DITEM_FAILURE | DITEM_RECREATE);
743 fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
744 S_IRUSR | S_IRGRP | S_IROTH);
746 snprintf(title, sizeof(title), "Error");
747 snprintf(prompt, sizeof(prompt),
748 "Could not open %s: %s",
749 path_localtime, strerror(errno));
751 dialog_msgbox(title, prompt, 8, 72, 1);
753 fprintf(stderr, "%s\n", prompt);
754 return (DITEM_FAILURE | DITEM_RECREATE);
757 while ((len = read(fd1, buf, sizeof(buf))) > 0)
758 if ((len = write(fd2, buf, len)) < 0)
762 snprintf(title, sizeof(title), "Error");
763 snprintf(prompt, sizeof(prompt),
764 "Error copying %s to %s %s", zoneinfo_file,
765 path_localtime, strerror(errno));
767 dialog_msgbox(title, prompt, 8, 72, 1);
769 fprintf(stderr, "%s\n", prompt);
770 /* Better to leave none than a corrupt one. */
771 unlink(path_localtime);
772 return (DITEM_FAILURE | DITEM_RECREATE);
777 if (access(zoneinfo_file, R_OK) != 0) {
778 snprintf(title, sizeof(title), "Error");
779 snprintf(prompt, sizeof(prompt),
780 "Cannot access %s: %s", zoneinfo_file,
783 dialog_msgbox(title, prompt, 8, 72, 1);
785 fprintf(stderr, "%s\n", prompt);
786 return (DITEM_FAILURE | DITEM_RECREATE);
788 if (unlink(path_localtime) < 0 && errno != ENOENT) {
789 snprintf(prompt, sizeof(prompt),
790 "Could not unlink %s: %s",
791 path_localtime, strerror(errno));
793 snprintf(title, sizeof(title), "Error");
794 dialog_msgbox(title, prompt, 8, 72, 1);
796 fprintf(stderr, "%s\n", prompt);
797 return (DITEM_FAILURE | DITEM_RECREATE);
799 if (symlink(zoneinfo_file, path_localtime) < 0) {
800 snprintf(title, sizeof(title), "Error");
801 snprintf(prompt, sizeof(prompt),
802 "Cannot create symbolic link %s to %s: %s",
803 path_localtime, zoneinfo_file,
806 dialog_msgbox(title, prompt, 8, 72, 1);
808 fprintf(stderr, "%s\n", prompt);
809 return (DITEM_FAILURE | DITEM_RECREATE);
814 snprintf(title, sizeof(title), "Done");
816 snprintf(prompt, sizeof(prompt),
817 "Copied timezone file from %s to %s",
818 zoneinfo_file, path_localtime);
820 snprintf(prompt, sizeof(prompt),
821 "Created symbolic link from %s to %s",
822 zoneinfo_file, path_localtime);
824 dialog_msgbox(title, prompt, 8, 72, 1);
826 fprintf(stderr, "%s\n", prompt);
830 return (DITEM_LEAVE_MENU);
834 install_zoneinfo(const char *zoneinfo)
838 char path_zoneinfo_file[MAXPATHLEN];
840 sprintf(path_zoneinfo_file, "%s/%s", path_zoneinfo, zoneinfo);
841 rv = install_zoneinfo_file(path_zoneinfo_file);
843 /* Save knowledge for later */
844 if (reallydoit && (rv & DITEM_FAILURE) == 0) {
845 if ((f = fopen(path_db, "w")) != NULL) {
846 fprintf(f, "%s\n", zoneinfo);
855 confirm_zone(const char *filename)
857 char title[64], prompt[64];
862 setenv("TZ", filename == NULL ? "" : filename, 1);
866 snprintf(title, sizeof(title), "Confirmation");
867 snprintf(prompt, sizeof(prompt),
868 "Does the abbreviation `%s' look reasonable?", tm->tm_zone);
869 rv = !dialog_yesno(title, prompt, 5, 72);
874 set_zone_multi(dialogMenuItem *dmi)
876 struct zone *zp = dmi->data;
879 if (!confirm_zone(zp->filename))
880 return (DITEM_FAILURE | DITEM_RECREATE);
882 rv = install_zoneinfo(zp->filename);
887 set_zone_whole_country(dialogMenuItem *dmi)
889 struct country *cp = dmi->data;
892 if (!confirm_zone(cp->filename))
893 return (DITEM_FAILURE | DITEM_RECREATE);
895 rv = install_zoneinfo(cp->filename);
903 fprintf(stderr, "usage: tzsetup [-nrs] [-C chroot_directory]"
904 " [zoneinfo_file | zoneinfo_name]\n");
909 main(int argc, char **argv)
911 char title[64], prompt[128];
912 int c, fd, rv, skiputc;
915 while ((c = getopt(argc, argv, "C:nrs")) != -1) {
935 if (argc - optind > 1)
938 if (chrootenv == NULL) {
939 strcpy(path_zonetab, _PATH_ZONETAB);
940 strcpy(path_iso3166, _PATH_ISO3166);
941 strcpy(path_zoneinfo, _PATH_ZONEINFO);
942 strcpy(path_localtime, _PATH_LOCALTIME);
943 strcpy(path_db, _PATH_DB);
944 strcpy(path_wall_cmos_clock, _PATH_WALL_CMOS_CLOCK);
946 sprintf(path_zonetab, "%s/%s", chrootenv, _PATH_ZONETAB);
947 sprintf(path_iso3166, "%s/%s", chrootenv, _PATH_ISO3166);
948 sprintf(path_zoneinfo, "%s/%s", chrootenv, _PATH_ZONEINFO);
949 sprintf(path_localtime, "%s/%s", chrootenv, _PATH_LOCALTIME);
950 sprintf(path_db, "%s/%s", chrootenv, _PATH_DB);
951 sprintf(path_wall_cmos_clock, "%s/%s", chrootenv,
952 _PATH_WALL_CMOS_CLOCK);
956 /* Override the user-supplied umask. */
957 (void)umask(S_IWGRP | S_IWOTH);
959 if (reinstall == 1) {
961 char zoneinfo[MAXPATHLEN];
963 if ((f = fopen(path_db, "r")) != NULL) {
964 if (fgets(zoneinfo, sizeof(zoneinfo), f) != NULL) {
965 zoneinfo[sizeof(zoneinfo) - 1] = 0;
966 if (strlen(zoneinfo) > 0) {
967 zoneinfo[strlen(zoneinfo) - 1] = 0;
968 rv = install_zoneinfo(zoneinfo);
969 exit(rv & ~DITEM_LEAVE_MENU);
971 errx(1, "Error reading %s.\n", path_db);
975 "Unable to determine earlier installed zoneinfo "
976 "name. Check %s", path_db);
978 errx(1, "Cannot open %s for reading. Does it exist?", path_db);
982 * If the arguments on the command-line do not specify a file,
983 * then interpret it as a zoneinfo name
985 if (optind == argc - 1) {
988 if (stat(argv[optind], &sb) != 0) {
990 rv = install_zoneinfo(argv[optind]);
991 exit(rv & ~DITEM_LEAVE_MENU);
996 read_iso3166_table();
1001 init_dialog(stdin, stdout);
1003 DIALOG_VARS save_vars;
1006 snprintf(title, sizeof(title),
1007 "Select local or UTC (Greenwich Mean Time) clock");
1008 snprintf(prompt, sizeof(prompt),
1009 "Is this machine's CMOS clock set to UTC? "
1010 "If it is set to local time,\n"
1011 "or you don't know, please choose NO here!");
1012 dlg_save_vars(&save_vars);
1013 #if !defined(__sparc64__)
1014 dialog_vars.defaultno = TRUE;
1016 yesno = dialog_yesno(title, prompt, 7, 73);
1017 dlg_restore_vars(&save_vars);
1020 unlink(path_wall_cmos_clock);
1023 fd = open(path_wall_cmos_clock,
1024 O_WRONLY | O_CREAT | O_TRUNC,
1025 S_IRUSR | S_IRGRP | S_IROTH);
1029 path_wall_cmos_clock);
1036 if (optind == argc - 1) {
1037 snprintf(title, sizeof(title), "Default timezone provided");
1038 snprintf(prompt, sizeof(prompt),
1039 "\nUse the default `%s' zone?", argv[optind]);
1040 if (!dialog_yesno(title, prompt, 7, 72)) {
1041 rv = install_zoneinfo_file(argv[optind]);
1044 exit(rv & ~DITEM_LEAVE_MENU);
1048 snprintf(title, sizeof(title), "Time Zone Selector");
1049 snprintf(prompt, sizeof(prompt), "Select a region");
1050 xdialog_menu(title, prompt, -1, -1, NCONTINENTS, NCONTINENTS,