summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authoreadler <eadler@FreeBSD.org>2013-05-10 03:42:48 +0000
committereadler <eadler@FreeBSD.org>2013-05-10 03:42:48 +0000
commit56def3d68d612ab479869fc64af58e12ff1fb811 (patch)
tree2d3b1fbe0aa078399d1401d43d74461516b09b3e /sbin
parent9800f9b0a776c1db3e28c2aae7c4a952e0c96ce7 (diff)
downloadFreeBSD-src-56def3d68d612ab479869fc64af58e12ff1fb811.zip
FreeBSD-src-56def3d68d612ab479869fc64af58e12ff1fb811.tar.gz
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
Diffstat (limited to 'sbin')
-rw-r--r--sbin/dmesg/dmesg.84
-rw-r--r--sbin/dmesg/dmesg.c20
2 files changed, 18 insertions, 6 deletions
diff --git a/sbin/dmesg/dmesg.8 b/sbin/dmesg/dmesg.8
index 9d05e6c..b5004f5 100644
--- a/sbin/dmesg/dmesg.8
+++ b/sbin/dmesg/dmesg.8
@@ -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
diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c
index 002732c..1d548a7 100644
--- a/sbin/dmesg/dmesg.c
+++ b/sbin/dmesg/dmesg.c
@@ -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);
}
OpenPOWER on IntegriCloud