Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/distrib/utils/sysinst Pull changes up to netbsd-1-5 bra...



details:   https://anonhg.NetBSD.org/src/rev/bd89731c119d
branches:  netbsd-1-5
changeset: 489115:bd89731c119d
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Tue Aug 15 02:12:52 2000 +0000

description:
Pull changes up to netbsd-1-5 branch, OK'd by thorpej:

Revisions:
 > cvs rdiff -r1.54 -r1.55 basesrc/distrib/utils/sysinst/defs.h
 > cvs rdiff -r1.19 -r1.20 basesrc/distrib/utils/sysinst/install.c
 > cvs rdiff -r1.42 -r1.43 basesrc/distrib/utils/sysinst/menus.mi.en
 > cvs rdiff -r1.64 -r1.65 basesrc/distrib/utils/sysinst/msg.mi.en
 > cvs rdiff -r1.30 -r1.31 basesrc/distrib/utils/sysinst/run.c
 > cvs rdiff -r1.51 -r1.52 basesrc/distrib/utils/sysinst/util.c

Log Message:
 >  * Add timezone-setting menu to sysinst, offering all timezones from
 >    (/mnt)/usr/share/zoneinfo in a listbox, and setting (/mnt)/etc/localtime
 >    accordingly.
 >  * Adjust for the needed menuc change un run.c's log_flip() and script_flip()
 >    functions.
 >
 > Related PRs:
 >  5777   sysinst does not offer to tweak /etc/localtime
 >  8099   changing the default time zone is non-obvious
 >  9910   sysinst doesn't ask about setting timezone

diffstat:

 distrib/utils/sysinst/defs.h      |    3 +-
 distrib/utils/sysinst/install.c   |    4 +-
 distrib/utils/sysinst/menus.mi.en |    6 +-
 distrib/utils/sysinst/msg.mi.en   |   11 ++-
 distrib/utils/sysinst/run.c       |   10 +-
 distrib/utils/sysinst/util.c      |  165 +++++++++++++++++++++++++++++++++++++-
 6 files changed, 189 insertions(+), 10 deletions(-)

diffs (291 lines):

diff -r 517543d0f3eb -r bd89731c119d distrib/utils/sysinst/defs.h
--- a/distrib/utils/sysinst/defs.h      Tue Aug 15 02:09:29 2000 +0000
+++ b/distrib/utils/sysinst/defs.h      Tue Aug 15 02:12:52 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.53 2000/06/18 23:50:02 cyber Exp $  */
+/*     $NetBSD: defs.h,v 1.53.2.1 2000/08/15 02:12:52 hubertf Exp $    */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -323,6 +323,7 @@
 void   ask_verbose_dist __P((void));
 int    get_and_unpack_sets(msg success_msg, msg failure_msg);
 int    sanity_check __P((void));
+int    set_timezone __P((void));
 
 /* from target.c */
 int    must_mount_root __P((void));
diff -r 517543d0f3eb -r bd89731c119d distrib/utils/sysinst/install.c
--- a/distrib/utils/sysinst/install.c   Tue Aug 15 02:09:29 2000 +0000
+++ b/distrib/utils/sysinst/install.c   Tue Aug 15 02:12:52 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: install.c,v 1.19 1999/06/22 06:57:00 cgd Exp $ */
+/*     $NetBSD: install.c,v 1.19.10.1 2000/08/15 02:12:52 hubertf Exp $        */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -125,6 +125,8 @@
        if (get_and_unpack_sets(MSG_instcomplete, MSG_abortinst) != 0)
                return;
 
+       set_timezone();
+       
        sanity_check();
 
        md_cleanup_install();
diff -r 517543d0f3eb -r bd89731c119d distrib/utils/sysinst/menus.mi.en
--- a/distrib/utils/sysinst/menus.mi.en Tue Aug 15 02:09:29 2000 +0000
+++ b/distrib/utils/sysinst/menus.mi.en Tue Aug 15 02:12:52 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: menus.mi.en,v 1.40.2.1 2000/08/13 16:32:11 jhawk Exp $ */
+/*     $NetBSD: menus.mi.en,v 1.40.2.2 2000/08/15 02:12:52 hubertf Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -77,6 +77,10 @@
        option "Run /bin/sh",
                action (endwin) { system("/bin/sh"); };
 /*     option "test", action { run_prog(0, 1, NULL, "/bin/pwd"); }; */
