mirror of
git://git.suckless.org/ubase
synced 2024-12-24 23:52:34 +00:00
Fix dmesg printing on Linux
This commit is contained in:
parent
63678c3235
commit
6253a46693
5
dmesg.c
5
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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user