summaryrefslogtreecommitdiffstats
path: root/toolbox/dmesg.c
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commit4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53 (patch)
tree54fd1b2695a591d2306d41264df67c53077b752c /toolbox/dmesg.c
downloadsystem_core-4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53.zip
system_core-4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53.tar.gz
system_core-4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53.tar.bz2
Initial Contribution
Diffstat (limited to 'toolbox/dmesg.c')
-rw-r--r--toolbox/dmesg.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/toolbox/dmesg.c b/toolbox/dmesg.c
new file mode 100644
index 0000000..e57f607
--- /dev/null
+++ b/toolbox/dmesg.c
@@ -0,0 +1,43 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#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)
+
+int dmesg_main(int argc, char **argv)
+{
+ char buffer[KLOG_BUF_LEN + 1];
+ char *p = buffer;
+ ssize_t ret;
+ int n, op;
+
+ if((argc == 2) && (!strcmp(argv[1],"-c"))) {
+ op = KLOG_READ_CLEAR;
+ } else {
+ op = KLOG_READ_ALL;
+ }
+
+ n = klogctl(op, buffer, KLOG_BUF_LEN);
+ if (n < 0) {
+ perror("klogctl");
+ return EXIT_FAILURE;
+ }
+ buffer[n] = '\0';
+
+ while((ret = write(STDOUT_FILENO, p, n))) {
+ if (ret == -1) {
+ if (errno == EINTR)
+ continue;
+ perror("write");
+ return EXIT_FAILURE;
+ }
+ p += ret;
+ n -= ret;
+ }
+
+ return 0;
+}