ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit 6253a466939b323cbc6f6d474d6d6d13f8f02e47
parent 63678c3235c7267a8fb5384737a8ed64ea345c51
Author: sin <sin@2f30.org>
Date:   Fri,  9 Aug 2013 19:05:38 +0100

Fix dmesg printing on Linux

Diffstat:
Mdmesg.c | 5+++--
Mlinux/syslog.c | 22++++++++++++++++++++++
Mopenbsd/syslog.c | 6++++++
Mubase.h | 1+
4 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/dmesg.c b/dmesg.c @@ -31,8 +31,9 @@ main(int argc, char *argv[]) n = syslog_read(buf, n); if (n < 0) eprintf("syslog_read:"); - if (write(STDOUT_FILENO, buf, n) != n) - eprintf("write:"); + n = syslog_show(STDOUT_FILENO, buf, n); + if (n < 0) + eprintf("syslog_show:"); free(buf); return 0; } diff --git a/linux/syslog.c b/linux/syslog.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include <sys/klog.h> +#include <unistd.h> #include <stdio.h> enum { @@ -18,3 +19,24 @@ syslog_read(void *buf, size_t n) { return klogctl(SYSLOG_ACTION_READ_ALL, buf, n); } + +int +syslog_show(int fd, const void *buf, size_t n) +{ + int last = '\n'; + const char *p = buf; + size_t i; + + for (i = 0; i < n; ) { + if (last == '\n' && p[i] == '<') { + i += 2; + if (i + 1 < n && p[i + 1] == '>') + i++; + } else { + if (write(fd, &p[i], 1) != 1) + return -1; + } + last = p[i++]; + } + return 0; +} diff --git a/openbsd/syslog.c b/openbsd/syslog.c @@ -38,3 +38,9 @@ syslog_read(void *buf, size_t n) memmove(buf, ((struct msgbuf *)buf)->msg_bufc, n); return n; } + +int +syslog_show(int fd, const void *buf, size_t n) +{ + return write(fd, buf, n); +} diff --git a/ubase.h b/ubase.h @@ -11,6 +11,7 @@ int grabmntinfo(struct mntinfo **minfo); /* syslog.c */ int syslog_size(void); int syslog_read(void *buf, size_t n); +int syslog_show(int fd, const void *buf, size_t n); /* umount.c */ enum {