Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sysinst Don't use asctime(localtime(time_t *)) beca...
details: https://anonhg.NetBSD.org/src/rev/91d1280e4c43
branches: trunk
changeset: 333016:91d1280e4c43
user: christos <christos%NetBSD.org@localhost>
date: Tue Oct 14 16:35:20 2014 +0000
description:
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 2874df653c01 -r 91d1280e4c43 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h Tue Oct 14 16:15:18 2014 +0000
+++ b/usr.sbin/sysinst/defs.h Tue Oct 14 16:35:20 2014 +0000
@@ -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 @@
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 2874df653c01 -r 91d1280e4c43 usr.sbin/sysinst/main.c
--- a/usr.sbin/sysinst/main.c Tue Oct 14 16:15:18 2014 +0000
+++ b/usr.sbin/sysinst/main.c Tue Oct 14 16:35:20 2014 +0000
@@ -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 @@
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 2874df653c01 -r 91d1280e4c43 usr.sbin/sysinst/net.c
--- a/usr.sbin/sysinst/net.c Tue Oct 14 16:15:18 2014 +0000
+++ b/usr.sbin/sysinst/net.c Tue Oct 14 16:35:20 2014 +0000
@@ -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 @@
}
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 2874df653c01 -r 91d1280e4c43 usr.sbin/sysinst/run.c
--- a/usr.sbin/sysinst/run.c Tue Oct 14 16:15:18 2014 +0000
+++ b/usr.sbin/sysinst/run.c Tue Oct 14 16:35:20 2014 +0000
@@ -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 @@
(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 2874df653c01 -r 91d1280e4c43 usr.sbin/sysinst/util.c
--- a/usr.sbin/sysinst/util.c Tue Oct 14 16:15:18 2014 +0000
+++ b/usr.sbin/sysinst/util.c Tue Oct 14 16:35:20 2014 +0000
@@ -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 @@
{
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