Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/util-linux/dmesg.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/util-linux/dmesg.c
r821 r1770 1 /* vi: set ts=4: 2 * 1 /* vi: set sw=4 ts=4: */ 2 /* 3 * 3 4 * dmesg - display/control kernel ring buffer. 4 5 * 5 * Copyring 2006 Rob Landley <rob@landley.net> 6 * Copyright 2006 Rob Landley <rob@landley.net> 7 * Copyright 2006 Bernhard Fischer <rep.nop@aon.at> 6 8 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.9 * Licensed under GPLv2, see file LICENSE in this tarball for details. 8 10 */ 9 11 10 #include "busybox.h"11 #include <unistd.h>12 12 #include <sys/klog.h> 13 #include "libbb.h" 13 14 14 int dmesg_main(int argc, char *argv[]) 15 int dmesg_main(int argc, char **argv); 16 int dmesg_main(int argc, char **argv) 15 17 { 16 18 char *size, *level; 17 int flags = bb_getopt_ulflags(argc,argv, "cs:n:", &size, &level);19 int flags = getopt32(argv, "cs:n:", &size, &level); 18 20 19 21 if (flags & 4) { 20 if (klogctl(8, NULL, bb_xgetlarg(level, 10, 0, 10)))22 if (klogctl(8, NULL, xatoul_range(level, 0, 10))) 21 23 bb_perror_msg_and_die("klogctl"); 22 24 } else { … … 24 26 char *buf; 25 27 26 len = (flags & 2) ? bb_xgetlarg(size, 10, 2, INT_MAX) : 16384;28 len = (flags & 2) ? xatoul_range(size, 2, INT_MAX) : 16384; 27 29 buf = xmalloc(len); 28 30 if (0 > (len = klogctl(3 + (flags & 1), buf, len))) 29 31 bb_perror_msg_and_die("klogctl"); 30 write(1,buf,len); 31 if (len && buf[len-1]!='\n') putchar('\n'); 32 33 // Skip <#> at the start of lines, and make sure we end with a newline. 34 35 if (ENABLE_FEATURE_DMESG_PRETTY) { 36 int last = '\n'; 37 int in; 38 39 for (in = 0; in<len;) { 40 if (last == '\n' && buf[in] == '<') in += 3; 41 else putchar(last = buf[in++]); 42 } 43 if (last != '\n') putchar('\n'); 44 } else { 45 write(1,buf,len); 46 if (len && buf[len-1]!='\n') putchar('\n'); 47 } 48 49 if (ENABLE_FEATURE_CLEAN_UP) free(buf); 32 50 } 33 51
Note:
See TracChangeset
for help on using the changeset viewer.