summaryrefslogtreecommitdiffstats
path: root/plugins/imfile
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-10-20 16:19:18 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2010-10-20 16:19:18 +0200
commit950fe206f84322bdff755988403a9d4017ec26f4 (patch)
treeabd33a27f155d0e9090d5f7c6e52a199045d9249 /plugins/imfile
parentb8ffbecb7825f36528487d1e5fd67dd28ba6ce1d (diff)
parentbd157a7d698f420ea3a9459fc90dd930c54a5e54 (diff)
downloadrsyslog-950fe206f84322bdff755988403a9d4017ec26f4.tar.gz
rsyslog-950fe206f84322bdff755988403a9d4017ec26f4.tar.xz
rsyslog-950fe206f84322bdff755988403a9d4017ec26f4.zip
Merge branch 'v5-devel'
Conflicts: plugins/imfile/imfile.c
Diffstat (limited to 'plugins/imfile')
-rw-r--r--plugins/imfile/imfile.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c
index 6eecd9af..6b1a189d 100644
--- a/plugins/imfile/imfile.c
+++ b/plugins/imfile/imfile.c
@@ -67,15 +67,21 @@ typedef struct fileInfo_s {
uchar *pszStateFile; /* file in which state between runs is to be stored */
int iFacility;
int iSeverity;
+ int nRecords; /**< How many records did we process before persisting the stream? */
+ int iPersistStateInterval; /**< how often should state be persisted? (0=on close only) */
strm_t *pStrm; /* its stream (NULL if not assigned) */
} fileInfo_t;
+/* forward definitions */
+static rsRetVal persistStrmState(fileInfo_t *pInfo);
+
/* config variables */
static uchar *pszFileName = NULL;
static uchar *pszFileTag = NULL;
static uchar *pszStateFile = NULL;
static int iPollInterval = 10; /* number of seconds to sleep when there was no file activity */
+static int iPersistStateInterval = 0; /* how often if state file to be persisted? (default 0->never) */
static int iFacility = 128; /* local0 */
static int iSeverity = 5; /* notice, as of rfc 3164 */
@@ -153,10 +159,9 @@ openFile(fileInfo_t *pThis)
CHKiRet(strm.SeekCurrOffs(pThis->pStrm));
- /* OK, we could successfully read the file, so we now can request that it be deleted.
- * If we need it again, it will be written on the next shutdown.
+ /* note: we do not delete the state file, so that the last position remains
+ * known even in the case that rsyslogd aborts for some reason (like powerfail)
*/
- psSF->bDeleteOnClose = 1;
finalize_it:
if(psSF != NULL)
@@ -210,6 +215,10 @@ static rsRetVal pollFile(fileInfo_t *pThis, int *pbHadFileData)
*pbHadFileData = 1; /* this is just a flag, so set it and forget it */
CHKiRet(enqLine(pThis, pCStr)); /* process line */
rsCStrDestruct(&pCStr); /* discard string (must be done by us!) */
+ if(pThis->iPersistStateInterval > 0 && pThis->nRecords++ >= pThis->iPersistStateInterval) {
+ persistStrmState(pThis);
+ pThis->nRecords = 0;
+ }
}
finalize_it:
@@ -477,6 +486,9 @@ static rsRetVal addMonitor(void __attribute__((unused)) *pVal, uchar *pNewVal)
pThis->iSeverity = iSeverity;
pThis->iFacility = iFacility;
+ pThis->iPersistStateInterval = iPersistStateInterval;
+ pThis->nRecords = 0;
+ iPersistStateInterval = 0;
} else {
errmsg.LogError(0, RS_RET_OUT_OF_DESRIPTORS, "Too many file monitors configured - ignoring this one");
ABORT_FINALIZE(RS_RET_OUT_OF_DESRIPTORS);
@@ -522,6 +534,8 @@ CODEmodInit_QueryRegCFSLineHdlr
NULL, &iFacility, STD_LOADABLE_MODULE_ID, eConfObjGlobal));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilepollinterval", 0, eCmdHdlrInt,
NULL, &iPollInterval, STD_LOADABLE_MODULE_ID, eConfObjGlobal));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilepersiststateinterval", 0, eCmdHdlrInt,
+ NULL, &iPersistStateInterval, STD_LOADABLE_MODULE_ID, eConfObjGlobal));
/* that command ads a new file! */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputrunfilemonitor", 0, eCmdHdlrGetWord,
addMonitor, NULL, STD_LOADABLE_MODULE_ID, eConfObjGlobal));