aboutsummaryrefslogtreecommitdiff
path: root/util-linux/dmesg.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-19 20:03:34 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-19 20:03:34 +0000
commite77ae3a2c0328590b43447550bdb1284650b8236 (patch)
tree1e46d5cf36870771a4f3cedfe84f6161c3871131 /util-linux/dmesg.c
parenta3f09076ef5e9a2c26b4d0728cd066bba6c474e4 (diff)
downloadbusybox-w32-e77ae3a2c0328590b43447550bdb1284650b8236.tar.gz
busybox-w32-e77ae3a2c0328590b43447550bdb1284650b8236.tar.bz2
busybox-w32-e77ae3a2c0328590b43447550bdb1284650b8236.zip
Added sfdisk. Ststic-ified a bunch of stuff.
Diffstat (limited to 'util-linux/dmesg.c')
-rw-r--r--util-linux/dmesg.c128
1 files changed, 73 insertions, 55 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index e5d403f7a..aa26f5836 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -1,45 +1,49 @@
1#include "internal.h"
2#include <stdlib.h>
3#include <unistd.h>
4#include <time.h>
5
6/* dmesg.c -- Print out the contents of the kernel ring buffer 1/* dmesg.c -- Print out the contents of the kernel ring buffer
7 * Created: Sat Oct 9 16:19:47 1993 2 * Created: Sat Oct 9 16:19:47 1993
8 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu 3 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
9 * Copyright 1993 Theodore Ts'o (tytso@athena.mit.edu) 4 * Copyright 1993 Theodore Ts'o (tytso@athena.mit.edu)
10 * This program comes with ABSOLUTELY NO WARRANTY. 5 * This program comes with ABSOLUTELY NO WARRANTY.
11 * Modifications by Rick Sladkey (jrs@world.std.com) 6 * Modifications by Rick Sladkey (jrs@world.std.com)
12 * from util-linux; adapted for busybox 7 * Larger buffersize 3 June 1998 by Nicolai Langfeldt, based on a patch
8 * by Peeter Joot. This was also suggested by John Hudson.
9 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
10 * - added Native Language Support
11 *
12 * from util-linux -- adapted for busybox by
13 * Erik Andersen <andersee@debian.org>. I ripped out Native Language
14 * Support, replaced getopt, added some gotos for redundant stuff.
13 */ 15 */
14 16
17#include "internal.h"
15#include <linux/unistd.h> 18#include <linux/unistd.h>
16#include <stdio.h> 19#include <stdio.h>
20#include <getopt.h>
21#include <stdlib.h>
17 22
18#define __NR_klog __NR_syslog 23#if __GNU_LIBRARY__ < 5
19
20#if defined(__GLIBC__)
21#include <sys/klog.h>
22#define klog klogctl
23#else
24static inline _syscall3 (int, klog, int, type, char *, b, int, len)
25#endif /* __GLIBC__ */
26 24
25#ifndef __alpha__
26# define __NR_klogctl __NR_syslog
27 static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
28#else /* __alpha__ */
29#define klogctl syslog
30#endif
27 31
32#else
33# include <sys/klog.h>
34#endif
28 35
29static const char dmesg_usage[] = "dmesg [-c] [-n level]\n"; 36static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
30 37
31int dmesg_main (int argc, char **argv) 38int dmesg_main( int argc, char** argv )
32{ 39{
33 40 char *buf;
34 char buf[4096]; 41 int bufsize=8196;
35 int i; 42 int i;
36 int n; 43 int n;
37 int level = 0; 44 int level = 0;
38 int lastc; 45 int lastc;
39 int cmd = 3; 46 int cmd = 3;
40
41 argc--;
42 argv++;
43 47
44 /* Parse any options */ 48 /* Parse any options */
45 while (argc && **argv == '-') { 49 while (argc && **argv == '-') {
@@ -56,43 +60,57 @@ int dmesg_main (int argc, char **argv)
56 --argc; 60 --argc;
57 ++argv; 61 ++argv;
58 break; 62 break;
63 case 's':
64 if (--argc == 0)
65 goto end;
66 bufsize = atoi (*(++argv));
67 --argc;
68 ++argv;
69 break;
59 default: 70 default:
60 goto end; 71 goto end;
61 } 72 }
62 } 73 }
74
75 if (argc > 1) {
76 goto end;
77 }
63 78
64 if (cmd == 8) { 79 if (cmd == 8) {
65 n = klog (cmd, NULL, level); 80 n = klogctl( cmd, NULL, level );
66 if (n < 0) { 81 if (n < 0) {
67 perror ("klog"); 82 goto klogctl_error;
68 exit (FALSE); 83 }
69 } 84 exit( TRUE );
70 exit (TRUE); 85 }
71 }
72 86
73 n = klog (cmd, buf, sizeof (buf)); 87 if (bufsize < 4096) bufsize = 4096;
74 if (n < 0) { 88 buf = (char*)malloc(bufsize);
75 perror ("klog"); 89 n = klogctl( cmd, buf, bufsize );
76 exit (FALSE); 90 if (n < 0) {
77 } 91 goto klogctl_error;
92 }
78 93
79 lastc = '\n'; 94 lastc = '\n';
80 for (i = 0; i < n; i++) { 95 for (i = 0; i < n; i++) {
81 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { 96 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
97 i++;
98 while (buf[i] >= '0' && buf[i] <= '9')
82 i++; 99 i++;
83 while (buf[i] >= '0' && buf[i] <= '9') 100 if (buf[i] == '>')
84 i++; 101 i++;
85 if (buf[i] == '>') 102 }
86 i++; 103 lastc = buf[i];
87 } 104 putchar( lastc );
88 lastc = buf[i]; 105 }
89 putchar (lastc); 106 if (lastc != '\n')
90 } 107 putchar( '\n' );
91 if (lastc != '\n') 108 exit( TRUE);
92 putchar ('\n'); 109end:
93 exit (TRUE);
94
95 end:
96 usage( dmesg_usage); 110 usage( dmesg_usage);
97 exit (FALSE); 111 exit (FALSE);
112klogctl_error:
113 perror( "klogctl" );
114 exit( FALSE );
115
98} 116}