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 tarball for details.
15 int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16 int dmesg_main(int argc UNUSED_PARAM, char **argv)
21 unsigned flags = getopt32(argv, "cs:n:", &size, &level);
29 if (klogctl(8, NULL, xatoul_range(level, 0, 10)))
30 bb_perror_msg_and_die("klogctl");
34 len = (flags & OPT_s) ? xatoul_range(size, 2, INT_MAX) : 16384;
36 len = klogctl(3 + (flags & OPT_c), buf, len);
38 bb_perror_msg_and_die("klogctl");
42 /* Skip <#> at the start of lines, and make sure we end with a newline. */
44 if (ENABLE_FEATURE_DMESG_PRETTY) {
49 if (last == '\n' && buf[in] == '<')
59 full_write(STDOUT_FILENO, buf, len);
60 if (buf[len-1] != '\n')
64 if (ENABLE_FEATURE_CLEAN_UP) free(buf);