diff options
| author | James Sullins <jcsullins@gmail.com> | 2012-06-24 07:07:42 -0500 |
|---|---|---|
| committer | Andrew Dodd <atd7@cornell.edu> | 2012-10-07 16:07:48 -0400 |
| commit | e1d9986814a12c00764b987e71d83f426bd280aa (patch) | |
| tree | 1676779e26db2aca8e88ebabae6d9e666a4c7c38 /toolbox/dmesg.c | |
| parent | f7ac9ae1c0dfccdbc441a5c64ae843bc3c56ff1d (diff) | |
| download | system_core-e1d9986814a12c00764b987e71d83f426bd280aa.tar.gz system_core-e1d9986814a12c00764b987e71d83f426bd280aa.tar.bz2 system_core-e1d9986814a12c00764b987e71d83f426bd280aa.zip | |
toolbox/dmesg: do not hardcode KLOG_BUF_LEN
Change-Id: Ia99654a53d6adfeba5a5088b7cff45c6e47b6188
Diffstat (limited to 'toolbox/dmesg.c')
| -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 e57f6077..9c73b00c 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; |
