X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournal-remote-parse.c;h=dbdf02aa3c6ba5d8b6ad67858dedb8a4fbc0f6a7;hb=948a6f8eb42c85d2b96e9b5817fcfa29ad4752ae;hp=ee2260c5a961e2175f1702a06a66bcee1106ab7d;hpb=fdfccdbc985944a57017a25f44dd6acc1a937bab;p=elogind.git diff --git a/src/journal/journal-remote-parse.c b/src/journal/journal-remote-parse.c index ee2260c5a..dbdf02aa3 100644 --- a/src/journal/journal-remote-parse.c +++ b/src/journal/journal-remote-parse.c @@ -40,7 +40,7 @@ void source_free(RemoteSource *source) { static int get_line(RemoteSource *source, char **line, size_t *size) { ssize_t n, remain; - char *c; + char *c = NULL; char *newbuf = NULL; size_t newsize = 0; @@ -49,11 +49,17 @@ static int get_line(RemoteSource *source, char **line, size_t *size) { assert(source->filled <= source->size); assert(source->buf == NULL || source->size > 0); - c = memchr(source->buf, '\n', source->filled); + if (source->buf) + c = memchr(source->buf, '\n', source->filled); + if (c != NULL) goto docopy; resize: + if (source->fd < 0) + /* we have to wait for some data to come to us */ + return -EWOULDBLOCK; + if (source->size - source->filled < LINE_CHUNK) { // XXX: add check for maximum line length @@ -100,6 +106,20 @@ static int get_line(RemoteSource *source, char **line, size_t *size) { return 1; } +int push_data(RemoteSource *source, const char *data, size_t size) { + assert(source); + assert(source->state != STATE_EOF); + + if (!GREEDY_REALLOC(source->buf, source->size, + source->filled + size)) + return log_oom(); + + memcpy(source->buf + source->filled, data, size); + source->filled += size; + + return 0; +} + static int fill_fixed_size(RemoteSource *source, void **data, size_t size) { int n; char *newbuf = NULL; @@ -116,6 +136,10 @@ static int fill_fixed_size(RemoteSource *source, void **data, size_t size) { assert(data); while(source->filled < size) { + if (source->fd < 0) + /* we have to wait for some data to come to us */ + return -EWOULDBLOCK; + if (!GREEDY_REALLOC(source->buf, source->size, size)) return log_oom(); @@ -153,7 +177,7 @@ static int fill_fixed_size(RemoteSource *source, void **data, size_t size) { static int get_data_size(RemoteSource *source) { int r; - void _cleanup_free_ *data = NULL; + _cleanup_free_ void *data = NULL; assert(source); assert(source->state == STATE_DATA_START); @@ -191,7 +215,7 @@ static int get_data_data(RemoteSource *source, void **data) { static int get_data_newline(RemoteSource *source) { int r; - char _cleanup_free_ *data = NULL; + _cleanup_free_ char *data = NULL; assert(source); assert(source->state == STATE_DATA_FINISH);