summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-10 07:03:22 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-10 07:03:22 +0000
commitc247f4e02771960f5c880dc50a3003f786faefac (patch)
treed1c5079827af77c703b77de5d6199174242e0ce2 /stream.c
parentdee5485ade5b77748f2cebcd6b65ea71f01123f8 (diff)
downloadrsyslog-c247f4e02771960f5c880dc50a3003f786faefac.tar.gz
rsyslog-c247f4e02771960f5c880dc50a3003f786faefac.tar.xz
rsyslog-c247f4e02771960f5c880dc50a3003f786faefac.zip
changed queue file name generation (to be more generic)
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/stream.c b/stream.c
index 0f224787..b8a85463 100644
--- a/stream.c
+++ b/stream.c
@@ -73,7 +73,7 @@ rsRetVal strmOpenFile(strm_t *pThis, int flags, mode_t mode)
ABORT_FINALIZE(RS_RET_FILE_PREFIX_MISSING);
CHKiRet(genFileName(&pThis->pszCurrFName, pThis->pszDir, pThis->lenDir,
- pThis->pszFilePrefix, pThis->lenFilePrefix, pThis->iCurrFNum, (uchar*) "qf", 2));
+ pThis->pszFilePrefix, pThis->lenFilePrefix, pThis->iCurrFNum));
pThis->fd = open((char*)pThis->pszCurrFName, flags, mode); // TODO: open modes!
pThis->iCurrOffs = 0;
@@ -112,20 +112,24 @@ static rsRetVal strmCloseFile(strm_t *pThis)
}
-/* switch to next strm file */
+/* switch to next strm file
+ * This method must only be called if we are in a multi-file mode!
+ */
rsRetVal strmNextFile(strm_t *pThis)
{
DEFiRet;
dbgprintf("strmNextFile in\n");
assert(pThis != NULL);
+ assert(pThis->iMaxFiles != 0);
+
CHKiRet(strmCloseFile(pThis));
/* we do modulo 1,000,000 so that the file number is always at most 6 digits. If we have a million
* or more strm files, something is awfully wrong and it is OK if we run into problems in that
* situation ;) -- rgerhards, 2008-01-09
*/
- pThis->iCurrFNum = (pThis->iCurrFNum + 1) % 1000000;
+ pThis->iCurrFNum = (pThis->iCurrFNum + 1) % pThis->iMaxFiles;
finalize_it:
dbgprintf("strmNextFile out %d\n", iRet);
@@ -173,9 +177,14 @@ rsRetVal strmReadChar(strm_t *pThis, uchar *pC)
pThis->iBufPtrMax = read(pThis->fd, pThis->pIOBuf, STRM_IOBUF_SIZE);
dbgprintf("strmReadChar read %d bytes from file %d\n", pThis->iBufPtrMax, pThis->fd);
if(pThis->iBufPtrMax == 0) {
-// TODO: only when single file! ABORT_FINALIZE(RS_RET_EOF);
- dbgprintf("Stream 0x%lx: EOF on file %d\n", (unsigned long) pThis, pThis->fd);
- CHKiRet(strmNextFile(pThis));
+ if(pThis->iMaxFiles == 0)
+ ABORT_FINALIZE(RS_RET_EOF);
+ else {
+ /* we have multiple files and need to switch to the next one */
+ /* TODO: think about emulating EOF in this case (not yet needed) */
+ dbgprintf("Stream 0x%lx: EOF on file %d\n", (unsigned long) pThis, pThis->fd);
+ CHKiRet(strmNextFile(pThis));
+ }
} else if(pThis->iBufPtrMax < 0)
ABORT_FINALIZE(RS_RET_IO_ERROR);
else
@@ -343,6 +352,7 @@ finalize_it:
/* simple ones first */
DEFpropSetMeth(strm, bDeleteOnClose, int)
DEFpropSetMeth(strm, iMaxFileSize, int)
+DEFpropSetMeth(strm, iMaxFiles, int)
/* set the stream's file prefix
* The passed-in string is duplicated. So if the caller does not need