Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e8cd0cf authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Lose dmesg to toybox.

Change-Id: I29a6bf5e628e29e9b635fac2b23106220e36d6a3
parent c0ac9313
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -120,7 +120,6 @@ OUR_TOOLS := \
    cmp \
    date \
    df \
    dmesg \
    getenforce \
    getevent \
    getprop \

toolbox/dmesg.c

deleted100644 → 0
+0 −58
Original line number Diff line number Diff line
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <sys/klog.h>
#include <string.h>

#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;
    char *p;
    ssize_t ret;
    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;
    } 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;
}