Fix #26: handle Linux EPIPE on /dev/kmsg
When Linux CONFIG_LOG_BUF_SHIFT is set too low, or too many messages are generated by the kernel, /dev/kmsg will overflow. This is signaled with EPIPE to userspace. We can use the seqnos to figure out how many we've lost, but seqnos are currently ignored. > In case records get overwritten while /dev/kmsg is held open, or > records get faster overwritten than they are read, the next read() > will return -EPIPE and the current reading position gets updated to > the next available record. The passed sequence numbers allow the log > consumer to calculate the amount of lost messages. -- https://lwn.net/Articles/490690/ Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
parent
22d26c5945
commit
3e4000b25a
@ -469,9 +469,21 @@ static void kernel_cb(int fd, void *arg)
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
line[i + len] = '\0';
|
line[i + len] = '\0';
|
||||||
} else {
|
} else {
|
||||||
if (i < 0 && errno != EINTR && errno != EAGAIN) {
|
if (i < 0) {
|
||||||
|
switch (errno) {
|
||||||
|
case EPIPE: /* linux, log buffer overrun */
|
||||||
|
ERRX("Kernel log buffer filling up too quick, "
|
||||||
|
"or too small log buffer, "
|
||||||
|
"adjust kernel CONFIG_LOG_BUF_SHIFT");
|
||||||
|
case EINTR:
|
||||||
|
case EAGAIN:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
ERR("klog read()");
|
ERR("klog read()");
|
||||||
socket_close(fd);
|
socket_close(fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user