--- ./sysklogd/syslogd.c.klogd2 2006-03-13 15:05:03.000000000 +0100 +++ ./sysklogd/syslogd.c 2006-03-13 15:53:59.000000000 +0100 @@ -707,16 +707,62 @@ #endif /* SYSLOG_LISTEN_UDP */ #ifdef CONFIG_FEATURE_SYSLOG_INCLUDE_KLOG if (doKernelLog && FD_ISSET(klog_fd, &fds)) { - int i; + int i, j, msgptr, msgend; + int save, remain; - if ((i = read(klog_fd, tmpbuf + 8, TMP_BUF_SZ - 8)) > 0) { - memcpy(tmpbuf, "kernel: ", 8); - i += 8; - tmpbuf[i] = '\0'; - serveConnection(tmpbuf, i); - } else if (i < 0 && errno != EINTR && errno != EAGAIN) { - bb_perror_msg_and_die("/proc/kmsg read error"); - } + save = strlen("kernel: "); + remain = 0; + while (1) { + i = read(klog_fd, tmpbuf + save + remain, + TMP_BUF_SZ - save - remain - 1); + + if (i < 0) { + if (errno != EINTR && errno != EAGAIN) { + bb_perror_msg_and_die("/proc/kmsg read error"); + } + + /* we don't abort yet if we have some data + * remaining from a previous read + */ + + if (remain > 0) + i = 0; + else + break; + } + + /* there was some data remaining and there's nothing + * new, so we push the old data. + */ + if (i == 0) { + tmpbuf[save + remain] = 0; + memcpy(tmpbuf, "kernel: ", save); + serveConnection(tmpbuf, save + remain); + break; + } + + /* look for a line feed after remaining data */ + msgptr = save; + j = msgptr + remain; + msgend = j + i; + while (j < msgend) { + if (tmpbuf[j] != '\n') { + j++; + continue; + } + /* we have one complete message between msgptr and j */ + tmpbuf[j] = 0; + memcpy(tmpbuf + msgptr - save, + "kernel: ", save); + serveConnection(tmpbuf + msgptr - save, + j - msgptr + save); + msgptr = ++j; + } + remain = msgend - msgptr; + if (remain) { + memmove(tmpbuf + save, tmpbuf + msgptr, remain); + } + } /* end of while(1) */ } #endif } /* for main loop */