+       option "Set timezone", 
+               action {
+                       set_timezone();
+               };
        option "Configure network",
                action {
                        extern int network_up;
diff -r 517543d0f3eb -r bd89731c119d distrib/utils/sysinst/msg.mi.en
--- a/distrib/utils/sysinst/msg.mi.en   Tue Aug 15 02:09:29 2000 +0000
+++ b/distrib/utils/sysinst/msg.mi.en   Tue Aug 15 02:12:52 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg.mi.en,v 1.62.2.2 2000/08/11 01:19:18 hubertf Exp $ */
+/*     $NetBSD: msg.mi.en,v 1.62.2.3 2000/08/15 02:12:53 hubertf Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -748,3 +748,12 @@
 message continue
 {Continue?}
 
+message choose_timezone
+{Please choose the timezone that fits you best from the list below.
+Press RETURN to select an entry, press 'x' followed by RETURN to quit
+the timezone selection. 
+
+ Default:      %s 
+ Selected:     %s 
+ Local time:   %s %s 
+}
diff -r 517543d0f3eb -r bd89731c119d distrib/utils/sysinst/run.c
--- a/distrib/utils/sysinst/run.c       Tue Aug 15 02:09:29 2000 +0000
+++ b/distrib/utils/sysinst/run.c       Tue Aug 15 02:12:52 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: run.c,v 1.30 2000/04/14 21:46:11 thorpej Exp $ */
+/*     $NetBSD: run.c,v 1.30.4.1 2000/08/15 02:12:53 hubertf Exp $     */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -72,8 +72,8 @@
  */
 char* va_prog_cmdstr __P((const char *cmd, va_list ap));
 int launch_subwin __P((WINDOW *actionwin, char **args, struct winsize win, int display));
-int log_flip __P((void));
-int script_flip __P((void));
+int log_flip __P((menudesc *));
+int script_flip __P((menudesc *));
 
 #define BUFSIZE 4096
 
@@ -103,7 +103,7 @@
 }
 
 int
-log_flip(void)
+log_flip(menudesc *m)
 {
        time_t tloc;
 
@@ -129,7 +129,7 @@
 }
 
 int
-script_flip(void)
+script_flip(menudesc *m)
 {
        time_t tloc;
 
diff -r 517543d0f3eb -r bd89731c119d distrib/utils/sysinst/util.c
--- a/distrib/utils/sysinst/util.c      Tue Aug 15 02:09:29 2000 +0000
+++ b/distrib/utils/sysinst/util.c      Tue Aug 15 02:12:52 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.51 2000/06/18 13:40:41 hubertf Exp $        */
+/*     $NetBSD: util.c,v 1.51.2.1 2000/08/15 02:12:53 hubertf Exp $    */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -899,3 +899,166 @@
        refresh();
        return(found);
 }
