Module Name: src
Committed By: martin
Date: Fri Feb 27 11:29:44 UTC 2015
Modified Files:
src/usr.sbin/sysinst [netbsd-7]: defs.h main.c net.c run.c util.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.3.4.1 -r1.3.4.2 src/usr.sbin/sysinst/defs.h \
src/usr.sbin/sysinst/main.c
cvs rdiff -u -r1.2.4.1 -r1.2.4.2 src/usr.sbin/sysinst/net.c \
src/usr.sbin/sysinst/run.c
cvs rdiff -u -r1.3.2.1 -r1.3.2.2 src/usr.sbin/sysinst/util.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/sysinst/defs.h
diff -u src/usr.sbin/sysinst/defs.h:1.3.4.1 src/usr.sbin/sysinst/defs.h:1.3.4.2
--- src/usr.sbin/sysinst/defs.h:1.3.4.1 Sun Jan 11 04:32:38 2015
+++ src/usr.sbin/sysinst/defs.h Fri Feb 27 11:29:44 2015
@@ -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 @@ void get_tz_default(void);
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)
Index: src/usr.sbin/sysinst/main.c
diff -u src/usr.sbin/sysinst/main.c:1.3.4.1 src/usr.sbin/sysinst/main.c:1.3.4.2
--- src/usr.sbin/sysinst/main.c:1.3.4.1 Sat Aug 23 03:44:02 2014
+++ src/usr.sbin/sysinst/main.c Fri Feb 27 11:29:44 2015
@@ -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 @@ cleanup(void)
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;
Index: src/usr.sbin/sysinst/net.c
diff -u src/usr.sbin/sysinst/net.c:1.2.4.1 src/usr.sbin/sysinst/net.c:1.2.4.2
--- src/usr.sbin/sysinst/net.c:1.2.4.1 Sat Aug 23 03:44:02 2014
+++ src/usr.sbin/sysinst/net.c Fri Feb 27 11:29:44 2015
@@ -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 @@ done:
}
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')
Index: src/usr.sbin/sysinst/run.c
diff -u src/usr.sbin/sysinst/run.c:1.2.4.1 src/usr.sbin/sysinst/run.c:1.2.4.2
--- src/usr.sbin/sysinst/run.c:1.2.4.1 Wed Dec 31 06:23:11 2014
+++ src/usr.sbin/sysinst/run.c Fri Feb 27 11:29:44 2015
@@ -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 @@ log_flip(menudesc *m, void *arg)
(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 @@ log_flip(menudesc *m, void *arg)
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 @@ script_flip(menudesc *m, void *arg)
(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 @@ script_flip(menudesc *m, void *arg)
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",
Index: src/usr.sbin/sysinst/util.c
diff -u src/usr.sbin/sysinst/util.c:1.3.2.1 src/usr.sbin/sysinst/util.c:1.3.2.2
--- src/usr.sbin/sysinst/util.c:1.3.2.1 Sat Aug 23 03:44:02 2014
+++ src/usr.sbin/sysinst/util.c Fri Feb 27 11:29:44 2015
@@ -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 @@ set_tz_select(menudesc *m, void *arg)
{
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 @@ set_tz_select(menudesc *m, void *arg)
/* 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 @@ set_timezone(void)
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 @@ set_timezone(void)
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 @@ binary_available(const char *prog)
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";
+}