diff options
author | Rob Landley <rob@landley.net> | 2006-06-13 18:31:04 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-06-13 18:31:04 +0000 |
commit | 7c7b0d74372da5fbde67513aa9ce162a555d4765 (patch) | |
tree | 4b95919b39b7f9b76ccc52829e84abd7979d5db4 | |
parent | 18958e9309b6565245ae14a19aab947fb2da79aa (diff) | |
download | busybox-w32-7c7b0d74372da5fbde67513aa9ce162a555d4765.tar.gz busybox-w32-7c7b0d74372da5fbde67513aa9ce162a555d4765.tar.bz2 busybox-w32-7c7b0d74372da5fbde67513aa9ce162a555d4765.zip |
Rewrite of dmesg, smaller and simpler.
-rw-r--r-- | util-linux/dmesg.c | 95 |
1 files changed, 25 insertions, 70 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index 2166edba3..6adba159a 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c | |||
@@ -1,80 +1,35 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set ts=4: |
2 | /* dmesg.c -- Print out the contents of the kernel ring buffer | 2 | * |
3 | * Created: Sat Oct 9 16:19:47 1993 | 3 | * dmesg - display/control kernel ring buffer. |
4 | * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu | ||
5 | * Copyright 1993 Theodore Ts'o (tytso@athena.mit.edu) | ||
6 | * This program comes with ABSOLUTELY NO WARRANTY. | ||
7 | * Modifications by Rick Sladkey (jrs@world.std.com) | ||
8 | * Larger buffersize 3 June 1998 by Nicolai Langfeldt, based on a patch | ||
9 | * by Peeter Joot. This was also suggested by John Hudson. | ||
10 | * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> | ||
11 | * - added Native Language Support | ||
12 | * | 4 | * |
13 | * from util-linux -- adapted for busybox by | 5 | * Copyring 2006 Rob Landley <rob@landley.net> |
14 | * Erik Andersen <andersen@codepoet.org>. I ripped out Native Language | ||
15 | * Support, replaced getopt, added some gotos for redundant stuff. | ||
16 | * | 6 | * |
17 | * Audited and cleaned up on 7 March 2003 to reduce size of | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
18 | * check error handling by Erik Andersen <andersen@codepoet.org> | ||
19 | */ | 8 | */ |
20 | 9 | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <errno.h> | ||
24 | #include <sys/klog.h> | ||
25 | |||
26 | #include "busybox.h" | 10 | #include "busybox.h" |
11 | #include <unistd.h> | ||
12 | #include <sys/klog.h> | ||
27 | 13 | ||
28 | int dmesg_main(int argc, char **argv) | 14 | int dmesg_main(int argc, char *argv[]) |
29 | { | 15 | { |
30 | char *buf, *tmp; | 16 | char *size, *level; |
31 | int bufsize = 8196; | 17 | int flags = bb_getopt_ulflags(argc, argv, "c:s:n:", &size, &level); |
32 | int i, n = 0; | 18 | |
33 | int c = 3; | 19 | if (flags & 4) { |
34 | 20 | if(klogctl(8, NULL, bb_xgetlarg(size, 10, 0, 10))) | |
35 | i = bb_getopt_ulflags(argc, argv, "cn:s:", &buf, &tmp); | 21 | bb_perror_msg_and_die("klogctl"); |
36 | if (i & 1) | 22 | } else { |
37 | c = 4; | 23 | int len; |
38 | if (i & 2) { | 24 | char *buf; |
39 | c = 8; | 25 | |
40 | n = bb_xgetlarg(buf, 10, 0, 10); | 26 | len = (flags & 2) ? bb_xgetlarg(size, 10, 4096, INT_MAX) : 16384; |
41 | } | 27 | buf = xmalloc(len); |
42 | if (i & 4) | 28 | if (0 > (len = klogctl(3 + (flags & 1), buf, len))) |
43 | /* I think a 512k max kernel ring buffer is big enough for | 29 | bb_perror_msg_and_die("klogctl"); |
44 | * anybody, as the default is 16k... Could be wrong though. | 30 | write(1,buf,len); |
45 | * If so I'm sure I'll hear about it by the enraged masses*/ | 31 | if (len && buf[len-1]!='\n') putchar('\n'); |
46 | bufsize = bb_xgetlarg(tmp, 10, 4096, 512*1024); | ||
47 | |||
48 | if (c == 8) { | ||
49 | if (klogctl(c, NULL, n) < 0) | ||
50 | goto die_the_death; | ||
51 | goto all_done; | ||
52 | } | ||
53 | |||
54 | buf = xmalloc(bufsize); | ||
55 | if ((n = klogctl(c, buf, bufsize)) < 0) | ||
56 | goto die_the_death; | ||
57 | |||
58 | c = '\n'; | ||
59 | for (i = 0; i < n; i++) { | ||
60 | if (c == '\n' && buf[i] == '<') { | ||
61 | i++; | ||
62 | while (buf[i] >= '0' && buf[i] <= '9') | ||
63 | i++; | ||
64 | if (buf[i] == '>') | ||
65 | i++; | ||
66 | } | ||
67 | c = buf[i]; | ||
68 | putchar(c); | ||
69 | } | ||
70 | if (c != '\n') | ||
71 | putchar('\n'); | ||
72 | all_done: | ||
73 | if (ENABLE_FEATURE_CLEAN_UP) { | ||
74 | free(buf); | ||
75 | } | 32 | } |
76 | 33 | ||
77 | return EXIT_SUCCESS; | 34 | return 0; |
78 | die_the_death: | ||
79 | bb_perror_nomsg_and_die(); | ||
80 | } | 35 | } |