Add raw flag for dmesg

This commit is contained in:
sin 2013-08-17 17:22:30 +01:00
parent 41d82175fc
commit 5c73758bba

17
dmesg.c
View File

@ -18,7 +18,7 @@ enum {
static void
usage(void)
{
eprintf("usage: [-Cc] %s\n", argv0);
eprintf("usage: [-Ccr] %s\n", argv0);
}
int
@ -27,6 +27,7 @@ main(int argc, char *argv[])
int n;
char *buf;
int cflag = 0;
int rflag = 0;
ARGBEGIN {
case 'C':
@ -36,6 +37,9 @@ main(int argc, char *argv[])
case 'c':
cflag = 1;
break;
case 'r':
rflag = 1;
break;
default:
usage();
} ARGEND;
@ -52,9 +56,14 @@ main(int argc, char *argv[])
if (n < 0)
eprintf("klogctl:");
n = dmesg_show(STDOUT_FILENO, buf, n);
if (n < 0)
eprintf("dmesg_show:");
if (rflag) {
if (write(STDOUT_FILENO, buf, n) != n)
eprintf("write:");
} else {
n = dmesg_show(STDOUT_FILENO, buf, n);
if (n < 0)
eprintf("dmesg_show:");
}
if (cflag && klogctl(SYSLOG_ACTION_CLEAR, NULL, 0) < 0)
eprintf("klogctl:");