X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal-remote%2Fjournal-remote-parse.c;h=14af55ca552465ad4e276e8a52871781fdb11ed1;hb=4a0a6ac03864998c83918175609275df712a5a05;hp=fe21bd3e1d91baca4a9294076e3617e065f8bfb9;hpb=851d4e2a67efb2c8777df151b697391ff1a76af0;p=elogind.git diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c index fe21bd3e1..14af55ca5 100644 --- a/src/journal-remote/journal-remote-parse.c +++ b/src/journal-remote/journal-remote-parse.c @@ -22,7 +22,7 @@ #include "journal-remote-parse.h" #include "journald-native.h" -#define LINE_CHUNK 1024u +#define LINE_CHUNK 8*1024u void source_free(RemoteSource *source) { if (!source) @@ -30,11 +30,14 @@ void source_free(RemoteSource *source) { if (source->fd >= 0) { log_debug("Closing fd:%d (%s)", source->fd, source->name); - close(source->fd); + safe_close(source->fd); } free(source->name); free(source->buf); iovw_free_contents(&source->iovw); + + sd_event_source_unref(source->event); + free(source); } @@ -68,13 +71,17 @@ static int get_line(RemoteSource *source, char **line, size_t *size) { if (source->size - source->filled < LINE_CHUNK && !GREEDY_REALLOC(source->buf, source->size, - MAX(source->filled + LINE_CHUNK, DATA_SIZE_MAX))) + MIN(source->filled + LINE_CHUNK, DATA_SIZE_MAX))) return log_oom(); - assert(source->size - source->filled >= LINE_CHUNK); + assert(source->size - source->filled >= LINE_CHUNK || + source->size == DATA_SIZE_MAX); + + // FIXME: the buffer probably needs to be bigger than DATA_SIZE_MAX + // to accomodate such big fields. n = read(source->fd, source->buf + source->filled, - MAX(source->size, DATA_SIZE_MAX) - source->filled); + source->size - source->filled); if (n < 0) { if (errno != EAGAIN && errno != EWOULDBLOCK) log_error("read(%d, ..., %zd): %m", source->fd,