diff options
author | Michael Biebl <biebl@debian.org> | 2012-11-16 17:43:41 +0100 |
---|---|---|
committer | Michael Biebl <biebl@debian.org> | 2012-11-16 17:43:41 +0100 |
commit | 792f31fe29bef0c9960d3951f266fc7b2c70a2fc (patch) | |
tree | e82d85662e0ba5fc7e4ed0838011ea2a0ac0b44b /runtime/stream.c | |
parent | 05bd88b115965e17631a4af10c84d71622fe4e3d (diff) | |
download | rsyslog-792f31fe29bef0c9960d3951f266fc7b2c70a2fc.tar.gz |
Imported Upstream version 7.2.2upstream/7.2.2
Diffstat (limited to 'runtime/stream.c')
-rw-r--r-- | runtime/stream.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/runtime/stream.c b/runtime/stream.c index 742799d..193d14d 100644 --- a/runtime/stream.c +++ b/runtime/stream.c @@ -585,25 +585,33 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, int mode) * mode = 2 LF <not whitespace> mode, a log line starts at the beginning of a line, but following lines that are indented are part of the same log entry * This modal interface is not nearly as flexible as being able to define a regex for when a new record starts, but it's also not nearly as hard (or as slow) to implement */ - DEFiRet; uchar c; uchar finished; + rsRetVal readCharRet; + DEFiRet; ASSERT(pThis != NULL); ASSERT(ppCStr != NULL); CHKiRet(cstrConstruct(ppCStr)); - - /* now read the line */ CHKiRet(strmReadChar(pThis, &c)); - if (mode == 0){ - while(c != '\n') { + + if(mode == 0) { + /* append previous message to current message if necessary */ + if(pThis->prevLineSegment != NULL) { + CHKiRet(cstrAppendCStr(*ppCStr, pThis->prevLineSegment)); + cstrDestruct(&pThis->prevLineSegment); + } + while(c != '\n') { CHKiRet(cstrAppendChar(*ppCStr, c)); - CHKiRet(strmReadChar(pThis, &c)); + readCharRet = strmReadChar(pThis, &c); + if(readCharRet == RS_RET_EOF) {/* end of file reached without \n? */ + CHKiRet(rsCStrConstructFromCStr(&pThis->prevLineSegment, *ppCStr)); + } + CHKiRet(readCharRet); } CHKiRet(cstrFinalize(*ppCStr)); - } - if (mode == 1){ + } else if(mode == 1) { finished=0; while(finished == 0){ if(c != '\n') { @@ -624,8 +632,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, int mode) } } CHKiRet(cstrFinalize(*ppCStr)); - } - if (mode == 2){ + } else if(mode == 2) { /* indented follow-up lines */ finished=0; while(finished == 0){ @@ -678,6 +685,7 @@ BEGINobjConstruct(strm) /* be sure to specify the object type also in END macro! pThis->sType = STREAMTYPE_FILE_SINGLE; pThis->sIOBufSize = glblGetIOBufSize(); pThis->tOpenMode = 0600; + pThis->prevLineSegment = NULL; ENDobjConstruct(strm) @@ -1128,6 +1136,7 @@ strmPhysWrite(strm_t *pThis, uchar *pBuf, size_t lenBuf) DEFiRet; ISOBJ_TYPE_assert(pThis, strm); + DBGPRINTF("strmPhysWrite, stream %p, len %d\n", pThis, (int) lenBuf); if(pThis->fd == -1) CHKiRet(strmOpenFile(pThis)); @@ -1584,6 +1593,8 @@ static rsRetVal strmSerialize(strm_t *pThis, strm_t *pStrm) l = pThis->iCurrOffs; objSerializeSCALAR_VAR(pStrm, iCurrOffs, INT64, l); + objSerializePTR(pStrm, prevLineSegment, PSZ); + CHKiRet(obj.EndSerialize(pStrm)); finalize_it: @@ -1689,6 +1700,8 @@ static rsRetVal strmSetProperty(strm_t *pThis, var_t *pProp) CHKiRet(strmSetiFileNumDigits(pThis, pProp->val.num)); } else if(isProp("bDeleteOnClose")) { CHKiRet(strmSetbDeleteOnClose(pThis, pProp->val.num)); + } else if(isProp("prevLineSegment")) { + CHKiRet(rsCStrConstructFromCStr(&pThis->prevLineSegment, pProp->val.pStr)); } finalize_it: |