summaryrefslogtreecommitdiff
path: root/util-linux/dmesg.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-27 04:35:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-27 04:35:04 +0000
commit8d42f86b146871ae4c4cafd3801a85f381249a14 (patch)
treeb963999fc54eddb65f1929b894f868e24851fc9c /util-linux/dmesg.c
downloadbusybox-w32-8d42f86b146871ae4c4cafd3801a85f381249a14.tar.gz
busybox-w32-8d42f86b146871ae4c4cafd3801a85f381249a14.tar.bz2
busybox-w32-8d42f86b146871ae4c4cafd3801a85f381249a14.zip
Correcting branch name to be like previous ones
Diffstat (limited to 'util-linux/dmesg.c')
-rw-r--r--util-linux/dmesg.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
new file mode 100644
index 000000000..658cddc38
--- /dev/null
+++ b/util-linux/dmesg.c
@@ -0,0 +1,53 @@
1/* vi: set sw=4 ts=4: */
2/*
3 *
4 * dmesg - display/control kernel ring buffer.
5 *
6 * Copyright 2006 Rob Landley <rob@landley.net>
7 * Copyright 2006 Bernhard Fischer <rep.nop@aon.at>
8 *
9 * Licensed under GPLv2, see file LICENSE in this tarball for details.
10 */
11
12#include "busybox.h"
13#include <unistd.h>
14#include <sys/klog.h>
15
16int dmesg_main(int argc, char *argv[])
17{
18 char *size, *level;
19 int flags = getopt32(argc, argv, "cs:n:", &size, &level);
20
21 if (flags & 4) {
22 if (klogctl(8, NULL, xatoul_range(level, 0, 10)))
23 bb_perror_msg_and_die("klogctl");
24 } else {
25 int len;
26 char *buf;
27
28 len = (flags & 2) ? xatoul_range(size, 2, INT_MAX) : 16384;
29 buf = xmalloc(len);
30 if (0 > (len = klogctl(3 + (flags & 1), buf, len)))
31 bb_perror_msg_and_die("klogctl");
32
33 // Skip <#> at the start of lines, and make sure we end with a newline.
34
35 if (ENABLE_FEATURE_DMESG_PRETTY) {
36 int last = '\n';
37 int in;
38
39 for (in = 0; in<len;) {
40 if (last == '\n' && buf[in] == '<') in += 3;
41 else putchar(last = buf[in++]);
42 }
43 if (last != '\n') putchar('\n');
44 } else {
45 write(1,buf,len);
46 if (len && buf[len-1]!='\n') putchar('\n');
47 }
48
49 if (ENABLE_FEATURE_CLEAN_UP) free(buf);
50 }
51
52 return 0;
53}