Source-Changes-HG archive

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

[src/netbsd-7]: src/usr.sbin/sysinst Pull up following revision(s) (requested...



details:   https://anonhg.NetBSD.org/src/rev/b9b2fa9aea63
branches:  netbsd-7
changeset: 799034:b9b2fa9aea63
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Feb 27 11:29:44 2015 +0000

description:
Pull up following revision(s) (requested by snj in ticket #554):
        usr.sbin/sysinst/defs.h: revision 1.5
        usr.sbin/sysinst/main.c: revision 1.6
        usr.sbin/sysinst/net.c: revision 1.17
        usr.sbin/sysinst/util.c: revision 1.5
        usr.sbin/sysinst/run.c: revision 1.3
Don't use asctime(localtime(time_t *)) because this is really ctime(time_t *)
and not checking the result of localtime can lead to tears.
Add a safectime() that always returns a good string, and add some debugging
so that we can see if there is indeed something wrong in the new libc time
code.

diffstat:

 usr.sbin/sysinst/defs.h |   3 ++-
 usr.sbin/sysinst/main.c |   7 +++----
 usr.sbin/sysinst/net.c  |   5 ++---
 usr.sbin/sysinst/run.c  |  10 +++++-----
 usr.sbin/sysinst/util.c |  25 ++++++++++++++++++++++---
 5 files changed, 34 insertions(+), 16 deletions(-)

diffs (174 lines):

diff -r 3d90e26ad6f4 -r b9b2fa9aea63 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h   Fri Feb 27 11:23:53 2015 +0000
+++ b/usr.sbin/sysinst/defs.h   Fri Feb 27 11:29:44 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.3.4.1 2015/01/11 04:32:38 snj Exp $ */
+/*     $NetBSD: defs.h,v 1.3.4.2 2015/02/27 11:29:44 martin Exp $      */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -550,6 +550,7 @@
 int    extract_file(distinfo *, int);
 void   do_coloring (unsigned int, unsigned int);
 int set_menu_select(menudesc *, void *);
+const char *safectime(time_t *);
 
 /* from target.c */
 #if defined(DEBUG)  || defined(DEBUG_ROOT)
diff -r 3d90e26ad6f4 -r b9b2fa9aea63 usr.sbin/sysinst/main.c
--- a/usr.sbin/sysinst/main.c   Fri Feb 27 11:23:53 2015 +0000
+++ b/usr.sbin/sysinst/main.c   Fri Feb 27 11:29:44 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.3.4.1 2014/08/23 03:44:02 riz Exp $ */
+/*     $NetBSD: main.c,v 1.3.4.2 2015/02/27 11:29:44 martin Exp $      */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -474,14 +474,13 @@
        endwin();
 
        if (logfp) {
-               fprintf(logfp, "Log ended at: %s\n", asctime(localtime(&tloc)));
+               fprintf(logfp, "Log ended at: %s\n", safectime(&tloc));
                fflush(logfp);
                fclose(logfp);
                logfp = NULL;
        }
        if (script) {
-               fprintf(script, "# Script ended at: %s\n",
-                   asctime(localtime(&tloc)));
+               fprintf(script, "# Script ended at: %s\n", safectime(&tloc));
                fflush(script);
                fclose(script);
                script = NULL;
diff -r 3d90e26ad6f4 -r b9b2fa9aea63 usr.sbin/sysinst/net.c
--- a/usr.sbin/sysinst/net.c    Fri Feb 27 11:23:53 2015 +0000
+++ b/usr.sbin/sysinst/net.c    Fri Feb 27 11:29:44 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.2.4.1 2014/08/23 03:44:02 riz Exp $  */
+/*     $NetBSD: net.c,v 1.2.4.2 2015/02/27 11:29:44 martin Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -802,9 +802,8 @@
                }
                scripting_fprintf(NULL, "cat <<EOF >/etc/resolv.conf\n");
                time(&now);
-               /* NB: ctime() returns a string ending in  '\n' */
                scripting_fprintf(f, ";\n; BIND data file\n; %s %s;\n",
-                   "Created by NetBSD sysinst on", ctime(&now));
+                   "Created by NetBSD sysinst on", safectime(&now));
                if (net_domain[0] != '\0')
                        scripting_fprintf(f, "search %s\n", net_domain);
                if (net_namesvr[0] != '\0')
diff -r 3d90e26ad6f4 -r b9b2fa9aea63 usr.sbin/sysinst/run.c
--- a/usr.sbin/sysinst/run.c    Fri Feb 27 11:23:53 2015 +0000
+++ b/usr.sbin/sysinst/run.c    Fri Feb 27 11:29:44 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: run.c,v 1.2.4.1 2014/12/31 06:23:11 snj Exp $  */
+/*     $NetBSD: run.c,v 1.2.4.2 2015/02/27 11:29:44 martin Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -113,7 +113,7 @@
 
        (void)time(&tloc);
        if (logfp) {
-               fprintf(logfp, "Log ended at: %s\n", asctime(localtime(&tloc)));
+               fprintf(logfp, "Log ended at: %s\n", safectime(&tloc));
                fflush(logfp);
                fclose(logfp);
                logfp = NULL;
@@ -121,7 +121,7 @@
                logfp = fopen("/tmp/sysinst.log", "a");
                if (logfp != NULL) {
                        fprintf(logfp,
-                           "Log started at: %s\n", asctime(localtime(&tloc)));
+                           "Log started at: %s\n", safectime(&tloc));
                        fflush(logfp);
                } else {
                        if (mainwin) {
@@ -146,7 +146,7 @@
        (void)time(&tloc);
        if (script) {
                scripting_fprintf(NULL, "# Script ended at: %s\n",
-                   asctime(localtime(&tloc)));
+                   safectime(&tloc));
                fflush(script);
                fclose(script);
                script = NULL;
@@ -155,7 +155,7 @@
                if (script != NULL) {
                        scripting_fprintf(NULL, "#!/bin/sh\n");
                        scripting_fprintf(NULL, "# Script started at: %s\n",
-                           asctime(localtime(&tloc)));
+                           safectime(&tloc));
                        fflush(script);
                } else {
                        msg_display(MSG_openfail, "script file",
diff -r 3d90e26ad6f4 -r b9b2fa9aea63 usr.sbin/sysinst/util.c
--- a/usr.sbin/sysinst/util.c   Fri Feb 27 11:23:53 2015 +0000
+++ b/usr.sbin/sysinst/util.c   Fri Feb 27 11:29:44 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.3.2.1 2014/08/23 03:44:02 riz Exp $ */
+/*     $NetBSD: util.c,v 1.3.2.2 2015/02/27 11:29:44 martin Exp $      */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1233,6 +1233,7 @@
 {
        time_t t;
        char *new;
+       struct tm *tm;
 
        if (m && strcmp(tz_selected, m->opts[m->cursel].opt_name) != 0) {
                /* Change the displayed timezone */
@@ -1251,8 +1252,10 @@
 
        /* Update displayed time */
        t = time(NULL);
+       tm = localtime(&t);
        msg_display(MSG_choose_timezone,
-                   tz_default, tz_selected, ctime(&t), localtime(&t)->tm_zone);
+                   tz_default, tz_selected, safectime(&t), tm ? tm->tm_zone :
+                   "?");
        return 0;
 }
 
@@ -1406,6 +1409,7 @@
        char localtime_link[STRSIZE];
        char localtime_target[STRSIZE];
        time_t t;
+       struct tm *tm;
        int menu_no;
 
        strlcpy(zoneinfo_dir, target_expand("/usr/share/zoneinfo/"),
@@ -1418,8 +1422,10 @@
        snprintf(tz_env, sizeof(tz_env), "%s%s", zoneinfo_dir, tz_selected);
        setenv("TZ", tz_env, 1);
        t = time(NULL);
+       tm = localtime(&t);
        msg_display(MSG_choose_timezone,
-                   tz_default, tz_selected, ctime(&t), localtime(&t)->tm_zone);
+                   tz_default, tz_selected, safectime(&t), tm ? tm->tm_zone :
+                   "?");
 
        signal(SIGALRM, timezone_sig);
        alarm(60);
@@ -1698,3 +1704,16 @@
         return 0;
 }
 
+const char *
+safectime(time_t *t)
+{
+       const char *s = ctime(t);
+       if (s != NULL)
+               return s;
+
+       // Debugging.
+       fprintf(stderr, "Can't convert to localtime 0x%jx (%s)\n",
+           (intmax_t)*t, strerror(errno));
+             /*123456789012345678901234*/
+       return "preposterous clock time\n";
+}



Home | Main Index | Thread Index | Old Index