CVS commit: src/sbin/dmesg

2019-12-31 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jan  1 00:24:52 UTC 2020

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
Make recent change build for SMALL builds as well as normal ones.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 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.c
diff -u src/sbin/dmesg/dmesg.c:1.44 src/sbin/dmesg/dmesg.c:1.45
--- src/sbin/dmesg/dmesg.c:1.44	Tue Dec 31 19:58:56 2019
+++ src/sbin/dmesg/dmesg.c	Wed Jan  1 00:24:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.44 2019/12/31 19:58:56 tsutsui Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.45 2020/01/01 00:24:52 kre 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.44 2019/12/31 19:58:56 tsutsui Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.45 2020/01/01 00:24:52 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -377,8 +377,12 @@ main(int argc, char *argv[])
 continue;
 #endif
 			case ' ':
+#ifndef SMALL
 if (!tstamp && postts) {
 	postts = false;
+#else
+if (!tstamp) {
+#endif
 	continue;
 }
 /*FALLTHROUGH*/



CVS commit: src/sbin/dmesg

2019-12-31 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Tue Dec 31 19:58:56 UTC 2019

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
Fix dmesg(8) to preserve leading whitespaces of kernel messages.

Closes PR/54729.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 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.c
diff -u src/sbin/dmesg/dmesg.c:1.43 src/sbin/dmesg/dmesg.c:1.44
--- src/sbin/dmesg/dmesg.c:1.43	Tue Jun  4 11:59:05 2019
+++ src/sbin/dmesg/dmesg.c	Tue Dec 31 19:58:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.43 2019/06/04 11:59:05 kre Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.44 2019/12/31 19:58:56 tsutsui 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.43 2019/06/04 11:59:05 kre Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.44 2019/12/31 19:58:56 tsutsui Exp $");
 #endif
 #endif /* not lint */
 
@@ -157,7 +157,7 @@ main(int argc, char *argv[])
 	long nsec, fsec;
 	int scale;
 	int deltas, quiet, humantime;
-	bool frac;
+	bool frac, postts;
 
 	static const int bmib[] = { CTL_KERN, KERN_BOOTTIME };
 	size = sizeof(boottime);
@@ -262,6 +262,7 @@ main(int argc, char *argv[])
 	 */
 #ifndef SMALL
 	frac = false;
+	postts = false;
 	scale = 0;
 #endif
 	for (tstamp = 0, newl = 1, log = i = 0, p = bufdata + cur.msg_bufx;
@@ -310,6 +311,7 @@ main(int argc, char *argv[])
 ADDC(ch);
 ADDC('\0');
 tstamp = 0;
+postts = true;
 sec = fsec = 0;
 switch (sscanf(tbuf, "[%jd.%ld]", , )){
 case EOF:
@@ -375,8 +377,10 @@ main(int argc, char *argv[])
 continue;
 #endif
 			case ' ':
-if (!tstamp)
+if (!tstamp && postts) {
+	postts = false;
 	continue;
+}
 /*FALLTHROUGH*/
 			default:
 #ifndef SMALL



CVS commit: src/sbin/dmesg

2018-09-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep 20 23:46:42 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
Whitespace.  NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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.c
diff -u src/sbin/dmesg/dmesg.c:1.39 src/sbin/dmesg/dmesg.c:1.40
--- src/sbin/dmesg/dmesg.c:1.39	Thu Sep 20 19:50:42 2018
+++ src/sbin/dmesg/dmesg.c	Thu Sep 20 23:46:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.39 2018/09/20 19:50:42 kre Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.40 2018/09/20 23:46:42 kre 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.39 2018/09/20 19:50:42 kre Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.40 2018/09/20 23:46:42 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -106,7 +106,7 @@ fmtydhmsf(char *b, size_t l, intmax_t t,
 
 #define APPEND(a) \
 do if (a) \
-APPENDFMT("%jd%c", a, toupper((unsigned char)__STRING(a)[0])); \
+	APPENDFMT("%jd%c", a, toupper((unsigned char)__STRING(a)[0])); \
 while (/*CONSTCOND*/0)
 #define APPENDS(a, pr, ms) \
 APPENDFMT("%jd%s%.*ld%c", a, radix, pr, ms, \
@@ -158,7 +158,7 @@ main(int argc, char *argv[])
 	int scale;
 	int deltas, quiet, humantime;
 	bool frac;
-	
+
 	static const int bmib[] = { CTL_KERN, KERN_BOOTTIME };
 	size = sizeof(boottime);
 
@@ -173,7 +173,7 @@ main(int argc, char *argv[])
 	lasttime.tv_nsec = 0;
 	deltas = quiet = humantime = 0;
 
-(void)sysctl(bmib, 2, , , NULL, 0);
+	(void)sysctl(bmib, 2, , , NULL, 0);
 
 	memf = nlistf = NULL;
 	while ((ch = getopt(argc, argv, "dM:N:tT")) != -1)
@@ -340,7 +340,7 @@ main(int argc, char *argv[])
 	if (localtime_r(, ) != NULL) {
 		strftime(tbuf, sizeof(tbuf),
 		"%a %b %e %H:%M:%S %Z %Y",
-		 );
+		);
 		printf("%s", tbuf);
 	}
 } else if (humantime > 1) {
@@ -371,7 +371,7 @@ main(int argc, char *argv[])
 continue;
 			case ' ':
 if (!tstamp)
-	continue;	
+	continue;
 /*FALLTHROUGH*/
 			default:
 if (tstamp) {



CVS commit: src/sbin/dmesg

2018-09-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep 20 19:50:42 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
Use the locale's numeric radix character ("decimal point") more generally
(in !SMALL versions of dmesg).


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 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.c
diff -u src/sbin/dmesg/dmesg.c:1.38 src/sbin/dmesg/dmesg.c:1.39
--- src/sbin/dmesg/dmesg.c:1.38	Thu Sep 20 06:06:06 2018
+++ src/sbin/dmesg/dmesg.c	Thu Sep 20 19:50:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.38 2018/09/20 06:06:06 kre Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.39 2018/09/20 19:50:42 kre 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.38 2018/09/20 06:06:06 kre Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.39 2018/09/20 19:50:42 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -350,7 +350,7 @@ main(int argc, char *argv[])
 		printf("%s", fp);
 	}
 } else if (!quiet) {
-	printf(" %5jd.", sec);
+	printf(" %5jd%s", sec, radix);
 	pnsec(nsec, fsec, scale);
 }
 if (deltas) {
@@ -360,8 +360,9 @@ main(int argc, char *argv[])
 	timespecsub(, , );
 	if (humantime || !quiet)
 		printf(" ");
-	printf("<% 4jd.%06ld>", (intmax_t)
-	dt.tv_sec, (dt.tv_nsec+499) / 1000);
+	printf("<% 4jd%s%6.6ld>",
+	(intmax_t)dt.tv_sec, radix,
+	(dt.tv_nsec+499) / 1000);
 	lasttime = nt;
 }
 if (!quiet || deltas)



CVS commit: src/sbin/dmesg

2018-09-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep 20 10:03:31 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.8

Log Message:
s/or/of/(a common typo of mine)and  s/or//  (too many of them.)


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sbin/dmesg/dmesg.8

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.24 src/sbin/dmesg/dmesg.8:1.25
--- src/sbin/dmesg/dmesg.8:1.24	Thu Sep 20 01:11:19 2018
+++ src/sbin/dmesg/dmesg.8	Thu Sep 20 10:03:31 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dmesg.8,v 1.24 2018/09/20 01:11:19 wiz Exp $
+.\"	$NetBSD: dmesg.8,v 1.25 2018/09/20 10:03:31 kre Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -101,7 +101,7 @@ command appeared in
 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.
+even when the number of hours is in the hundreds, 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.



CVS commit: src/sbin/dmesg

2018-09-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep 20 06:06:06 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
Remove #if 0'd code that somehow got mangled in the (somewhat messy)
commit process and ended up being a syntax error...


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 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.c
diff -u src/sbin/dmesg/dmesg.c:1.37 src/sbin/dmesg/dmesg.c:1.38
--- src/sbin/dmesg/dmesg.c:1.37	Wed Sep 19 23:02:14 2018
+++ src/sbin/dmesg/dmesg.c	Thu Sep 20 06:06:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.37 2018/09/19 23:02:14 christos Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.38 2018/09/20 06:06:06 kre 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.37 2018/09/19 23:02:14 christos Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.38 2018/09/20 06:06:06 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -78,10 +78,7 @@ __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
-#if 0
-			, d, M, y
-#endif
+	intmax_t s, m, h;
 	int z;
 	int prec;
 	size_t o;
@@ -92,30 +89,7 @@ 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;
-
-	d = t % 30;
-	t /= 30;
-
-	M = t % 12;
-	t /= 12;
-
-	y = t;
-#else
 	h = t;
-#endif
 
 	z = 0;
 	o = 0;
@@ -139,11 +113,6 @@ 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);



CVS commit: src/sbin/dmesg

2018-09-19 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Sep 20 01:11:20 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.8

Log Message:
Remove a comma and some trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sbin/dmesg/dmesg.8

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.23 src/sbin/dmesg/dmesg.8:1.24
--- src/sbin/dmesg/dmesg.8:1.23	Wed Sep 19 23:02:14 2018
+++ src/sbin/dmesg/dmesg.8	Thu Sep 20 01:11:19 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dmesg.8,v 1.23 2018/09/19 23:02:14 christos Exp $
+.\"	$NetBSD: dmesg.8,v 1.24 2018/09/20 01:11:19 wiz Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -61,7 +61,7 @@ Extract the name list from the specified
 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,
+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
@@ -98,7 +98,7 @@ The
 command appeared in
 .Bx 3.0 .
 .Sh BUGS
-When 
+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.



CVS commit: src/sbin/dmesg

2018-09-19 Thread Christos Zoulas
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 
 
 #ifndef SMALL
+#include 
+#include 
+
 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]))
 

