diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-03-29 17:26:14 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-03-29 17:26:14 +0000 |
commit | b256bd334fe354420eca91ad9a1d9346b2da2b27 (patch) | |
tree | 4279dce899dd237e022f3d79d5dc4a1e3046cbc9 | |
parent | ca087713f24d3e856c46829c005d3aa43a5dbdf1 (diff) | |
download | busybox-w32-b256bd334fe354420eca91ad9a1d9346b2da2b27.tar.gz busybox-w32-b256bd334fe354420eca91ad9a1d9346b2da2b27.tar.bz2 busybox-w32-b256bd334fe354420eca91ad9a1d9346b2da2b27.zip |
- shrink dmesg a bit.
http://busybox.net/lists/busybox/2006-March/019477.html
-rw-r--r-- | util-linux/dmesg.c | 63 |
1 files changed, 22 insertions, 41 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index 2ca882714..2166edba3 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c | |||
@@ -20,7 +20,6 @@ | |||
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <getopt.h> | ||
24 | #include <errno.h> | 23 | #include <errno.h> |
25 | #include <sys/klog.h> | 24 | #include <sys/klog.h> |
26 | 25 | ||
@@ -28,71 +27,53 @@ | |||
28 | 27 | ||
29 | int dmesg_main(int argc, char **argv) | 28 | int dmesg_main(int argc, char **argv) |
30 | { | 29 | { |
31 | char *buf | 30 | char *buf, *tmp; |
32 | #ifdef CONFIG_FEATURE_CLEAN_UP | ||
33 | = NULL | ||
34 | #endif | ||
35 | ; | ||
36 | int bufsize = 8196; | 31 | int bufsize = 8196; |
37 | int i, n; | 32 | int i, n = 0; |
38 | int level = 0; | 33 | int c = 3; |
39 | int lastc; | ||
40 | int cmd = 3; | ||
41 | 34 | ||
42 | while ((i = getopt(argc, argv, "cn:s:")) > 0) { | 35 | i = bb_getopt_ulflags(argc, argv, "cn:s:", &buf, &tmp); |
43 | switch (i) { | 36 | if (i & 1) |
44 | case 'c': | 37 | c = 4; |
45 | cmd = 4; | 38 | if (i & 2) { |
46 | break; | 39 | c = 8; |
47 | case 'n': | 40 | n = bb_xgetlarg(buf, 10, 0, 10); |
48 | cmd = 8; | 41 | } |
49 | level = bb_xgetlarg(optarg, 10, 0, 10); | 42 | if (i & 4) |
50 | break; | ||
51 | case 's': | ||
52 | /* I think a 512k max kernel ring buffer is big enough for | 43 | /* I think a 512k max kernel ring buffer is big enough for |
53 | * anybody, as the default is 16k... Could be wrong though. | 44 | * anybody, as the default is 16k... Could be wrong though. |
54 | * If so I'm sure I'll hear about it by the enraged masses*/ | 45 | * If so I'm sure I'll hear about it by the enraged masses*/ |
55 | bufsize = bb_xgetlarg(optarg, 10, 4096, 512*1024); | 46 | bufsize = bb_xgetlarg(tmp, 10, 4096, 512*1024); |
56 | break; | ||
57 | default: | ||
58 | bb_show_usage(); | ||
59 | } | ||
60 | } | ||
61 | 47 | ||
62 | if (optind < argc) { | 48 | if (c == 8) { |
63 | bb_show_usage(); | 49 | if (klogctl(c, NULL, n) < 0) |
64 | } | ||
65 | |||
66 | if (cmd == 8) { | ||
67 | if (klogctl(cmd, NULL, level) < 0) | ||
68 | goto die_the_death; | 50 | goto die_the_death; |
69 | goto all_done; | 51 | goto all_done; |
70 | } | 52 | } |
71 | 53 | ||
72 | buf = xmalloc(bufsize); | 54 | buf = xmalloc(bufsize); |
73 | if ((n = klogctl(cmd, buf, bufsize)) < 0) | 55 | if ((n = klogctl(c, buf, bufsize)) < 0) |
74 | goto die_the_death; | 56 | goto die_the_death; |
75 | 57 | ||
76 | lastc = '\n'; | 58 | c = '\n'; |
77 | for (i = 0; i < n; i++) { | 59 | for (i = 0; i < n; i++) { |
78 | if (lastc == '\n' && buf[i] == '<') { | 60 | if (c == '\n' && buf[i] == '<') { |
79 | i++; | 61 | i++; |
80 | while (buf[i] >= '0' && buf[i] <= '9') | 62 | while (buf[i] >= '0' && buf[i] <= '9') |
81 | i++; | 63 | i++; |
82 | if (buf[i] == '>') | 64 | if (buf[i] == '>') |
83 | i++; | 65 | i++; |
84 | } | 66 | } |
85 | lastc = buf[i]; | 67 | c = buf[i]; |
86 | putchar(lastc); | 68 | putchar(c); |
87 | } | 69 | } |
88 | if (lastc != '\n') | 70 | if (c != '\n') |
89 | putchar('\n'); | 71 | putchar('\n'); |
90 | all_done: | 72 | all_done: |
91 | #ifdef CONFIG_FEATURE_CLEAN_UP | 73 | if (ENABLE_FEATURE_CLEAN_UP) { |
92 | if (buf) { | ||
93 | free(buf); | 74 | free(buf); |
94 | } | 75 | } |
95 | #endif | 76 | |
96 | return EXIT_SUCCESS; | 77 | return EXIT_SUCCESS; |
97 | die_the_death: | 78 | die_the_death: |
98 | bb_perror_nomsg_and_die(); | 79 | bb_perror_nomsg_and_die(); |