[Midnightbsd-cvs] src [11230] trunk/sbin/dmesg/dmesg.c: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jul 1 17:11:10 EDT 2018


Revision: 11230
          http://svnweb.midnightbsd.org/src/?rev=11230
Author:   laffer1
Date:     2018-07-01 17:11:09 -0400 (Sun, 01 Jul 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/sbin/dmesg/Makefile
    trunk/sbin/dmesg/dmesg.8
    trunk/sbin/dmesg/dmesg.c

Property Changed:
----------------
    trunk/sbin/dmesg/dmesg.8

Modified: trunk/sbin/dmesg/Makefile
===================================================================
--- trunk/sbin/dmesg/Makefile	2018-07-01 21:10:15 UTC (rev 11229)
+++ trunk/sbin/dmesg/Makefile	2018-07-01 21:11:09 UTC (rev 11230)
@@ -1,6 +1,6 @@
+# $MidnightBSD$
 #	@(#)Makefile	8.1 (Berkeley) 6/5/93
-# $FreeBSD: src/sbin/dmesg/Makefile,v 1.8 2005/01/17 13:56:46 delphij Exp $
-# $MidnightBSD: src/sbin/dmesg/Makefile,v 1.2 2008/11/21 14:49:02 laffer1 Exp $
+# $FreeBSD: stable/10/sbin/dmesg/Makefile 198236 2009-10-19 16:00:24Z ru $
 
 PROG=	dmesg
 MAN=	dmesg.8

Modified: trunk/sbin/dmesg/dmesg.8
===================================================================
--- trunk/sbin/dmesg/dmesg.8	2018-07-01 21:10:15 UTC (rev 11229)
+++ trunk/sbin/dmesg/dmesg.8	2018-07-01 21:11:09 UTC (rev 11230)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -26,10 +27,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)dmesg.8	8.1 (Berkeley) 6/5/93
-.\" $FreeBSD: src/sbin/dmesg/dmesg.8,v 1.19 2004/04/09 19:58:26 markm Exp $
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/dmesg/dmesg.8 306880 2016-10-08 21:19:44Z sevan $
 .\"
-.Dd June 5, 1993
+.Dd October 3, 2016
 .Dt DMESG 8
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd "display the system message buffer"
 .Sh SYNOPSIS
 .Nm
-.Op Fl a
+.Op Fl ac
 .Op Fl M Ar core Op Fl N Ar system
 .Sh DESCRIPTION
 The
@@ -60,6 +60,8 @@
 This includes any syslog records and
 .Pa /dev/console
 output.
+.It Fl c
+Clear the kernel buffer after printing.
 .It Fl M
 Extract values associated with the name list from the specified core.
 .It Fl N
@@ -83,4 +85,4 @@
 The
 .Nm
 utility appeared in
-.Bx 4.0 .
+.Bx 3 .


Property changes on: trunk/sbin/dmesg/dmesg.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/dmesg/dmesg.c
===================================================================
--- trunk/sbin/dmesg/dmesg.c	2018-07-01 21:10:15 UTC (rev 11229)
+++ trunk/sbin/dmesg/dmesg.c	2018-07-01 21:11:09 UTC (rev 11230)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -39,7 +40,7 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/sbin/dmesg/dmesg.c,v 1.3 2008/11/21 14:49:02 laffer1 Exp $");
+__FBSDID("$FreeBSD: stable/10/sbin/dmesg/dmesg.c 288498 2015-10-02 14:24:39Z vangyzen $");
 
 #include <sys/types.h>
 #include <sys/msgbuf.h>
@@ -54,6 +55,7 @@
 #include <locale.h>
 #include <nlist.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -60,11 +62,9 @@
 #include <vis.h>
 #include <sys/syslog.h>
 
-char s_msgbufp[] = "_msgbufp";
-
-struct nlist nl[] = {
+static struct nlist nl[] = {
 #define	X_MSGBUF	0
-	{ s_msgbufp, 0, 0, 0, 0 },
+	{ "_msgbufp", 0, 0, 0, 0 },
 	{ NULL, 0, 0, 0, 0 },
 };
 
@@ -81,16 +81,21 @@
 	kvm_t *kd;
 	size_t buflen, bufpos;
 	long pri;
-	int all, ch;
+	int ch, clear;
+	bool all;
 
-	all = 0;
+	all = false;
+	clear = false;
 	(void) setlocale(LC_CTYPE, "");
 	memf = nlistf = NULL;
-	while ((ch = getopt(argc, argv, "aM:N:")) != -1)
+	while ((ch = getopt(argc, argv, "acM:N:")) != -1)
 		switch(ch) {
 		case 'a':
-			all++;
+			all = true;
 			break;
+		case 'c':
+			clear = true;
+			break;
 		case 'M':
 			memf = optarg;
 			break;
@@ -112,10 +117,16 @@
 		 */
 		if (sysctlbyname("kern.msgbuf", NULL, &buflen, NULL, 0) == -1)
 			err(1, "sysctl kern.msgbuf");
+		/* Allocate extra room for growth between the sysctl calls. */
+		buflen += buflen/8;
+		/* Allocate more than sysctl sees, for room to append \n\0. */
 		if ((bp = malloc(buflen + 2)) == NULL)
 			errx(1, "malloc failed");
 		if (sysctlbyname("kern.msgbuf", bp, &buflen, NULL, 0) == -1)
 			err(1, "sysctl kern.msgbuf");
+		if (clear)
+			if (sysctlbyname("kern.msgbuf_clear", NULL, NULL, &clear, sizeof(int)))
+				err(1, "sysctl kern.msgbuf_clear");
 	} else {
 		/* Read in kernel message buffer and do sanity checks. */
 		kd = kvm_open(nlistf, memf, NULL, O_RDONLY, "dmesg");
@@ -198,6 +209,6 @@
 void
 usage(void)
 {
-	(void)fprintf(stderr, "usage: dmesg [-a] [-M core [-N system]]\n");
+	fprintf(stderr, "usage: dmesg [-ac] [-M core [-N system]]\n");
 	exit(1);
 }



More information about the Midnightbsd-cvs mailing list