Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/util-linux/dmesg.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 816 - (hide annotations) (download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 1441 byte(s)
-updated to busybox-1.13.4
1 niro 532 /* 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 niro 816 * Copyright 2006 Bernhard Reutner-Fischer <rep.nop@aon.at>
8 niro 532 *
9     * Licensed under GPLv2, see file LICENSE in this tarball for details.
10     */
11    
12     #include <sys/klog.h>
13 niro 816 #include "libbb.h"
14 niro 532
15 niro 816 int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16     int dmesg_main(int argc UNUSED_PARAM, char **argv)
17 niro 532 {
18 niro 816 int len;
19     char *buf;
20 niro 532 char *size, *level;
21 niro 816 unsigned flags = getopt32(argv, "cs:n:", &size, &level);
22     enum {
23     OPT_c = 1<<0,
24     OPT_s = 1<<1,
25     OPT_n = 1<<2
26     };
27 niro 532
28 niro 816 if (flags & OPT_n) {
29 niro 532 if (klogctl(8, NULL, xatoul_range(level, 0, 10)))
30     bb_perror_msg_and_die("klogctl");
31 niro 816 return EXIT_SUCCESS;
32     }
33 niro 532
34 niro 816 len = (flags & OPT_s) ? xatoul_range(size, 2, INT_MAX) : 16384;
35     buf = xmalloc(len);
36     len = klogctl(3 + (flags & OPT_c), buf, len);
37     if (len < 0)
38     bb_perror_msg_and_die("klogctl");
39     if (len == 0)
40     return EXIT_SUCCESS;
41 niro 532
42 niro 816 /* Skip <#> at the start of lines, and make sure we end with a newline. */
43 niro 532
44 niro 816 if (ENABLE_FEATURE_DMESG_PRETTY) {
45     int last = '\n';
46     int in = 0;
47 niro 532
48 niro 816 do {
49     if (last == '\n' && buf[in] == '<')
50     in += 3;
51     else {
52     last = buf[in++];
53     bb_putchar(last);
54 niro 532 }
55 niro 816 } while (in < len);
56     if (last != '\n')
57     bb_putchar('\n');
58     } else {
59     full_write(STDOUT_FILENO, buf, len);
60     if (buf[len-1] != '\n')
61     bb_putchar('\n');
62 niro 532 }
63    
64 niro 816 if (ENABLE_FEATURE_CLEAN_UP) free(buf);
65    
66     return EXIT_SUCCESS;
67 niro 532 }