From 03c2dbc7c25316c377dbf70bfff564070f0441d2 Mon Sep 17 00:00:00 2001 From: Milan Bartos Date: Thu, 15 Nov 2012 09:14:48 +0100 Subject: bugfix: imfile discarded some file parts File lines that were incomplete (LF missing) *at the time imfile polled the file* were partially discarded. That part of the line that was read without the LF was discarded, and the rest of the line was submitted in the next polling cycle. This is now changed so that the partial content is saved until the complete line is read. Note that the patch affects only read mode 0. --- ChangeLog | 8 ++++++++ runtime/stream.c | 27 ++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 077e2b6f..1c6d6e94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,14 @@ Version 7.2.2 [v7-stable] 2012-10-?? aborted on startup. Note that no segfault could happen if the initial startup went well (this was a problem with the config parser). closes: http://bugzilla.adiscon.com/show_bug.cgi?id=381 +- bugfix: imfile discarded some file parts + File lines that were incomplete (LF missing) *at the time imfile polled + the file* were partially discarded. That part of the line that was read + without the LF was discarded, and the rest of the line was submitted in + the next polling cycle. This is now changed so that the partial content + is saved until the complete line is read. Note that the patch affects + only read mode 0. + Thanks to Milan Bartos for providing the patch. ---------------------------------------------------------------------------- Version 7.2.1 [v7-stable] 2012-10-29 - bugfix: ruleset()-object did only support a single statement diff --git a/runtime/stream.c b/runtime/stream.c index 906a45fc..52d143de 100644 --- a/runtime/stream.c +++ b/runtime/stream.c @@ -589,19 +589,40 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, int mode) uchar c; uchar finished; + rsRetVal readCharRet; + + static cstr_t *prevCStr = NULL; + ASSERT(pThis != NULL); ASSERT(ppCStr != NULL); CHKiRet(cstrConstruct(ppCStr)); - /* now read the line */ + /* append previous message to current message if necessary */ + if (prevCStr != NULL) { + CHKiRet(cstrAppendCStr(*ppCStr, prevCStr)); + } + CHKiRet(strmReadChar(pThis, &c)); if (mode == 0){ - while(c != '\n') { + while(c != '\n') { CHKiRet(cstrAppendChar(*ppCStr, c)); - CHKiRet(strmReadChar(pThis, &c)); + + readCharRet = strmReadChar(pThis, &c); + + /* end of file has been reached without \n */ + if (readCharRet == RS_RET_EOF) { + CHKiRet(rsCStrConstructFromCStr(&prevCStr, *ppCStr)); + } + + CHKiRet(readCharRet); } CHKiRet(cstrFinalize(*ppCStr)); + /* message has been finalized, destruct message from previous */ + if (prevCStr) { + cstrDestruct(&prevCStr); + prevCStr = NULL; + } } if (mode == 1){ finished=0; -- cgit v1.2.3