Source-Changes-HG archive

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

[src/trunk]: src/sbin/dmesg In -TT mode (ISO8601 duration timestamps) print m...



details:   https://anonhg.NetBSD.org/src/rev/3b659b1f180f
branches:  trunk
changeset: 835974:3b659b1f180f
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Sep 19 22:55:12 2018 +0000

description:
In -TT mode (ISO8601 duration timestamps) print milliseconds as
decimal fractions of a second (as they should be) rather than integer
milliseconds (ie nnn.1means nnn seconds and 1/10 of a second, not
nnn seconds, and 1 millisecond).   While here convert some inappropriate
time_t usage to intmax_t which works better (int, or long, would probably
work just as well).

diffstat:

 sbin/dmesg/dmesg.c |  22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diffs (61 lines):

diff -r d60167698847 -r 3b659b1f180f sbin/dmesg/dmesg.c
--- a/sbin/dmesg/dmesg.c        Wed Sep 19 18:53:25 2018 +0000
+++ b/sbin/dmesg/dmesg.c        Wed Sep 19 22:55:12 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dmesg.c,v 1.34 2018/09/19 00:15:05 christos Exp $      */
+/*     $NetBSD: dmesg.c,v 1.35 2018/09/19 22:55:12 kre 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.34 2018/09/19 00:15:05 christos Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.35 2018/09/19 22:55:12 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -71,10 +71,11 @@
        kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var)
 
 static const char *
-fmtydhmsf(char *b, size_t l, time_t t, long nsec)
+fmtydhmsf(char *b, size_t l, intmax_t t, long nsec)
 {
-       time_t s, m, h, d, M, y;
+       intmax_t s, m, h, d, M, y;
        int z;
+       int prec;
        size_t o;
 
        s = t % 60;
@@ -109,10 +110,10 @@
 
 #define APPEND(a) \
     do if (a) \
-    APPENDFMT("%jd%c", (intmax_t)a, toupper((unsigned char)__STRING(a)[0])); \
+        APPENDFMT("%jd%c", a, toupper((unsigned char)__STRING(a)[0])); \
     while (/*CONSTCOND*/0)
-#define APPENDS(a, s) \
-    APPENDFMT("%jd.%ld%c", (intmax_t)a, s, \
+#define APPENDS(a, pr, ms) \
+    APPENDFMT("%jd%s%.*ld%c", a, radix, pr, ms, \
        toupper((unsigned char)__STRING(a)[0]))
 
        APPENDFMT("%s", "P");
@@ -123,9 +124,12 @@
        APPEND(h);
        APPEND(m);
        if (nsec)
-               nsec = nsec / 1000000;
+               nsec = (nsec + 500000) / 1000000;       /* now milliseconds */
+       prec = 3;
+       while (prec > 0 && (nsec % 10) == 0)
+               --prec, nsec /= 10;
        if (nsec)
-               APPENDS(s, nsec);
+               APPENDS(s, prec, nsec);
        else
                APPEND(s);
        return b;



Home | Main Index | Thread Index | Old Index