aboutsummaryrefslogtreecommitdiff
path: root/util-linux/dmesg.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
commite49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /util-linux/dmesg.c
parentc0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff)
downloadbusybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'util-linux/dmesg.c')
-rw-r--r--util-linux/dmesg.c160
1 files changed, 81 insertions, 79 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index e38fd5555..bbed8221a 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* dmesg.c -- Print out the contents of the kernel ring buffer 2/* dmesg.c -- Print out the contents of the kernel ring buffer
2 * Created: Sat Oct 9 16:19:47 1993 3 * Created: Sat Oct 9 16:19:47 1993
3 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu 4 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
@@ -24,8 +25,8 @@
24 25
25#ifndef __alpha__ 26#ifndef __alpha__
26# define __NR_klogctl __NR_syslog 27# define __NR_klogctl __NR_syslog
27 static inline _syscall3(int, klogctl, int, type, char *, b, int, len); 28static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
28#else /* __alpha__ */ 29#else /* __alpha__ */
29#define klogctl syslog 30#define klogctl syslog
30#endif 31#endif
31 32
@@ -35,90 +36,91 @@
35 36
36static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n"; 37static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
37 38
38int dmesg_main( int argc, char** argv ) 39int dmesg_main(int argc, char **argv)
39{ 40{
40 char *buf; 41 char *buf;
41 int bufsize=8196; 42 int bufsize = 8196;
42 int i; 43 int i;
43 int n; 44 int n;
44 int level = 0; 45 int level = 0;
45 int lastc; 46 int lastc;
46 int cmd = 3; 47 int cmd = 3;
47 int stopDoingThat; 48 int stopDoingThat;
48 49
49 argc--; 50 argc--;
50 argv++; 51 argv++;
51 52
52 /* Parse any options */ 53 /* Parse any options */
53 while (argc && **argv == '-') { 54 while (argc && **argv == '-') {
54 stopDoingThat = FALSE; 55 stopDoingThat = FALSE;
55 while (stopDoingThat == FALSE && *++(*argv)) { 56 while (stopDoingThat == FALSE && *++(*argv)) {
56 switch (**argv) { 57 switch (**argv) {
57 case 'c': 58 case 'c':
58 cmd = 4; 59 cmd = 4;
59 break; 60 break;
60 case 'n': 61 case 'n':
61 cmd = 8; 62 cmd = 8;
62 if (--argc == 0) 63 if (--argc == 0)
63 goto end; 64 goto end;
64 level = atoi (*(++argv)); 65 level = atoi(*(++argv));
65 if (--argc > 0) 66 if (--argc > 0)
66 ++argv; 67 ++argv;
67 stopDoingThat = TRUE; 68 stopDoingThat = TRUE;
68 break; 69 break;
69 case 's': 70 case 's':
70 if (--argc == 0) 71 if (--argc == 0)
71 goto end; 72 goto end;
72 bufsize = atoi (*(++argv)); 73 bufsize = atoi(*(++argv));
73 if (--argc > 0) 74 if (--argc > 0)
74 ++argv; 75 ++argv;
75 stopDoingThat = TRUE; 76 stopDoingThat = TRUE;
76 break; 77 break;
77 default: 78 default:
79 goto end;
80 }
81 }
82 }
83
84 if (argc > 1) {
78 goto end; 85 goto end;
79 }
80 } 86 }
81 }
82
83 if (argc > 1) {
84 goto end;
85 }
86 87
87 if (cmd == 8) { 88 if (cmd == 8) {
88 n = klogctl( cmd, NULL, level ); 89 n = klogctl(cmd, NULL, level);
89 if (n < 0) { 90 if (n < 0) {
90 goto klogctl_error; 91 goto klogctl_error;
91 } 92 }
92 exit( TRUE ); 93 exit(TRUE);
93 } 94 }
94 95
95 if (bufsize < 4096) bufsize = 4096; 96 if (bufsize < 4096)
96 buf = (char*)malloc(bufsize); 97 bufsize = 4096;
97 n = klogctl( cmd, buf, bufsize ); 98 buf = (char *) malloc(bufsize);
98 if (n < 0) { 99 n = klogctl(cmd, buf, bufsize);
99 goto klogctl_error; 100 if (n < 0) {
100 } 101 goto klogctl_error;
102 }
101 103
102 lastc = '\n'; 104 lastc = '\n';
103 for (i = 0; i < n; i++) { 105 for (i = 0; i < n; i++) {
104 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { 106 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
105 i++; 107 i++;
106 while (buf[i] >= '0' && buf[i] <= '9') 108 while (buf[i] >= '0' && buf[i] <= '9')
107 i++; 109 i++;
108 if (buf[i] == '>') 110 if (buf[i] == '>')
109 i++; 111 i++;
110 } 112 }
111 lastc = buf[i]; 113 lastc = buf[i];
112 putchar( lastc ); 114 putchar(lastc);
113 } 115 }
114 if (lastc != '\n') 116 if (lastc != '\n')
115 putchar( '\n' ); 117 putchar('\n');
116 exit( TRUE); 118 exit(TRUE);
117end: 119 end:
118 usage( dmesg_usage); 120 usage(dmesg_usage);
119 exit (FALSE); 121 exit(FALSE);
120klogctl_error: 122 klogctl_error:
121 perror( "klogctl" ); 123 perror("klogctl");
122 exit( FALSE ); 124 exit(FALSE);
123 125
124} 126}