Module Name: src
Committed By: christos
Date: Wed Sep 19 23:02:14 UTC 2018
Modified Files:
src/sbin/dmesg: dmesg.8 dmesg.c
Log Message:
changes from kre@
- pass intmax to fmtydhmsf instead of time_t to avoid extra conversions.
- make -TTT mean "always keep 3 decimal digits of duration precision" (ie:
always print ms) (including trailing 0's, even .000 if it happens)
- make -T (all forms) be subject to the locale (obey the radix character)
- don't print ymd, since that would require calendar calculations to get
right.
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sbin/dmesg/dmesg.8
cvs rdiff -u -r1.36 -r1.37 src/sbin/dmesg/dmesg.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/dmesg/dmesg.8
diff -u src/sbin/dmesg/dmesg.8:1.22 src/sbin/dmesg/dmesg.8:1.23
--- src/sbin/dmesg/dmesg.8:1.22 Tue Sep 18 20:15:05 2018
+++ src/sbin/dmesg/dmesg.8 Wed Sep 19 19:02:14 2018
@@ -1,4 +1,4 @@
-.\" $NetBSD: dmesg.8,v 1.22 2018/09/19 00:15:05 christos Exp $
+.\" $NetBSD: dmesg.8,v 1.23 2018/09/19 23:02:14 christos Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -58,9 +58,15 @@ instead of the default ``/dev/mem''.
Extract the name list from the specified system instead of the default
``/netbsd''.
.It Fl T
-Format uptime timestamps in a human readable form. (using
-.Xr ctime 3 ) .
-Repeating this option, prints the uptime in ISO 8601 duration form.
+Format uptime timestamps in a human readable form (using
+.Xr ctime 3 )
+using output suitable for the local locale as set in the environment.
+Repeating this option, prints the uptime in ISO 8601 duration form,
+giving the duration since boot, in hours, minutes, and seconds (to
+millisecond resolution).
+A third occurrence causes the duration to always be represented
+to millisecond precision, even where that means trailing zeroes
+appear.
.It Fl t
Quiet printing, don't print timestamps.
.El
@@ -91,3 +97,20 @@ The
.Nm
command appeared in
.Bx 3.0 .
+.Sh BUGS
+When
+.Fl TT
+is used, the duration is always given with maximum units of hours,
+even when the number or hours is in the hundreds, or thousands, or more.
+This is because converting hours to days, over periods when
+.Dq time skips
+occur, such as summer time beginning or ending, is not trivial.
+A duration of 26 hours might be 1D3H or 1D1H at such events,
+rather than the usual 1D2H,
+and when a time zone alters its offset,
+even more complex calculations are needed.
+None of those calculations are done
+.Pq even to account for sub-hour time zone shifts ,
+the duration indicated is always calculated by simple division of
+seconds by 60 to produce minutes, and again to produce hours.
+Most of the time\ [!] this is correct.
Index: src/sbin/dmesg/dmesg.c
diff -u src/sbin/dmesg/dmesg.c:1.36 src/sbin/dmesg/dmesg.c:1.37
--- src/sbin/dmesg/dmesg.c:1.36 Wed Sep 19 18:58:03 2018
+++ src/sbin/dmesg/dmesg.c Wed Sep 19 19:02:14 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: dmesg.c,v 1.36 2018/09/19 22:58:03 kre Exp $ */
+/* $NetBSD: dmesg.c,v 1.37 2018/09/19 23:02:14 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -38,7 +38,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
#if 0
static char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93";
#else
-__RCSID("$NetBSD: dmesg.c,v 1.36 2018/09/19 22:58:03 kre Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.37 2018/09/19 23:02:14 christos Exp $");
#endif
#endif /* not lint */
@@ -59,12 +59,17 @@ __RCSID("$NetBSD: dmesg.c,v 1.36 2018/09
#include <vis.h>
#ifndef SMALL
+#include <langinfo.h>
+#include <locale.h>
+
static struct nlist nl[] = {
#define X_MSGBUF 0
{ .n_name = "_msgbufp" },
{ .n_name = NULL },
};
+static const char *radix;
+
__dead static void usage(void);
#define KREAD(addr, var) \
@@ -73,7 +78,10 @@ __dead static void usage(void);
static const char *
fmtydhmsf(char *b, size_t l, intmax_t t, long nsec, int ht)
{
- intmax_t s, m, h, d, M, y;
+ intmax_t s, m, h
+#if 0
+ , d, M, y
+#endif
int z;
int prec;
size_t o;
@@ -84,6 +92,17 @@ fmtydhmsf(char *b, size_t l, intmax_t t,
m = t % 60;
t /= 60;
+#if 0
+ /*
+ * This is wrong for 2 reasons, first, months do not all
+ * have 30 days (and yes, it matters, I think) and because when
+ * summer time begins(ends) "1 day" is 23 (25) hours, not 24.
+ *
+ * We would need to convert to localtime, before and after,
+ * and subtract in localtime format, then normalise, to produce
+ * a meaningfuly yYmMdD string to use here. So just stick to
+ * a count of hours. It is legit, and easy...
+ */
h = t % 24;
t /= 24;
@@ -94,6 +113,9 @@ fmtydhmsf(char *b, size_t l, intmax_t t,
t /= 12;
y = t;
+#else
+ h = t;
+#endif
z = 0;
o = 0;
@@ -117,9 +139,11 @@ fmtydhmsf(char *b, size_t l, intmax_t t,
toupper((unsigned char)__STRING(a)[0]))
APPENDFMT("%s", "P");
+#if 0
APPEND(y);
APPEND(M);
APPEND(d);
+#endif
APPENDFMT("%s", "T");
APPEND(h);
APPEND(m);
@@ -169,6 +193,11 @@ main(int argc, char *argv[])
static const int bmib[] = { CTL_KERN, KERN_BOOTTIME };
size = sizeof(boottime);
+ (void)setlocale(LC_ALL, "");
+ radix = nl_langinfo(RADIXCHAR);
+ if (radix == NULL)
+ radix = "."; /* could also select "," */
+
boottime.tv_sec = 0;
boottime.tv_usec = 0;
lasttime.tv_sec = 0;