Fix dmesg printing on Linux

This commit is contained in:
sin 2013-08-09 19:05:38 +01:00
parent 63678c3235
commit 6253a46693
4 changed files with 32 additions and 2 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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 {