X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fstdout-syslog-bridge.c;h=9a0408819ec964a1626cadcd2090268065c8323f;hb=66ccd0387e528567dff92239e85c962d2f140ef1;hp=48a301f6a711ffd2fb8d8213b4868abfed8fd70a;hpb=346bce1f4cff0096177c613987cdc80fa4ec134e;p=elogind.git diff --git a/src/stdout-syslog-bridge.c b/src/stdout-syslog-bridge.c index 48a301f6a..9a0408819 100644 --- a/src/stdout-syslog-bridge.c +++ b/src/stdout-syslog-bridge.c @@ -88,7 +88,7 @@ struct Stream { bool prefix:1; bool tee_console:1; - char buffer[LINE_MAX]; + char buffer[LINE_MAX+1]; size_t length; LIST_FIELDS(Stream, stream); @@ -111,9 +111,9 @@ static int stream_log(Stream *s, char *p, usec_t ts) { if (*p == 0) return 0; - /* Patch in LOG_USER facility if necessary */ + /* Patch in configured facility if necessary */ if ((priority & LOG_FACMASK) == 0) - priority = LOG_USER | LOG_PRI(priority); + priority = (s->priority & LOG_FACMASK) | priority; /* * The format glibc uses to talk to the syslog daemon is: @@ -321,16 +321,25 @@ static int stream_scan(Stream *s, usec_t ts) { p = s->buffer; remaining = s->length; for (;;) { - char *newline; - - if (!(newline = memchr(p, '\n', remaining))) - break; + char *end; + size_t skip; + + end = memchr(p, '\n', remaining); + if (!end) { + if (remaining >= LINE_MAX) { + end = p + LINE_MAX; + skip = LINE_MAX; + } else + break; + } else + skip = end - p + 1; - *newline = 0; + *end = 0; - if ((r = stream_line(s, p, ts)) >= 0) { - remaining -= newline-p+1; - p = newline+1; + r = stream_line(s, p, ts); + if (r >= 0) { + remaining -= skip; + p += skip; } } @@ -347,7 +356,8 @@ static int stream_process(Stream *s, usec_t ts) { int r; assert(s); - if ((l = read(s->fd, s->buffer+s->length, LINE_MAX-s->length)) < 0) { + l = read(s->fd, s->buffer+s->length, LINE_MAX-s->length); + if (l < 0) { if (errno == EAGAIN) return 0;