CVS commit: src/sbin/dmesg

2018-09-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Sep 19 22:58:03 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
Allow a third use of -T to force .NNN (always three digits) in -TT
(ISO8601 durations) format for timestamps - that is,not dropping trailing 0's.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.c
diff -u src/sbin/dmesg/dmesg.c:1.35 src/sbin/dmesg/dmesg.c:1.36
--- src/sbin/dmesg/dmesg.c:1.35	Wed Sep 19 22:55:12 2018
+++ src/sbin/dmesg/dmesg.c	Wed Sep 19 22:58:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.35 2018/09/19 22:55:12 kre Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.36 2018/09/19 22:58:03 kre 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.35 2018/09/19 22:55:12 kre Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.36 2018/09/19 22:58:03 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -71,7 +71,7 @@ __dead static void	usage(void);
 	kvm_read(kd, addr, , sizeof(var)) != sizeof(var)
 
 static const char *
-fmtydhmsf(char *b, size_t l, intmax_t t, long nsec)
+fmtydhmsf(char *b, size_t l, intmax_t t, long nsec, int ht)
 {
 	intmax_t s, m, h, d, M, y;
 	int z;
@@ -126,9 +126,11 @@ fmtydhmsf(char *b, size_t l, intmax_t t,
 	if (nsec)
 		nsec = (nsec + 50) / 100;	/* now milliseconds */
 	prec = 3;
-	while (prec > 0 && (nsec % 10) == 0)
-		--prec, nsec /= 10;
-	if (nsec)
+	if (nsec && ht == 2) {
+		while (prec > 0 && (nsec % 10) == 0)
+			--prec, nsec /= 10;
+	}
+	if (nsec || ht > 2)
 		APPENDS(s, prec, nsec);
 	else
 		APPEND(s);
@@ -345,7 +347,7 @@ main(int argc, char *argv[])
 	}
 } else if (humantime > 1) {
 	const char *fp = fmtydhmsf(tbuf,
-	sizeof(tbuf), sec, fsec);
+	sizeof(tbuf), sec, fsec, humantime);
 	if (fp) {
 		printf("%s", fp);
 	}



