aboutsummaryrefslogtreecommitdiff
path: root/util-linux/dmesg.c
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 /util-linux/dmesg.c
parentae68f1133f5d7ea56ac3ea7f0ee439c3496835e8 (diff)
downloadbusybox-874201fee5a57acf25efe1b0b9c7e58ef6ef98a5.tar.gz
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>
Diffstat (limited to 'util-linux/dmesg.c')
-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 @@
*
* Licensed under GPLv2, see file LICENSE in this tarball for details.
*/
-
#include <sys/klog.h>
#include "libbb.h"
int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dmesg_main(int argc UNUSED_PARAM, char **argv)
{
- int len;
+ int len, level;
char *buf;
- char *size, *level;
- unsigned flags = getopt32(argv, "cs:n:", &size, &level);
+ unsigned opts;
enum {
- OPT_c = 1<<0,
- OPT_s = 1<<1,
- OPT_n = 1<<2
+ OPT_c = 1 << 0,
+ OPT_s = 1 << 1,
+ OPT_n = 1 << 2
};
- if (flags & OPT_n) {
- if (klogctl(8, NULL, xatoul_range(level, 0, 10)))
+ opt_complementary = "s+:n+"; /* numeric */
+ opts = getopt32(argv, "cs:n:", &len, &level);
+ if (opts & OPT_n) {
+ if (klogctl(8, NULL, (long) level))
bb_perror_msg_and_die("klogctl");
return EXIT_SUCCESS;
}
- len = (flags & OPT_s) ? xatoul_range(size, 2, INT_MAX) : 16384;
+ if (!(opts & OPT_s))
+ len = klogctl(10, NULL, 0); /* read ring buffer size */
+ if (len < 16*1024)
+ len = 16*1024;
+ if (len > 16*1024*1024)
+ len = 16*1024*1024;
+
buf = xmalloc(len);
- len = klogctl(3 + (flags & OPT_c), buf, len);
+ len = klogctl(3 + (opts & OPT_c), buf, len); /* read ring buffer */
if (len < 0)
bb_perror_msg_and_die("klogctl");
if (len == 0)
return EXIT_SUCCESS;
- /* Skip <#> at the start of lines, and make sure we end with a newline. */
+ /* Skip <#> at the start of lines, and make sure we end with a newline */
if (ENABLE_FEATURE_DMESG_PRETTY) {
int last = '\n';