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 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);
16 int dmesg_main(int argc, char **argv)
19 int flags = getopt32(argv, "cs:n:", &size, &level);
22 if (klogctl(8, NULL, xatoul_range(level, 0, 10)))
23 bb_perror_msg_and_die("klogctl");
28 len = (flags & 2) ? xatoul_range(size, 2, INT_MAX) : 16384;
30 if (0 > (len = klogctl(3 + (flags & 1), buf, len)))
31 bb_perror_msg_and_die("klogctl");
33 // Skip <#> at the start of lines, and make sure we end with a newline.
35 if (ENABLE_FEATURE_DMESG_PRETTY) {
39 for (in = 0; in<len;) {
40 if (last == '\n' && buf[in] == '<') in += 3;
41 else putchar(last = buf[in++]);
43 if (last != '\n') putchar('\n');
46 if (len && buf[len-1]!='\n') putchar('\n');
49 if (ENABLE_FEATURE_CLEAN_UP) free(buf);