summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-09-20 02:46:04 +0200
committerLennart Poettering <lennart@poettering.net>2011-09-20 02:46:04 +0200
commita94e09a5b935a3fb64a4e2c9f22220899ff40294 (patch)
tree01151333f82561a9964199d1fe734d7bd27a0638
parent00ca7f07825dd3d0a8820eafdd8fcdbd2c7809d9 (diff)
stdout-syslog-bridge: properly handle overly long log lines
-rw-r--r--src/stdout-syslog-bridge.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/stdout-syslog-bridge.c b/src/stdout-syslog-bridge.c
index 7358a42f70..9a0408819e 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);
@@ -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;