Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: android-4.0.1_…
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 44 lines (37 sloc) 0.856 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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;
}
Something went wrong with that request. Please try again.