diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-12 22:26:06 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-12 22:26:06 +0000 |
commit | 3cf52d19581b2077480e7d2e63010baa1f5399c1 (patch) | |
tree | d91b0cb332ebc976126e36a394655dde7a15d8b1 /util-linux/dmesg.c | |
parent | 2ce1edcf544ac675e6762c9861a6b918401ea716 (diff) | |
download | busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.gz busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.bz2 busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.zip |
More stuff...
Diffstat (limited to 'util-linux/dmesg.c')
-rw-r--r-- | util-linux/dmesg.c | 127 |
1 files changed, 65 insertions, 62 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index 9096621b0..64265b473 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c | |||
@@ -14,7 +14,6 @@ | |||
14 | 14 | ||
15 | #include <linux/unistd.h> | 15 | #include <linux/unistd.h> |
16 | #include <stdio.h> | 16 | #include <stdio.h> |
17 | #include <getopt.h> | ||
18 | 17 | ||
19 | #define __NR_klog __NR_syslog | 18 | #define __NR_klog __NR_syslog |
20 | 19 | ||
@@ -22,74 +21,78 @@ | |||
22 | #include <sys/klog.h> | 21 | #include <sys/klog.h> |
23 | #define klog klogctl | 22 | #define klog klogctl |
24 | #else | 23 | #else |
25 | static inline _syscall3(int,klog,int,type,char *,b,int,len) | 24 | static inline _syscall3 (int, klog, int, type, char *, b, int, len) |
26 | #endif /* __GLIBC__ */ | 25 | #endif /* __GLIBC__ */ |
27 | 26 | ||
28 | const char dmesg_usage[] = "dmesg"; | ||
29 | 27 | ||
30 | int | 28 | |
31 | dmesg_main(int argc, char * * argv) | 29 | static const char dmesg_usage[] = "dmesg [-c] [-n level]\n"; |
30 | |||
31 | int dmesg_main (int argc, char **argv) | ||
32 | { | 32 | { |
33 | 33 | ||
34 | char buf[4096]; | 34 | char buf[4096]; |
35 | int i; | 35 | int i; |
36 | int n; | 36 | int n; |
37 | int c; | 37 | int level = 0; |
38 | int level = 0; | 38 | int lastc; |
39 | int lastc; | 39 | int cmd = 3; |
40 | int cmd = 3; | ||
41 | 40 | ||
42 | while ((c = getopt( argc, argv, "cn:" )) != EOF) { | 41 | argc--; |
43 | switch (c) { | 42 | argv++; |
44 | case 'c': | ||
45 | cmd = 4; | ||
46 | break; | ||
47 | case 'n': | ||
48 | cmd = 8; | ||
49 | level = atoi(optarg); | ||
50 | break; | ||
51 | case '?': | ||
52 | default: | ||
53 | fprintf(stderr, "%s\n", dmesg_usage); | ||
54 | exit(1); | ||
55 | } | ||
56 | } | ||
57 | argc -= optind; | ||
58 | argv += optind; | ||
59 | |||
60 | if (argc > 1) { | ||
61 | fprintf(stderr, "%s\n", dmesg_usage); | ||
62 | exit(1); | ||
63 | } | ||
64 | 43 | ||
65 | if (cmd == 8) { | 44 | /* Parse any options */ |
66 | n = klog( cmd, NULL, level ); | 45 | while (argc && **argv == '-') { |
67 | if (n < 0) { | 46 | while (*++(*argv)) |
68 | perror( "klog" ); | 47 | switch (**argv) { |
69 | exit( 1 ); | 48 | case 'c': |
70 | } | 49 | cmd = 4; |
71 | exit( 0 ); | 50 | break; |
72 | } | 51 | case 'n': |
52 | cmd = 8; | ||
53 | if (--argc == 0) | ||
54 | goto end; | ||
55 | level = atoi (*(++argv)); | ||
56 | --argc; | ||
57 | ++argv; | ||
58 | break; | ||
59 | default: | ||
60 | goto end; | ||
61 | } | ||
62 | } | ||
73 | 63 | ||
74 | n = klog( cmd, buf, sizeof( buf ) ); | 64 | if (cmd == 8) { |
75 | if (n < 0) { | 65 | n = klog (cmd, NULL, level); |
76 | perror( "klog" ); | 66 | if (n < 0) { |
77 | exit( 1 ); | 67 | perror ("klog"); |
78 | } | 68 | exit (FALSE); |
69 | } | ||
70 | exit (TRUE); | ||
71 | } | ||
79 | 72 | ||
80 | lastc = '\n'; | 73 | n = klog (cmd, buf, sizeof (buf)); |
81 | for (i = 0; i < n; i++) { | 74 | if (n < 0) { |
82 | if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { | 75 | perror ("klog"); |
83 | i++; | 76 | exit (FALSE); |
84 | while (buf[i] >= '0' && buf[i] <= '9') | 77 | } |
85 | i++; | 78 | |
86 | if (buf[i] == '>') | 79 | lastc = '\n'; |
80 | for (i = 0; i < n; i++) { | ||
81 | if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { | ||
87 | i++; | 82 | i++; |
88 | } | 83 | while (buf[i] >= '0' && buf[i] <= '9') |
89 | lastc = buf[i]; | 84 | i++; |
90 | putchar( lastc ); | 85 | if (buf[i] == '>') |
91 | } | 86 | i++; |
92 | if (lastc != '\n') | 87 | } |
93 | putchar( '\n' ); | 88 | lastc = buf[i]; |
94 | return 0; | 89 | putchar (lastc); |
90 | } | ||
91 | if (lastc != '\n') | ||
92 | putchar ('\n'); | ||
93 | exit (TRUE); | ||
94 | |||
95 | end: | ||
96 | fprintf (stderr, "Usage: %s\n", dmesg_usage); | ||
97 | exit (FALSE); | ||
95 | } | 98 | } |