Source-Changes-HG archive

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

[src/trunk]: src/sbin/dmesg changes from kre@



details:   https://anonhg.NetBSD.org/src/rev/a40261505801
branches:  trunk
changeset: 993594:a40261505801
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Sep 19 23:02:14 2018 +0000

description:
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.

diffstat:

 sbin/dmesg/dmesg.8 |  31 +++++++++++++++++++++++++++----
 sbin/dmesg/dmesg.c |  35 ++++++++++++++++++++++++++++++++---
 2 files changed, 59 insertions(+), 7 deletions(-)

diffs (149 lines):

diff -r 945de23e41af -r a40261505801 sbin/dmesg/dmesg.8
--- a/sbin/dmesg/dmesg.8        Wed Sep 19 22:58:03 2018 +0000
+++ b/sbin/dmesg/dmesg.8        Wed Sep 19 23:02:14 2018 +0000
@@ -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 @@
 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 @@
 .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.
diff -r 945de23e41af -r a40261505801 sbin/dmesg/dmesg.c
--- a/sbin/dmesg/dmesg.c        Wed Sep 19 22:58:03 2018 +0000
+++ b/sbin/dmesg/dmesg.c        Wed Sep 19 23:02:14 2018 +0000
@@ -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 @@
 #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 @@
 #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 @@
 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 @@
        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 @@
        t /= 12;
 
        y = t;
+#else
+       h = t;
+#endif
 
        z = 0;
        o = 0;
@@ -117,9 +139,11 @@
        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 @@
        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;



Home | Main Index | Thread Index | Old Index