summaryrefslogtreecommitdiffstats
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
parentdee5485ade5b77748f2cebcd6b65ea71f01123f8 (diff)
downloadrsyslog-c247f4e02771960f5c880dc50a3003f786faefac.tar.gz
rsyslog-c247f4e02771960f5c880dc50a3003f786faefac.tar.xz
rsyslog-c247f4e02771960f5c880dc50a3003f786faefac.zip
changed queue file name generation (to be more generic)
-rw-r--r--queue.c9
-rwxr-xr-xsrUtils.c16
-rwxr-xr-xsrUtils.h3
-rw-r--r--stream.c22
-rw-r--r--stream.h2
5 files changed, 34 insertions, 18 deletions
diff --git a/queue.c b/queue.c
index 834dab8b..272161a9 100644
--- a/queue.c
+++ b/queue.c
@@ -189,6 +189,13 @@ static rsRetVal qDelLinkedList(queue_t *pThis, void **ppUsr)
/* -------------------- disk -------------------- */
+/* disk queue constructor.
+ * Note that we use a file limit of 10,000,000 files. That number should never pose a
+ * problem. If so, I guess the user has a design issue... But of course, the code can
+ * always be changed (though it would probably be more appropriate to increase the
+ * allowed file size at this point - that should be a config setting...
+ * rgerhards, 2008-01-10
+ */
static rsRetVal qConstructDisk(queue_t *pThis)
{
DEFiRet;
@@ -197,11 +204,13 @@ static rsRetVal qConstructDisk(queue_t *pThis)
CHKiRet(strmConstruct(&pThis->tVars.disk.pWrite));
CHKiRet(strmSetDir(pThis->tVars.disk.pWrite, pszSpoolDirectory, strlen((char*)pszSpoolDirectory)));
+ CHKiRet(strmSetiMaxFiles(pThis->tVars.disk.pWrite, 10000000));
CHKiRet(strmConstructFinalize(pThis->tVars.disk.pWrite));
CHKiRet(strmConstruct(&pThis->tVars.disk.pRead));
CHKiRet(strmSetbDeleteOnClose(pThis->tVars.disk.pRead, 1));
CHKiRet(strmSetDir(pThis->tVars.disk.pRead, pszSpoolDirectory, strlen((char*)pszSpoolDirectory)));
+ CHKiRet(strmSetiMaxFiles(pThis->tVars.disk.pRead, 10000000));
CHKiRet(strmConstructFinalize(pThis->tVars.disk.pRead));
finalize_it:
diff --git a/srUtils.c b/srUtils.c
index b500cab3..fc0869be 100755
--- a/srUtils.c
+++ b/srUtils.c
@@ -240,13 +240,12 @@ void skipWhiteSpace(uchar **pp)
/* generate a file name from four parts:
- * <directory name>/<prefix>-<number>.<type>
+ * <directory name>/<name>.<number>
* If number is negative, it is not used. If any of the strings is
* NULL, an empty string is used instead. Length must be provided.
* rgerhards, 2008-01-03
*/
-rsRetVal genFileName(uchar **ppName, uchar *pDirName, size_t lenDirName,
- uchar *pPrefix, size_t lenPrefix, long lNum, uchar *pType, size_t lenType)
+rsRetVal genFileName(uchar **ppName, uchar *pDirName, size_t lenDirName, uchar *pFName, size_t lenFName, long lNum)
{
DEFiRet;
uchar *pName;
@@ -259,10 +258,10 @@ rsRetVal genFileName(uchar **ppName, uchar *pDirName, size_t lenDirName,
szBuf[0] = '\0';
lenBuf = 0;
} else {
- lenBuf = snprintf((char*)szBuf, sizeof(szBuf), "-%ld", lNum);
+ lenBuf = snprintf((char*)szBuf, sizeof(szBuf), ".%ld", lNum);
}
- lenName = lenDirName + 1 + lenPrefix + lenBuf + 1 + lenType + 1; /* last +1 for \0 char! */
+ lenName = lenDirName + 1 + lenName + lenBuf + 1; /* last +1 for \0 char! */
if((pName = malloc(sizeof(uchar) * lenName)) == NULL)
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
@@ -270,15 +269,12 @@ rsRetVal genFileName(uchar **ppName, uchar *pDirName, size_t lenDirName,
memcpy(pName, pDirName, lenDirName);
pNameWork = pName + lenDirName;
*pNameWork++ = '/';
- memcpy(pNameWork, pPrefix, lenPrefix);
- pNameWork += lenPrefix;
+ memcpy(pNameWork, pFName, lenFName);
+ pNameWork += lenFName;
if(lenBuf > 0) {
memcpy(pNameWork, szBuf, lenBuf);
pNameWork += lenBuf;
}
- *pNameWork++ = '.';
- memcpy(pNameWork, pType, lenType);
- pNameWork += lenType;
*pNameWork = '\0';
*ppName = pName;
diff --git a/srUtils.h b/srUtils.h
index f3423d2d..e7912907 100755
--- a/srUtils.h
+++ b/srUtils.h
@@ -64,6 +64,5 @@ int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode, uid_t uid, gi
int execProg(uchar *program, int wait, uchar *arg);
void skipWhiteSpace(uchar **pp);
-rsRetVal genFileName(uchar **ppName, uchar *pDirName, size_t lenDirName,
- uchar *pPrefix, size_t lenPrefix, long lNum, uchar *pType, size_t lenType);
+rsRetVal genFileName(uchar **ppName, uchar *pDirName, size_t lenDirName, uchar *pName, size_t lenName, long lNum);
#endif
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
diff --git a/stream.h b/stream.h
index dd8f7d5b..f31be44e 100644
--- a/stream.h
+++ b/stream.h
@@ -71,6 +71,7 @@ typedef struct strm_s {
int iModeOpenOS;
size_t iMaxFileSize;/* maximum size a file may grow to */
int bDeleteOnClose; /* set to 1 to auto-delete on close -- be careful with that setting! */
+ int iMaxFiles; /* maximum number of files if a circular mode is in use */
} strm_t;
#define STRM_IOBUF_SIZE 4096 /* size of the IO buffer */
@@ -90,5 +91,6 @@ rsRetVal strmSetDir(strm_t *pThis, uchar *pszDir, size_t iLenDir);
PROTOTYPEObjClassInit(strm);
PROTOTYPEpropSetMeth(strm, bDeleteOnClose, int);
PROTOTYPEpropSetMeth(strm, iMaxFileSize, int);
+PROTOTYPEpropSetMeth(strm, iMaxFiles, int);
#endif /* #ifndef STREAM_H_INCLUDED */