From owner-svn-src-head@FreeBSD.ORG Fri May 10 03:42:49 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 65D3FDDE; Fri, 10 May 2013 03:42:49 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 3FFCE94A; Fri, 10 May 2013 03:42:49 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4A3gnUS080598; Fri, 10 May 2013 03:42:49 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4A3gmc9080595; Fri, 10 May 2013 03:42:48 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201305100342.r4A3gmc9080595@svn.freebsd.org> From: Eitan Adler Date: Fri, 10 May 2013 03:42:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r250430 - head/sbin/dmesg X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 May 2013 03:42:49 -0000 Author: eadler Date: Fri May 10 03:42:48 2013 New Revision: 250430 URL: http://svnweb.freebsd.org/changeset/base/250430 Log: Add support for 'dmesg -c' which clears the dmesg buffer after it has been printed. This provides compatibility with other *nix systems (including Linux). While here use stdbool booleans for 'all'. PR: bin/178295 Submitted by: Levent Serinol Reviewed by: will Modified: head/sbin/dmesg/dmesg.8 head/sbin/dmesg/dmesg.c Modified: head/sbin/dmesg/dmesg.8 ============================================================================== --- head/sbin/dmesg/dmesg.8 Fri May 10 03:05:44 2013 (r250429) +++ head/sbin/dmesg/dmesg.8 Fri May 10 03:42:48 2013 (r250430) @@ -36,7 +36,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 @@ -59,6 +59,8 @@ Show all data in the message buffer. 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 Modified: head/sbin/dmesg/dmesg.c ============================================================================== --- head/sbin/dmesg/dmesg.c Fri May 10 03:05:44 2013 (r250429) +++ head/sbin/dmesg/dmesg.c Fri May 10 03:42:48 2013 (r250430) @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -79,15 +80,20 @@ main(int argc, char *argv[]) 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; @@ -190,12 +196,16 @@ main(int argc, char *argv[]) (void)strvisx(visbp, p, nextp - p, 0); (void)printf("%s", visbp); } + if (clear) + if (sysctlbyname("kern.msgbuf_clear", NULL, NULL, &clear, sizeof(int))) + err(1, "sysctl kern.msgbuf_clear"); + exit(0); } 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); }