1 /* vi: set sw=4 ts=4: */
4 * dmesg - display/control kernel ring buffer.
6 * Copyright 2006 Rob Landley <rob@landley.net>
7 * Copyright 2006 Bernhard Reutner-Fischer <rep.nop@aon.at>
9 * Licensed under GPLv2, see file LICENSE in this source tree.
12 //usage:#define dmesg_trivial_usage
13 //usage: "[-c] [-n LEVEL] [-s SIZE]"
14 //usage:#define dmesg_full_usage "\n\n"
15 //usage: "Print or control the kernel ring buffer\n"
16 //usage: "\n -c Clear ring buffer after printing"
17 //usage: "\n -n LEVEL Set console logging level"
18 //usage: "\n -s SIZE Buffer size"
23 int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
24 int dmesg_main(int argc UNUSED_PARAM, char **argv)
35 opt_complementary = "s+:n+"; /* numeric */
36 opts = getopt32(argv, "cs:n:", &len, &level);
38 if (klogctl(8, NULL, (long) level))
39 bb_perror_msg_and_die("klogctl");
44 len = klogctl(10, NULL, 0); /* read ring buffer size */
47 if (len > 16*1024*1024)
51 len = klogctl(3 + (opts & OPT_c), buf, len); /* read ring buffer */
53 bb_perror_msg_and_die("klogctl");
58 if (ENABLE_FEATURE_DMESG_PRETTY) {
62 /* Skip <#> at the start of lines */
64 if (last == '\n' && buf[in] == '<') {
75 /* Make sure we end with a newline */
79 full_write(STDOUT_FILENO, buf, len);
80 if (buf[len-1] != '\n')
84 if (ENABLE_FEATURE_CLEAN_UP) free(buf);