aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-10 14:14:14 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-10 14:14:14 +0200
commit874201fee5a57acf25efe1b0b9c7e58ef6ef98a5 (patch)
tree84447e300204f14816e8576742c00cee2f707ab9
parentae68f1133f5d7ea56ac3ea7f0ee439c3496835e8 (diff)
downloadbusybox-w32-874201fee5a57acf25efe1b0b9c7e58ef6ef98a5.tar.gz
busybox-w32-874201fee5a57acf25efe1b0b9c7e58ef6ef98a5.tar.bz2
busybox-w32-874201fee5a57acf25efe1b0b9c7e58ef6ef98a5.zip
dmesg: try to detect buffer size
function old new delta dmesg_main 214 246 +32 Signed-off-by: Randy Robertson <rmrobert@vmware.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/dmesg.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index f52026c2f..b0dc592d2 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -8,38 +8,44 @@
8 * 8 *
9 * Licensed under GPLv2, see file LICENSE in this tarball for details. 9 * Licensed under GPLv2, see file LICENSE in this tarball for details.
10 */ 10 */
11
12#include <sys/klog.h> 11#include <sys/klog.h>
13#include "libbb.h" 12#include "libbb.h"
14 13
15int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 14int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16int dmesg_main(int argc UNUSED_PARAM, char **argv) 15int dmesg_main(int argc UNUSED_PARAM, char **argv)
17{ 16{
18 int len; 17 int len, level;
19 char *buf; 18 char *buf;
20 char *size, *level; 19 unsigned opts;
21 unsigned flags = getopt32(argv, "cs:n:", &size, &level);
22 enum { 20 enum {
23 OPT_c = 1<<0, 21 OPT_c = 1 << 0,
24 OPT_s = 1<<1, 22 OPT_s = 1 << 1,
25 OPT_n = 1<<2 23 OPT_n = 1 << 2
26 }; 24 };
27 25
28 if (flags & OPT_n) { 26 opt_complementary = "s+:n+"; /* numeric */
29 if (klogctl(8, NULL, xatoul_range(level, 0, 10))) 27 opts = getopt32(argv, "cs:n:", &len, &level);
28 if (opts & OPT_n) {
29 if (klogctl(8, NULL, (long) level))
30 bb_perror_msg_and_die("klogctl"); 30 bb_perror_msg_and_die("klogctl");
31 return EXIT_SUCCESS; 31 return EXIT_SUCCESS;
32 } 32 }
33 33
34 len = (flags & OPT_s) ? xatoul_range(size, 2, INT_MAX) : 16384; 34 if (!(opts & OPT_s))
35 len = klogctl(10, NULL, 0); /* read ring buffer size */
36 if (len < 16*1024)
37 len = 16*1024;
38 if (len > 16*1024*1024)
39 len = 16*1024*1024;
40
35 buf = xmalloc(len); 41 buf = xmalloc(len);
36 len = klogctl(3 + (flags & OPT_c), buf, len); 42 len = klogctl(3 + (opts & OPT_c), buf, len); /* read ring buffer */
37 if (len < 0) 43 if (len < 0)
38 bb_perror_msg_and_die("klogctl"); 44 bb_perror_msg_and_die("klogctl");
39 if (len == 0) 45 if (len == 0)
40 return EXIT_SUCCESS; 46 return EXIT_SUCCESS;
41 47
42 /* Skip <#> at the start of lines, and make sure we end with a newline. */ 48 /* Skip <#> at the start of lines, and make sure we end with a newline */
43 49
44 if (ENABLE_FEATURE_DMESG_PRETTY) { 50 if (ENABLE_FEATURE_DMESG_PRETTY) {
45 int last = '\n'; 51 int last = '\n';