CVS commit: src/sbin/dmesg

2018-09-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Sep 19 22:55:12 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
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).


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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.c
diff -u src/sbin/dmesg/dmesg.c:1.34 src/sbin/dmesg/dmesg.c:1.35
--- src/sbin/dmesg/dmesg.c:1.34	Wed Sep 19 00:15:05 2018
+++ src/sbin/dmesg/dmesg.c	Wed Sep 19 22:55:12 2018
@@ -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 @@ __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.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 @@ __dead static void	usage(void);
 	kvm_read(kd, addr, , 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 @@ fmtydhmsf(char *b, size_t l, time_t t, l
 
 #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 @@ fmtydhmsf(char *b, size_t l, time_t t, l
 	APPEND(h);
 	APPEND(m);
 	if (nsec)
-		nsec = nsec / 100;
+		nsec = (nsec + 50) / 100;	/* 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;



CVS commit: src/sbin/dmesg

2018-09-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 19 00:15:05 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.8 dmesg.c

Log Message:
add -TT printing ISO 8601 duration


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sbin/dmesg/dmesg.8
cvs rdiff -u -r1.33 -r1.34 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.21 src/sbin/dmesg/dmesg.8:1.22
--- src/sbin/dmesg/dmesg.8:1.21	Fri Apr 13 21:34:47 2018
+++ src/sbin/dmesg/dmesg.8	Tue Sep 18 20:15:05 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dmesg.8,v 1.21 2018/04/14 01:34:47 kre Exp $
+.\"	$NetBSD: dmesg.8,v 1.22 2018/09/19 00:15:05 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 April 10, 2018
+.Dd September 18, 2018
 .Dt DMESG 8
 .Os
 .Sh NAME
@@ -58,8 +58,9 @@ 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
+Format uptime timestamps in a human readable form.  (using
 .Xr ctime 3 ) .
+Repeating this option, prints the uptime in ISO 8601 duration form.
 .It Fl t
 Quiet printing, don't print timestamps.
 .El

Index: src/sbin/dmesg/dmesg.c
diff -u src/sbin/dmesg/dmesg.c:1.33 src/sbin/dmesg/dmesg.c:1.34
--- src/sbin/dmesg/dmesg.c:1.33	Fri Apr 13 21:37:34 2018
+++ src/sbin/dmesg/dmesg.c	Tue Sep 18 20:15:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.33 2018/04/14 01:37:34 kre Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.34 2018/09/19 00:15:05 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.33 2018/04/14 01:37:34 kre Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.34 2018/09/19 00:15:05 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -47,6 +47,7 @@ __RCSID("$NetBSD: dmesg.c,v 1.33 2018/04
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -68,6 +69,76 @@ __dead static void	usage(void);
 
 #define	KREAD(addr, var) \
 	kvm_read(kd, addr, , sizeof(var)) != sizeof(var)
+
+static const char *
+fmtydhmsf(char *b, size_t l, time_t t, long nsec)
+{
+	time_t s, m, h, d, M, y;
+	int z;
+	size_t o;
+
+	s = t % 60;
+	t /= 60;
+
+	m = t % 60;
+	t /= 60;
+
+	h = t % 24;
+	t /= 24;
+
+	d = t % 30;
+	t /= 30;
+
+	M = t % 12;
+	t /= 12;
+
+	y = t;
+
+	z = 0;
+	o = 0;
+
+#define APPENDFMT(fmt, ...)  \
+do { \
+	z = snprintf(b + o, l - o, fmt, __VA_ARGS__); \
+	if (z == -1) \
+		return b; \
+	o += (size_t)z; \
+	if (o >= l) \
+		return b; \
+} while (/*CONSTCOND*/0)
+
+#define APPEND(a) \
+do if (a) \
+APPENDFMT("%jd%c", (intmax_t)a, toupper((unsigned char)__STRING(a)[0])); \
+while (/*CONSTCOND*/0)
+#define APPENDS(a, s) \
+APPENDFMT("%jd.%ld%c", (intmax_t)a, s, \
+	toupper((unsigned char)__STRING(a)[0]))
+
+	APPENDFMT("%s", "P");
+	APPEND(y);
+	APPEND(M);
+	APPEND(d);
+	APPENDFMT("%s", "T");
+	APPEND(h);
+	APPEND(m);
+	if (nsec)
+		nsec = nsec / 100;
+	if (nsec)
+		APPENDS(s, nsec);
+	else
+		APPEND(s);
+	return b;
+}
+
+static void
+pnsec(long nsec, long fsec, int scale)
+{
+	if (scale > 6)
+		printf("%6.6ld", (nsec + 499) / 1000);
+	else
+		printf("%*.*ld%.*s", scale, scale, fsec, 6 - scale, "00");
+}
 #endif
 
 int
