Source-Changes-HG archive

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

src: match the linux dmesg flags.



details:   https://anonhg.NetBSD.org/src/rev/61117e8d9231
branches:  trunk
changeset: 318035:61117e8d9231
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Apr 10 22:21:52 2018 +0000
description:
match the linux dmesg flags.

diffstat:

 sbin/dmesg/dmesg.8 |  18 ++++++++++-----
 sbin/dmesg/dmesg.c |  60 ++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 53 insertions(+), 25 deletions(-)

diffs (173 lines):

diff -r 33adfecab453 -r 61117e8d9231 sbin/dmesg/dmesg.8
--- a/sbin/dmesg/dmesg.8        Tue Apr 10 16:12:29 2018 +0000
+++ b/sbin/dmesg/dmesg.8        Tue Apr 10 22:21:52 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: dmesg.8,v 1.18 2018/04/01 19:31:16 christos Exp $
+.\"    $NetBSD: dmesg.8,v 1.19 2018/04/10 22:21:52 christos Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)dmesg.8    8.1 (Berkeley) 6/5/93
 .\"
-.Dd March 31, 2018
+.Dd April 10, 2018
 .Dt DMESG 8
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd "display the system message buffer"
 .Sh SYNOPSIS
 .Nm
-.Op Fl qt
+.Op Fl dtT
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Sh DESCRIPTION
@@ -46,16 +46,22 @@
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl d
+Show just the timestamp deltas.
+Used together with
+.Fl t
+only the deltas are shown.
 .It Fl M
 Extract values associated with the name list from the specified core
 instead of the default ``/dev/mem''.
 .It Fl N
 Extract the name list from the specified system instead of the default
 ``/netbsd''.
-.It Fl q
+.It Fl T
+Format uptime timestamps in a human readable form (using
+.Xr ctime 3 ).
+.It Fl t
 Quiet printing, don't print timestamps.
-.It Fl t
-Format uptime timestamps in a human readable form.
 .El
 .Pp
 The system message buffer is a circular buffer of a fixed size.
diff -r 33adfecab453 -r 61117e8d9231 sbin/dmesg/dmesg.c
--- a/sbin/dmesg/dmesg.c        Tue Apr 10 16:12:29 2018 +0000
+++ b/sbin/dmesg/dmesg.c        Tue Apr 10 22:21:52 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dmesg.c,v 1.30 2018/04/02 01:15:31 christos Exp $      */
+/*     $NetBSD: dmesg.c,v 1.31 2018/04/10 22:21:52 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.30 2018/04/02 01:15:31 christos Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.31 2018/04/10 22:21:52 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -82,31 +82,39 @@
        char tbuf[64];
        char *memf, *nlistf;
        struct timeval boottime;
-       int ptime = 0;
+       struct timespec lasttime;
+       intmax_t sec;
+       long nsec;
+       int deltas, quiet, humantime;
        
        static const int bmib[] = { CTL_KERN, KERN_BOOTTIME };
        size = sizeof(boottime);
 
        boottime.tv_sec = 0;
        boottime.tv_usec = 0;
-       ptime = 0;
+       lasttime.tv_sec = 0;
+       lasttime.tv_nsec = 0;
+       deltas = quiet = humantime = 0;
 
         (void)sysctl(bmib, 2, &boottime, &size, NULL, 0);
 
        memf = nlistf = NULL;
-       while ((ch = getopt(argc, argv, "M:N:qt")) != -1)
+       while ((ch = getopt(argc, argv, "dM:N:tT")) != -1)
                switch(ch) {
+               case 'd':
+                       deltas = 1;
+                       break;
                case 'M':
                        memf = optarg;
                        break;
                case 'N':
                        nlistf = optarg;
                        break;
-               case 'q':
-                       ptime = -1;
+               case 't':
+                       quiet = 1;
                        break;
-               case 't':
-                       ptime = 1;
+               case 'T':
+                       humantime = 1;
                        break;
                case '?':
                default:
@@ -114,6 +122,8 @@
                }
        argc -= optind;
        argv += optind;
+       if (quiet && humantime)
+               err(EXIT_FAILURE, "-t cannot be used with -T");
 
        if (memf == NULL) {
 #endif
@@ -207,23 +217,35 @@
                                ADDC('\0');
                                tstamp = 0;
 #ifndef SMALL
-                               if (ptime == 1) {
-                                       intmax_t sec;
+                               sscanf(tbuf, "[%jd.%ld]", &sec, &nsec);
+                               if (!quiet || deltas)
+                                       printf("[");
+                               if (humantime) {
                                        time_t t;
-                                       long nsec;
                                        struct tm tm;
-
-                                       sscanf(tbuf, "[%jd.%ld]", &sec, &nsec);
                                        t = boottime.tv_sec + sec;
                                        if (localtime_r(&t, &tm) != NULL) {
                                                strftime(tbuf, sizeof(tbuf),
-                                                   "[%a %b %e %H:%M:%S %Z %Y]",
+                                                   "%a %b %e %H:%M:%S %Z %Y",
                                                     &tm);
-                                               printf("%s ", tbuf);
+                                               printf("%s", tbuf);
                                        }
-                                       continue;
-                               } else if (ptime != -1)
-                                       printf("%s ", tbuf);
+                               } else if (!quiet) {
+                                       printf("% 9jd.%06ld",
+                                           sec, nsec / 1000);
+                               }
+                               if (deltas) {
+                                       struct timespec nt = { sec, nsec };
+                                       struct timespec dt;
+                                       timespecsub(&nt, &lasttime, &dt);
+                                       if (humantime || !quiet)
+                                               printf(" ");
+                                       printf("<% 4jd.%06ld>", (intmax_t)
+                                           dt.tv_sec, dt.tv_nsec / 1000);
+                                       lasttime = nt;
+                               }
+                               if (!quiet || deltas)
+                                       printf("] ");
 #endif
                                continue;
                        case ' ':



Home | Main Index | Thread Index | Old Index