Module Name: src
Committed By: christos
Date: Tue Oct 14 16:35:20 UTC 2014
Modified Files:
src/usr.sbin/sysinst: defs.h main.c net.c run.c util.c
Log Message:
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.4 -r1.5 src/usr.sbin/sysinst/defs.h \
src/usr.sbin/sysinst/util.c
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/sysinst/main.c
cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/sysinst/net.c
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/sysinst/run.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.4 src/usr.sbin/sysinst/defs.h:1.5
--- src/usr.sbin/sysinst/defs.h:1.4 Fri Sep 12 20:38:36 2014
+++ src/usr.sbin/sysinst/defs.h Tue Oct 14 12:35:20 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.4 2014/09/13 00:38:36 roy Exp $ */
+/* $NetBSD: defs.h,v 1.5 2014/10/14 16:35:20 christos Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -549,6 +549,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/util.c
diff -u src/usr.sbin/sysinst/util.c:1.4 src/usr.sbin/sysinst/util.c:1.5
--- src/usr.sbin/sysinst/util.c:1.4 Tue Aug 19 09:36:04 2014
+++ src/usr.sbin/sysinst/util.c Tue Oct 14 12:35:20 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.4 2014/08/19 13:36:04 martin Exp $ */
+/* $NetBSD: util.c,v 1.5 2014/10/14 16:35:20 christos 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";
+}
Index: src/usr.sbin/sysinst/main.c
diff -u src/usr.sbin/sysinst/main.c:1.5 src/usr.sbin/sysinst/main.c:1.6
--- src/usr.sbin/sysinst/main.c:1.5 Tue Aug 19 09:30:32 2014
+++ src/usr.sbin/sysinst/main.c Tue Oct 14 12:35:20 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.5 2014/08/19 13:30:32 martin Exp $ */
+/* $NetBSD: main.c,v 1.6 2014/10/14 16:35:20 christos 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.16 src/usr.sbin/sysinst/net.c:1.17
--- src/usr.sbin/sysinst/net.c:1.16 Mon Sep 22 14:47:41 2014
+++ src/usr.sbin/sysinst/net.c Tue Oct 14 12:35:20 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: net.c,v 1.16 2014/09/22 18:47:41 roy Exp $ */
+/* $NetBSD: net.c,v 1.17 2014/10/14 16:35:20 christos Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -779,9 +779,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 src/usr.sbin/sysinst/run.c:1.3
--- src/usr.sbin/sysinst/run.c:1.2 Sun Aug 3 12:09:38 2014
+++ src/usr.sbin/sysinst/run.c Tue Oct 14 12:35:20 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: run.c,v 1.2 2014/08/03 16:09:38 martin Exp $ */
+/* $NetBSD: run.c,v 1.3 2014/10/14 16:35:20 christos 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",