@@ -116,7 +187,7 @@ main(int argc, char *argv[])
 			quiet = 1;
 			break;
 		case 'T':
-			humantime = 1;
+			humantime++;
 			break;
 		case '?':
 		default:
@@ -257,7 +328,7 @@ main(int argc, char *argv[])
 	nsec *= 10;
 if (!quiet || deltas)
 	printf("[");
-if (humantime) {
+if (humantime == 1) {
 	time_t t;
 	struct tm tm;
 
@@ -268,14 +339,15 @@ main(int argc, char *argv[])
 		 );
 		printf("%s", tbuf);
 	}
+} else if (humantime > 1) {
+	const char *fp = fmtydhmsf(tbuf,
+	sizeof(tbuf), sec, fsec);
+	if (fp) {
+		printf("%s", fp);
+	}
 } else if (!quiet) {
-	if (scale > 6)
-		printf("% 5jd.%6.6ld",
-		sec, (nsec + 499) / 1000);
-	else
-		printf("% 5jd.%*.*ld%.*s",
-		sec, scale, scale, fsec,
-		6 - scale, "00");
+	printf(" %5jd.", sec);
+	pnsec(nsec, fsec, scale);
 }
 if (deltas) {
 	struct timespec nt = { sec, nsec };



CVS commit: src/sbin/dmesg

2018-04-13 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Apr 14 01:37:34 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
Make timestamp reading code adapt to whatever precision (up to
nanoseconds, 9 digits) the kernel happens to send in the timestamps
in log messages.

Output (numeric) timestamps (when produced) are unchanged and always
in microseconds (for now).


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 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.c
diff -u src/sbin/dmesg/dmesg.c:1.32 src/sbin/dmesg/dmesg.c:1.33
--- src/sbin/dmesg/dmesg.c:1.32	Wed Apr 11 06:41:23 2018
+++ src/sbin/dmesg/dmesg.c	Sat Apr 14 01:37:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.32 2018/04/11 06:41:23 wiz Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.33 2018/04/14 01:37:34 kre 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.32 2018/04/11 06:41:23 wiz Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.33 2018/04/14 01:37:34 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -84,8 +84,10 @@ main(int argc, char *argv[])
 	struct timeval boottime;
 	struct timespec lasttime;
 	intmax_t sec;
-	long nsec;
+	long nsec, fsec;
+	int scale;
 	int deltas, quiet, humantime;
+	bool frac;
 	
 	static const int bmib[] = { CTL_KERN, KERN_BOOTTIME };
 	size = sizeof(boottime);
@@ -183,16 +185,23 @@ main(int argc, char *argv[])
 	 * over cur.msg_bufs times.  Unused area is skipped since it
 	 * contains nul.
 	 */
+#ifndef SMALL
+	frac = false;
+	scale = 0;
+#endif
 	for (tstamp = 0, newl = 1, log = i = 0, p = bufdata + cur.msg_bufx;
 	i < cur.msg_bufs; i++, p++) {
+
 #ifndef SMALL
 		if (p == bufdata + cur.msg_bufs)
 			p = bufdata;
 #define ADDC(c)\
-do 	\
+do {\
 	if (tstamp < sizeof(tbuf) - 1)	\
 		tbuf[tstamp++] = (c);	\
-while (/*CONSTCOND*/0)
+	if (frac)			\
+		scale++;		\
+} while (/*CONSTCOND*/0)
 #else
 #define ADDC(c)
 #endif
@@ -202,8 +211,16 @@ main(int argc, char *argv[])
 		/* Skip "\n<.*>" syslog sequences. */
 		/* Gather timestamp sequences */
 		if (newl) {
+#ifndef SMALL
+			int j;
+#endif
+
 			switch (ch) {
 			case '[':
+#ifndef SMALL
+frac = false;
+scale = 0;
+#endif
 ADDC(ch);
 continue;
 			case '<':
@@ -213,16 +230,37 @@ main(int argc, char *argv[])
 log = 0;
 continue;
 			case ']':
+#ifndef SMALL
+frac = false;
+#endif
 ADDC(ch);
 ADDC('\0');
 tstamp = 0;
 #ifndef SMALL
-sscanf(tbuf, "[%jd.%ld]", , );
+sec = fsec = 0;
+switch (sscanf(tbuf, "[%jd.%ld]", , )){
+case EOF:
+case 0:
+	/*???*/
+	continue;
+case 1:
+	fsec = 0;
+	break;
+case 2:
+	break;
+default:
+	/* Help */
+	continue;
+}
+
+for (nsec = fsec, j = 9 - scale; --j >= 0; )
+	nsec *= 10;
 if (!quiet || deltas)
 	printf("[");
 if (humantime) {
 	time_t t;
 	struct tm tm;
+
 	t = boottime.tv_sec + sec;
 	if (localtime_r(, ) != NULL) {
 		strftime(tbuf, sizeof(tbuf),
@@ -231,17 +269,23 @@ main(int argc, char *argv[])
 		printf("%s", tbuf);
 	}
 } else if (!quiet) {
-	printf("% 9jd.%06ld",
-	sec, nsec / 1000);
+	if (scale > 6)
+		printf("% 5jd.%6.6ld",
+		sec, (nsec + 499) / 1000);
+	else
+		printf("% 5jd.%*.*ld%.*s",
+		sec, scale, scale, fsec,
+		6 - scale, "00");
 }
 if (deltas) {
 	struct timespec nt = { sec, nsec };
 	struct timespec dt;
+
 	timespecsub(, , );
 	if (humantime || !quiet)
 		printf(" ");
 	printf("<% 4jd.%06ld>", (intmax_t)
-	dt.tv_sec, dt.tv_nsec / 1000);
+	dt.tv_sec, (dt.tv_nsec+499) / 1000);
 	lasttime = nt;
 }
 if (!quiet || deltas)
@@ -255,6 +299,10 @@ main(int argc, char *argv[])
 			default:
 if (tstamp) {
 ADDC(ch);
+#ifndef SMALL
+if (ch == '.')
+	frac = true;
+#endif
 continue;
 }
 if (log)



CVS commit: src/sbin/dmesg

2018-04-13 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Apr 14 01:34:47 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.8

Log Message:
Minor wording change (no date bump needed.)


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sbin/dmesg/dmesg.8

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.20 src/sbin/dmesg/dmesg.8:1.21
--- src/sbin/dmesg/dmesg.8:1.20	Wed Apr 11 06:40:53 2018
+++ src/sbin/dmesg/dmesg.8	Sat Apr 14 01:34:47 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dmesg.8,v 1.20 2018/04/11 06:40:53 wiz Exp $
+.\"	$NetBSD: dmesg.8,v 1.21 2018/04/14 01:34:47 kre Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -47,7 +47,7 @@ displays the contents of the system mess
 The options are as follows:
 .Bl -tag -width Ds
 .It Fl d
-Show just the timestamp deltas.
+Show the timestamp deltas.
 Used together with
 .Fl t
 only the deltas are shown.



CVS commit: src/sbin/dmesg

2018-04-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Apr 11 06:41:23 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
Update usage.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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.c
diff -u src/sbin/dmesg/dmesg.c:1.31 src/sbin/dmesg/dmesg.c:1.32
--- src/sbin/dmesg/dmesg.c:1.31	Tue Apr 10 22:21:52 2018
+++ src/sbin/dmesg/dmesg.c	Wed Apr 11 06:41:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.31 2018/04/10 22:21:52 christos Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.32 2018/04/11 06:41:23 wiz 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.31 2018/04/10 22:21:52 christos Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.32 2018/04/11 06:41:23 wiz Exp $");
 #endif
 #endif /* not lint */
 
@@ -282,7 +282,7 @@ static void
 usage(void)
 {
 
-	(void)fprintf(stderr, "Usage: %s [-qt] [-M core] [-N system]\n",
+	(void)fprintf(stderr, "Usage: %s [-dTt] [-M core] [-N system]\n",
 		getprogname());
 	exit(EXIT_FAILURE);
 }



CVS commit: src/sbin/dmesg

2018-04-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Apr 11 06:40:53 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.8

Log Message:
Sort flags in SYNOPSIS.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sbin/dmesg/dmesg.8

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.19 src/sbin/dmesg/dmesg.8:1.20
--- src/sbin/dmesg/dmesg.8:1.19	Tue Apr 10 22:21:52 2018
+++ src/sbin/dmesg/dmesg.8	Wed Apr 11 06:40:53 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dmesg.8,v 1.19 2018/04/10 22:21:52 christos Exp $
+.\"	$NetBSD: dmesg.8,v 1.20 2018/04/11 06:40:53 wiz Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -34,10 +34,10 @@
 .Os
 .Sh NAME
 .Nm dmesg
-.Nd "display the system message buffer"
+.Nd display the system message buffer
 .Sh SYNOPSIS
 .Nm
-.Op Fl dtT
+.Op Fl dTt
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Sh DESCRIPTION
@@ -59,7 +59,7 @@ Extract the name list from the specified
 ``/netbsd''.
 .It Fl T
 Format uptime timestamps in a human readable form (using
-.Xr ctime 3 ).
+.Xr ctime 3 ) .
 .It Fl t
 Quiet printing, don't print timestamps.
 .El



CVS commit: src/sbin/dmesg

2018-04-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 10 22:21:52 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.8 dmesg.c

Log Message:
match the linux dmesg flags.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sbin/dmesg/dmesg.8
cvs rdiff -u -r1.30 -r1.31 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.18 src/sbin/dmesg/dmesg.8:1.19
--- src/sbin/dmesg/dmesg.8:1.18	Sun Apr  1 15:31:16 2018
+++ src/sbin/dmesg/dmesg.8	Tue Apr 10 18:21:52 2018
@@ -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 @@ displays the contents of the system mess
 .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
-Quiet printing, don't print timestamps.
+.It Fl T
+Format uptime timestamps in a human readable form (using
+.Xr ctime 3 ).
 .It Fl t
-Format uptime timestamps in a human readable form.
+Quiet printing, don't print timestamps.
 .El
 .Pp
 The system message buffer is a circular buffer of a fixed size.

Index: src/sbin/dmesg/dmesg.c
diff -u src/sbin/dmesg/dmesg.c:1.30 src/sbin/dmesg/dmesg.c:1.31
--- src/sbin/dmesg/dmesg.c:1.30	Sun Apr  1 21:15:31 2018
+++ src/sbin/dmesg/dmesg.c	Tue Apr 10 18:21:52 2018
@@ -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 @@ __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.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 @@ main(int argc, char *argv[])
 	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, , , 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;
-			break;
 		case 't':
-			ptime = 1;
+			quiet = 1;
+			break;
+		case 'T':
+			humantime = 1;
 			break;
 		case '?':
 		default:
@@ -114,6 +122,8 @@ main(int argc, char *argv[])
 		}
 	argc -= optind;
 	argv += optind;
+	if (quiet && humantime)
+		err(EXIT_FAILURE, "-t cannot be used with -T");
 
 	if (memf == NULL) {
 #endif
@@ -207,23 +217,35 @@ main(int argc, char *argv[])
 ADDC('\0');
 tstamp = 0;
 #ifndef SMALL
-if (ptime == 1) {
-	intmax_t sec;
+sscanf(tbuf, "[%jd.%ld]", , );
+if (!quiet || deltas)
+	printf("[");
+if (humantime) {
 	time_t t;
-	long nsec;
 	struct tm tm;
-
-	sscanf(tbuf, "[%jd.%ld]", , );
 	t = boottime.tv_sec + sec;
 	if (localtime_r(, ) != NULL) {
 		strftime(tbuf, sizeof(tbuf),
-		"[%a %b %e %H:%M:%S %Z %Y]",
+		"%a %b %e %H:%M:%S %Z %Y",
 		 );
-		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(, , );
+	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 ' ':



CVS commit: src/sbin/dmesg

2018-04-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr  2 01:15:32 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
eat NUL's first so that the state machine is not altered by them.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.c
diff -u src/sbin/dmesg/dmesg.c:1.29 src/sbin/dmesg/dmesg.c:1.30
--- src/sbin/dmesg/dmesg.c:1.29	Sun Apr  1 15:36:13 2018
+++ src/sbin/dmesg/dmesg.c	Sun Apr  1 21:15:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.29 2018/04/01 19:36:13 christos Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.30 2018/04/02 01:15:31 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.29 2018/04/01 19:36:13 christos Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.30 2018/04/02 01:15:31 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -187,6 +187,8 @@ main(int argc, char *argv[])
 #define ADDC(c)
 #endif
 		ch = *p;
+		if (ch == '\0')
+			continue;
 		/* Skip "\n<.*>" syslog sequences. */
 		/* Gather timestamp sequences */
 		if (newl) {
@@ -239,8 +241,6 @@ main(int argc, char *argv[])
 			}
 			newl = 0;
 		}
-		if (ch == '\0')
-			continue;
 		newl = ch == '\n';
 		(void)vis(buf, ch, VIS_NOSLASH, 0);
 #ifndef SMALL



CVS commit: src/sbin/dmesg

2018-04-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr  1 19:36:13 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.c

Log Message:
handle log being before timestamp...


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 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.c
diff -u src/sbin/dmesg/dmesg.c:1.28 src/sbin/dmesg/dmesg.c:1.29
--- src/sbin/dmesg/dmesg.c:1.28	Sun Apr  1 15:31:16 2018
+++ src/sbin/dmesg/dmesg.c	Sun Apr  1 15:36:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.28 2018/04/01 19:31:16 christos Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.29 2018/04/01 19:36:13 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.28 2018/04/01 19:31:16 christos Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.29 2018/04/01 19:36:13 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -198,7 +198,7 @@ main(int argc, char *argv[])
 log = 1;
 continue;
 			case '>':
-log = newl = 0;
+log = 0;
 continue;
 			case ']':
 ADDC(ch);
@@ -237,6 +237,7 @@ main(int argc, char *argv[])
 	continue;
 break;
 			}
+			newl = 0;
 		}
 		if (ch == '\0')
 			continue;



CVS commit: src/sbin/dmesg

2018-04-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr  1 19:31:16 UTC 2018

Modified Files:
src/sbin/dmesg: dmesg.8 dmesg.c

Log Message:
Handle new timestamp sequences.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sbin/dmesg/dmesg.8
cvs rdiff -u -r1.27 -r1.28 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.17 src/sbin/dmesg/dmesg.8:1.18
--- src/sbin/dmesg/dmesg.8:1.17	Sat Sep 10 22:24:00 2016
+++ src/sbin/dmesg/dmesg.8	Sun Apr  1 15:31:16 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dmesg.8,v 1.17 2016/09/11 02:24:00 sevan Exp $
+.\"	$NetBSD: dmesg.8,v 1.18 2018/04/01 19:31:16 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 September 11, 2016
+.Dd March 31, 2018
 .Dt DMESG 8
 .Os
 .Sh NAME
@@ -37,6 +37,7 @@
 .Nd "display the system message buffer"
 .Sh SYNOPSIS
 .Nm
+.Op Fl qt
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Sh DESCRIPTION
@@ -51,6 +52,10 @@ 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
+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.

Index: src/sbin/dmesg/dmesg.c
diff -u src/sbin/dmesg/dmesg.c:1.27 src/sbin/dmesg/dmesg.c:1.28
--- src/sbin/dmesg/dmesg.c:1.27	Mon Aug 29 10:34:59 2011
+++ src/sbin/dmesg/dmesg.c	Sun Apr  1 15:31:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.27 2011/08/29 14:34:59 joerg Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.28 2018/04/01 19:31:16 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.27 2011/08/29 14:34:59 joerg Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.28 2018/04/01 19:31:16 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -48,6 +48,7 @@ __RCSID("$NetBSD: dmesg.c,v 1.27 2011/08
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -73,16 +74,27 @@ int
 main(int argc, char *argv[])
 {
 	struct kern_msgbuf cur;
-	int ch, newl, skip, i;
+	int ch, newl, log, i;
+	size_t tstamp, size;
 	char *p, *bufdata;
+	char buf[5];
 #ifndef SMALL
+	char tbuf[64];
 	char *memf, *nlistf;
-#endif
-	char buf[5];
+	struct timeval boottime;
+	int ptime = 0;
+	
+	static const int bmib[] = { CTL_KERN, KERN_BOOTTIME };
+	size = sizeof(boottime);
+
+	boottime.tv_sec = 0;
+	boottime.tv_usec = 0;
+	ptime = 0;
+
+(void)sysctl(bmib, 2, , , NULL, 0);
 
-#ifndef SMALL
 	memf = nlistf = NULL;
-	while ((ch = getopt(argc, argv, "M:N:")) != -1)
+	while ((ch = getopt(argc, argv, "M:N:qt")) != -1)
 		switch(ch) {
 		case 'M':
 			memf = optarg;
@@ -90,6 +102,12 @@ main(int argc, char *argv[])
 		case 'N':
 			nlistf = optarg;
 			break;
+		case 'q':
+			ptime = -1;
+			break;
+		case 't':
+			ptime = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -99,15 +117,11 @@ main(int argc, char *argv[])
 
 	if (memf == NULL) {
 #endif
-		size_t size;
-		int mib[2];
+		static const int mmib[2] = { CTL_KERN, KERN_MSGBUF };
 
-		mib[0] = CTL_KERN;
-		mib[1] = KERN_MSGBUF;
-
-		if (sysctl(mib, 2, NULL, , NULL, 0) == -1 ||
+		if (sysctl(mmib, 2, NULL, , NULL, 0) == -1 ||
 		(bufdata = malloc(size)) == NULL ||
-		sysctl(mib, 2, bufdata, , NULL, 0) == -1)
+		sysctl(mmib, 2, bufdata, , NULL, 0) == -1)
 			err(1, "can't get msgbuf");
 
 		/* make a dummy struct msgbuf for the display logic */
@@ -159,22 +173,70 @@ main(int argc, char *argv[])
 	 * over cur.msg_bufs times.  Unused area is skipped since it
 	 * contains nul.
 	 */
-	for (newl = skip = i = 0, p = bufdata + cur.msg_bufx;
+	for (tstamp = 0, newl = 1, log = i = 0, p = bufdata + cur.msg_bufx;
 	i < cur.msg_bufs; i++, p++) {
 #ifndef SMALL
 		if (p == bufdata + cur.msg_bufs)
 			p = bufdata;
+#define ADDC(c)\
+do 	\
+	if (tstamp < sizeof(tbuf) - 1)	\
+		tbuf[tstamp++] = (c);	\
+while (/*CONSTCOND*/0)
+#else
+#define ADDC(c)
 #endif
 		ch = *p;
 		/* Skip "\n<.*>" syslog sequences. */
-		if (skip) {
-			if (ch == '>')
-newl = skip = 0;
-			continue;
-		}
-		if (newl && ch == '<') {
-			skip = 1;
-			continue;
+		/* Gather timestamp sequences */
+		if (newl) {
+			switch (ch) {
+			case '[':
+ADDC(ch);
+continue;
+			case '<':
+log = 1;
+continue;
+			case '>':
+log = newl = 0;
+continue;
+			case ']':
+ADDC(ch);
+ADDC('\0');
+tstamp = 0;
+#ifndef SMALL
+if (ptime == 1) {
+	intmax_t sec;
+	time_t t;
+	long nsec;
+	struct tm tm;
+
+	

CVS commit: src/sbin/dmesg

2016-09-10 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Sun Sep 11 02:24:01 UTC 2016

Modified Files:
src/sbin/dmesg: dmesg.8

Log Message:
dmesg first appeared in 3BSD
http://minnie.tuhs.org/cgi-bin/utree.pl?file=3BSD/usr/src/cmd/dmesg.c
Bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sbin/dmesg/dmesg.8

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.16 src/sbin/dmesg/dmesg.8:1.17
--- src/sbin/dmesg/dmesg.8:1.16	Fri Apr 30 16:11:03 2004
+++ src/sbin/dmesg/dmesg.8	Sun Sep 11 02:24:00 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dmesg.8,v 1.16 2004/04/30 16:11:03 wiz Exp $
+.\"	$NetBSD: dmesg.8,v 1.17 2016/09/11 02:24:00 sevan 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 April 30, 2004
+.Dd September 11, 2016
 .Dt DMESG 8
 .Os
 .Sh NAME
@@ -78,4 +78,4 @@ copy of dmesg at the time of last boot.
 The
 .Nm
 command appeared in
-.Bx 4.0 .
+.Bx 3.0 .