From nobody@FreeBSD.org  Thu May  2 09:23:25 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 4B5DC95F
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  2 May 2013 09:23:25 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [69.147.83.34])
	by mx1.freebsd.org (Postfix) with ESMTP id 2317F1052
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  2 May 2013 09:23:25 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r429NOLr061918
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 2 May 2013 09:23:24 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r429NOGw061917;
	Thu, 2 May 2013 09:23:24 GMT
	(envelope-from nobody)
Message-Id: <201305020923.r429NOGw061917@red.freebsd.org>
Date: Thu, 2 May 2013 09:23:24 GMT
From: Levent Serinol <lserinol@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: small change to dmesg utility
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         178295
>Category:       bin
>Synopsis:       [patch] small change to dmesg(8) utility to add -c flag
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 02 09:30:00 UTC 2013
>Closed-Date:    Tue Jun 25 19:40:26 UTC 2013
>Last-Modified:  Tue Jun 25 19:40:26 UTC 2013
>Originator:     Levent Serinol
>Release:        9 and 10
>Organization:
Mynet
>Environment:
FreeBSD webmail105.mynet.com 10.0-CURRENT FreeBSD 10.0-CURRENT #5: Thu Mar 14 20:28:24 EET 2013     root@xxx.com:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
I would like to submit a small patch for dmesg system utility which
implements "-c" parameter like the other *nix systems support to clear
current kernel message buffer instead of using "sysctl kern.msgbuf_clear=1"
command for easier administration usage and similarity between other
unix systems.

Here i wrote an article about this issue sometime ago.

http://lserinol.blogspot.com/2012/02/linux-like-dmesg-in-freebsd.html
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

*** dmesg.c.org	Tue Jan  3 19:04:44 2012
--- dmesg.c	Mon Mar 12 15:48:34 2012
***************
*** 82,95 ****
  	size_t buflen, bufpos;
  	long pri;
! 	int all, ch;
  
  	all = 0;
  	(void) setlocale(LC_CTYPE, "");
  	memf = nlistf = NULL;
! 	while ((ch = getopt(argc, argv, "aM:N:")) != -1)
  		switch(ch) {
  		case 'a':
  			all++;
  			break;
  		case 'M':
  			memf = optarg;
--- 82,99 ----
  	size_t buflen, bufpos;
  	long pri;
! 	int all, ch, clear;
  
  	all = 0;
+ 	clear = 0;
  	(void) setlocale(LC_CTYPE, "");
  	memf = nlistf = NULL;
! 	while ((ch = getopt(argc, argv, "acM:N:")) != -1)
  		switch(ch) {
  		case 'a':
  			all++;
  			break;
+ 		case 'c':
+ 			clear++;
+ 			break;
  		case 'M':
  			memf = optarg;
***************
*** 192,195 ****
--- 196,202 ----
  		(void)strvisx(visbp, p, nextp - p, 0);
  		(void)printf("%s", visbp);
+ 		if (clear)
+ 			if (sysctlbyname("kern.msgbuf_clear", NULL, NULL, &clear, sizeof(int)) == -1)
+ 				err(1, "sysctl kern.msgbuf_clear");
  	}
  	exit(0);
***************
*** 199,203 ****
  usage(void)
  {
! 	(void)fprintf(stderr, "usage: dmesg [-a] [-M core [-N system]]\n");
  	exit(1);
  }
--- 206,210 ----
  usage(void)
  {
! 	(void)fprintf(stderr, "usage: dmesg [-a] [-c] [-M core [-N system]]\n");
  	exit(1);
  }


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Fri May 10 02:51:58 UTC 2013 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=178295 
State-Changed-From-To: open->patched 
State-Changed-By: eadler 
State-Changed-When: Fri May 10 03:43:04 UTC 2013 
State-Changed-Why:  
committed r250427 


http://www.freebsd.org/cgi/query-pr.cgi?pr=178295 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/178295: commit references a PR
Date: Fri, 10 May 2013 03:43:01 +0000 (UTC)

 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 <lserinol@gmail.com>
   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 <locale.h>
  #include <nlist.h>
  #include <stdio.h>
 +#include <stdbool.h>
  #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
 @@ -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);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Tue Jun 25 19:40:26 UTC 2013 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=178295 
>Unformatted:
