Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Jun 2013 17:46:33 +0000 (UTC)
From:      Florian Smeets <flo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r251618 - head/sbin/dmesg
Message-ID:  <201306111746.r5BHkX5u028422@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: flo (ports committer)
Date: Tue Jun 11 17:46:32 2013
New Revision: 251618
URL: http://svnweb.freebsd.org/changeset/base/251618

Log:
  Move the check whether the clear flag is set. This has 2 advantages
  
  - When operating on a core file (-M) and -c is specified we don't clear
    the message buffer of the running system.
  - If we don't have permission to clear the buffer print the error message
    only. That's what Linux does in this case, where this feature was ported
    from, and it ensures that the error message doesn't get lost in the noise.
  
  Discussed with:	antoine, cognet
  Approved by:	cognet

Modified:
  head/sbin/dmesg/dmesg.c

Modified: head/sbin/dmesg/dmesg.c
==============================================================================
--- head/sbin/dmesg/dmesg.c	Tue Jun 11 15:37:07 2013	(r251617)
+++ head/sbin/dmesg/dmesg.c	Tue Jun 11 17:46:32 2013	(r251618)
@@ -120,6 +120,9 @@ main(int argc, char *argv[])
 			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");
@@ -196,10 +199,6 @@ 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);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306111746.r5BHkX5u028422>