+
+/*
+ * Some globals to pass things back from callbacks
+ */
+static char zoneinfo_dir[STRSIZE];
+static char *tz_selected;      /* timezonename (relative to share/zoneinfo */
+static char *tz_default;       /* UTC, or whatever /etc/localtime points to */
+static char tz_env[STRSIZE];
+
+/*
+ * Callback from timezone menu
+ */
+static int
+set_timezone_select(menudesc *m)
+{
+       time_t t;
+
+       if (m)
+               tz_selected = m->opts[m->cursel].opt_name;
+       snprintf(tz_env, sizeof(tz_env), "%s/%s",
+                zoneinfo_dir, tz_selected);
+       setenv("TZ", tz_env, 1);
+       t = time(NULL);
+       msg_display(MSG_choose_timezone, 
+                   tz_default, tz_selected, ctime(&t), localtime(&t)->tm_zone);
+       return 0;
+}
+
+/*
+ * Alarm-handler to update example-display
+ */
+static void
+timezone_sig(int sig)
+{
+       set_timezone_select(NULL);
+       alarm(1);
+}
+
+/*
+ * Choose from the files in usr/share/zoneinfo and set etc/localtime
+ */
+int
+set_timezone()
+{
+       char localtime_link[STRSIZE];
+       char localtime_target[STRSIZE];
+       int rc;
+       time_t t;
+       sig_t oldalrm;
+
+       oldalrm=signal(SIGALRM, timezone_sig);
+       alarm(1);
+       
+       strncpy(zoneinfo_dir, target_expand("/usr/share/zoneinfo"), STRSIZE);
+       strncpy(localtime_link, target_expand("/etc/localtime"), STRSIZE);
+
+       rc = readlink(localtime_link, localtime_target,
+                     sizeof(localtime_target));
+       if (rc < 0) {
+               endwin();
+               printf("readlink(\"%s\")\n", localtime_link);
+               exit (1);
+       }
+       localtime_target[rc] = '\0';
+
+       tz_default = strchr(strstr(localtime_target, "zoneinfo"), '/')+1;
+       tz_selected=tz_default;
+       snprintf(tz_env, sizeof(tz_env), "%s/%s",
+                zoneinfo_dir, tz_selected);
+       setenv("TZ", tz_env, 1);
+       t = time(NULL);
+       msg_display(MSG_choose_timezone, 
+                   tz_default, tz_selected, ctime(&t), localtime(&t)->tm_zone);
+
+       {
+               #include <fts.h>
+
+               FTS *tree;
+               FTSENT *entry;
+               int rval;
+               char *argv[2];
+               int skip;
+               struct stat sb;
+               int nfiles, n;
+               int menu_no;
+               menu_ent *tz_menu;
+
+               skip = strlen(zoneinfo_dir);
+               argv[0] = zoneinfo_dir;
+               argv[1] = NULL;
+               if (!(tree = fts_open(argv, FTS_LOGICAL, NULL))) {
+                       endwin();
+                       fprintf(stderr, "ftsopen failed\n");
+                       exit(1);
+               }
+               for (nfiles = 0; (entry = fts_read(tree)) != NULL;) {
+                       stat(entry->fts_accpath, &sb);
+                       if (S_ISREG(sb.st_mode))
+                               nfiles++;
+               }
+               if (errno) {
+                       endwin();
+                       fprintf(stderr, "fts_read\n");
+                       exit(1);
+               }
+               (void)fts_close(tree);
+               
+               tz_menu = malloc(nfiles * sizeof(struct menu_ent));
+               if (tz_menu == NULL) {
+                       endwin();
+                       fprintf(stderr, "malloc nfiles*menu_ent\n");
+                       exit(1);
+               }
+               
+               if (!(tree = fts_open(argv, FTS_LOGICAL, NULL))) {
+                       endwin();
+                       fprintf(stderr, "ftsopen failed\n");
+                       exit(1);
+               }
+               n=0;
+               for (rval=0; (entry = fts_read(tree)) != NULL; ) {
+
+                       stat(entry->fts_accpath, &sb);
+                       if (S_ISREG(sb.st_mode)) {
+                               tz_menu[n].opt_name = strdup(entry->fts_accpath+skip+1);
+                               tz_menu[n].opt_menu = OPT_NOMENU;
+                               tz_menu[n].opt_flags = 0;
+                               tz_menu[n].opt_action = set_timezone_select;
+
+                               n++;
+                       }
+               }
+               if (errno) {
+                       endwin();
+                       fprintf(stderr, "fts_read\n");
+                       exit(1);
+               }
+               (void)fts_close(tree);  
+               
+               menu_no = new_menu(NULL, tz_menu, nfiles, 23, 9,
+                                  12, 32, MC_SCROLL|MC_NOSHORTCUT, NULL, NULL,
+                                  "\nPlease consult the install documents.");
+               if (menu_no < 0) {
+                       endwin();
+                       (void) fprintf(stderr, "Dynamic menu creation failed.\n");
+                       exit(1);
+               }
+               process_menu(menu_no);
+
+               free_menu(menu_no);
+               for(n=0; n < nfiles; n++)
+                       free(tz_menu[n].opt_name);
+               free(tz_menu);
+       }
+       signal(SIGALRM, SIG_IGN);
+
+       snprintf(localtime_target, sizeof(localtime_target),
+                "/usr/share/zoneinfo/%s", tz_selected);
+       unlink(localtime_link);
+       symlink(localtime_target, localtime_link);
+       
+       return 1;
+}



Home | Main Index | Thread Index | Old Index