diff options
author | Colin Cross <ccross@android.com> | 2013-04-06 12:51:35 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-04-06 12:51:35 -0700 |
commit | d3859e433d5a4e0da3f24851c5f5f6c9c8b97849 (patch) | |
tree | 589babe5f629d2159d77eea937299d4298929055 /toolbox | |
parent | a5ca229a4571f6df42c96e760257b7ca95c7fdeb (diff) | |
parent | 6e0b9ecb503b5611d815214e0a134ea0b1395089 (diff) | |
download | core-d3859e433d5a4e0da3f24851c5f5f6c9c8b97849.tar.gz core-d3859e433d5a4e0da3f24851c5f5f6c9c8b97849.tar.bz2 core-d3859e433d5a4e0da3f24851c5f5f6c9c8b97849.zip |
am 6e0b9ecb: Merge "toolbox/dmesg: do not hardcode KLOG_BUF_LEN"
* commit '6e0b9ecb503b5611d815214e0a134ea0b1395089':
toolbox/dmesg: do not hardcode KLOG_BUF_LEN
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/dmesg.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/toolbox/dmesg.c b/toolbox/dmesg.c index e57f6077f..9c73b00ca 100644 --- a/toolbox/dmesg.c +++ b/toolbox/dmesg.c @@ -5,15 +5,30 @@ #include <sys/klog.h> #include <string.h> -#define KLOG_BUF_SHIFT 17 /* CONFIG_LOG_BUF_SHIFT from our kernel */ -#define KLOG_BUF_LEN (1 << KLOG_BUF_SHIFT) +#define FALLBACK_KLOG_BUF_SHIFT 17 /* CONFIG_LOG_BUF_SHIFT from our kernel */ +#define FALLBACK_KLOG_BUF_LEN (1 << FALLBACK_KLOG_BUF_SHIFT) int dmesg_main(int argc, char **argv) { - char buffer[KLOG_BUF_LEN + 1]; - char *p = buffer; + char *buffer; + char *p; ssize_t ret; - int n, op; + int n, op, klog_buf_len; + + klog_buf_len = klogctl(KLOG_SIZE_BUFFER, 0, 0); + + if (klog_buf_len <= 0) { + klog_buf_len = FALLBACK_KLOG_BUF_LEN; + } + + buffer = (char *)malloc(klog_buf_len + 1); + + if (!buffer) { + perror("malloc"); + return EXIT_FAILURE; + } + + p = buffer; if((argc == 2) && (!strcmp(argv[1],"-c"))) { op = KLOG_READ_CLEAR; @@ -21,7 +36,7 @@ int dmesg_main(int argc, char **argv) op = KLOG_READ_ALL; } - n = klogctl(op, buffer, KLOG_BUF_LEN); + n = klogctl(op, buffer, klog_buf_len); if (n < 0) { perror("klogctl"); return EXIT_FAILURE; |