comparison toys/lsb/dmesg.c @ 694:786841fdb1e0

Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
author Rob Landley <rob@landley.net>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 7e846e281e38
children d26f235323db
comparison
equal deleted inserted replaced
693:4a5a250e0633 694:786841fdb1e0
1 /* vi: set sw=4 ts=4: 1 /* dmesg.c - display/control kernel ring buffer.
2 *
3 * dmesg.c - display/control kernel ring buffer.
4 * 2 *
5 * Copyright 2006, 2007 Rob Landley <rob@landley.net> 3 * Copyright 2006, 2007 Rob Landley <rob@landley.net>
6 * 4 *
7 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/dmesg.html 5 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/dmesg.html
8 6
9 USE_DMESG(NEWTOY(dmesg, "s#n#c", TOYFLAG_BIN)) 7 USE_DMESG(NEWTOY(dmesg, "s#n#c", TOYFLAG_BIN))
10 8
11 config DMESG 9 config DMESG
12 bool "dmesg" 10 bool "dmesg"
13 default y 11 default y
14 help 12 help
15 usage: dmesg [-n level] [-s bufsize] | -c 13 usage: dmesg [-n level] [-s bufsize] | -c
16 14
17 Print or control the kernel ring buffer. 15 Print or control the kernel ring buffer.
18 16
19 -n Set kernel logging level (1-9). 17 -n Set kernel logging level (1-9).
20 -s Size of buffer to read (in bytes), default 16384. 18 -s Size of buffer to read (in bytes), default 16384.
21 -c Clear the ring buffer after printing. 19 -c Clear the ring buffer after printing.
22 */ 20 */
23 21
24 #define FOR_dmesg 22 #define FOR_dmesg
25 #include "toys.h" 23 #include "toys.h"
26 #include <sys/klog.h> 24 #include <sys/klog.h>
27 25
28 GLOBALS( 26 GLOBALS(
29 long level; 27 long level;
30 long size; 28 long size;
31 ) 29 )
32 30
33 void dmesg_main(void) 31 void dmesg_main(void)
34 { 32 {
35 // For -n just tell kernel to which messages to keep. 33 // For -n just tell kernel to which messages to keep.
36 if (toys.optflags & 2) { 34 if (toys.optflags & 2) {
37 if (klogctl(8, NULL, TT.level)) 35 if (klogctl(8, NULL, TT.level)) error_exit("klogctl");
38 error_exit("klogctl"); 36 } else {
39 } else { 37 int size, i, last = '\n';
40 int size, i, last = '\n'; 38 char *data;
41 char *data;
42 39
43 // Figure out how much data we need, and fetch it. 40 // Figure out how much data we need, and fetch it.
44 size = TT.size; 41 size = TT.size;
45 if (size<2) size = 16384; 42 if (size<2) size = 16384;
46 data = xmalloc(size); 43 data = xmalloc(size);
47 size = klogctl(3 + (toys.optflags&1), data, size); 44 size = klogctl(3 + (toys.optflags&1), data, size);
48 if (size < 0) error_exit("klogctl"); 45 if (size < 0) error_exit("klogctl");
49 46
50 // Display data, filtering out level markers. 47 // Display data, filtering out level markers.
51 for (i=0; i<size; ) { 48 for (i=0; i<size; ) {
52 if (last=='\n' && data[i]=='<') i += 3; 49 if (last=='\n' && data[i]=='<') i += 3;
53 else xputc(last = data[i++]); 50 else xputc(last = data[i++]);
54 } 51 }
55 if (last!='\n') xputc('\n'); 52 if (last!='\n') xputc('\n');
56 if (CFG_TOYBOX_FREE) free(data); 53 if (CFG_TOYBOX_FREE) free(data);
57 } 54 }
58 } 55 }