summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--plugins/imfile/imfile.c77
2 files changed, 52 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index d5fb029a..d0dd19f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
---------------------------------------------------------------------------
Version 7.5.5 [devel] 2013-10-??
+- imfile: permit to monitor an unlimited number of files
- imptcp: add "defaultTZ" input parameter
- imudp: support for multiple receiver threads added
- imudp: add "dfltTZ" input config parameter
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c
index bb6ea501..8e041c30 100644
--- a/plugins/imfile/imfile.c
+++ b/plugins/imfile/imfile.c
@@ -72,8 +72,14 @@ static int bLegacyCnfModGlobalsPermitted;/* are legacy module-global config para
#define NUM_MULTISUB 1024 /* default max number of submits */
#define DFLT_PollInterval 10
+#define INIT_FILE_TAB_SIZE 4 /* default file table size - is extended as needed, use 2^x value */
+
+/* this structure is used in pure polling mode as well one of the support
+ * structures for inotify.
+ */
typedef struct fileInfo_s {
uchar *pszFileName;
+ uchar *pszBasename; /* our files basename part */
uchar *pszTag;
size_t lenTag;
uchar *pszStateFile; /* file in which state between runs is to be stored */
@@ -138,8 +144,8 @@ static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current l
static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current load process */
static int iFilPtr = 0; /* number of files to be monitored; pointer to next free spot during config */
-#define MAX_INPUT_FILES 100
-static fileInfo_t files[MAX_INPUT_FILES];
+static fileInfo_t *files = NULL;
+static int currMaxFiles;
static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this input */
@@ -476,33 +482,43 @@ static inline rsRetVal
addListner(instanceConf_t *inst)
{
DEFiRet;
+ int newMax;
+ fileInfo_t *newFileTab;
fileInfo_t *pThis;
- if(iFilPtr < MAX_INPUT_FILES) {
- pThis = &files[iFilPtr];
- pThis->pszFileName = (uchar*) strdup((char*) inst->pszFileName);
- pThis->pszTag = (uchar*) strdup((char*) inst->pszTag);
- pThis->lenTag = ustrlen(pThis->pszTag);
- pThis->pszStateFile = (uchar*) strdup((char*) inst->pszStateFile);
-
- CHKiRet(ratelimitNew(&pThis->ratelimiter, "imfile", (char*)inst->pszFileName));
- CHKmalloc(pThis->multiSub.ppMsgs = MALLOC(inst->nMultiSub * sizeof(msg_t*)));
- pThis->multiSub.maxElem = inst->nMultiSub;
- pThis->multiSub.nElem = 0;
- pThis->iSeverity = inst->iSeverity;
- pThis->iFacility = inst->iFacility;
- pThis->maxLinesAtOnce = inst->maxLinesAtOnce;
- pThis->iPersistStateInterval = inst->iPersistStateInterval;
- pThis->readMode = inst->readMode;
- pThis->escapeLF = inst->escapeLF;
- pThis->pRuleset = inst->pBindRuleset;
- pThis->nRecords = 0;
- } else {
- errmsg.LogError(0, RS_RET_OUT_OF_DESRIPTORS,
- "Too many file monitors configured - ignoring %s",
- inst->pszFileName);
- ABORT_FINALIZE(RS_RET_OUT_OF_DESRIPTORS);
+ if(iFilPtr == currMaxFiles) {
+ newMax = 2 * currMaxFiles;
+ newFileTab = realloc(files, newMax * sizeof(fileInfo_t));
+ if(newFileTab == NULL) {
+ errmsg.LogError(0, RS_RET_OUT_OF_MEMORY,
+ "cannot alloc memory to monitor file '%s' - ignoring",
+ inst->pszFileName);
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ }
+ files = newFileTab;
+ currMaxFiles = newMax;
+ DBGPRINTF("imfile: increased file table to %d entries\n", currMaxFiles);
}
+
+ /* if we reach this point, there is space in the file table for the new entry */
+ pThis = &files[iFilPtr];
+ pThis->pszFileName = (uchar*) strdup((char*) inst->pszFileName);
+ pThis->pszTag = (uchar*) strdup((char*) inst->pszTag);
+ pThis->lenTag = ustrlen(pThis->pszTag);
+ pThis->pszStateFile = (uchar*) strdup((char*) inst->pszStateFile);
+
+ CHKiRet(ratelimitNew(&pThis->ratelimiter, "imfile", (char*)inst->pszFileName));
+ CHKmalloc(pThis->multiSub.ppMsgs = MALLOC(inst->nMultiSub * sizeof(msg_t*)));
+ pThis->multiSub.maxElem = inst->nMultiSub;
+ pThis->multiSub.nElem = 0;
+ pThis->iSeverity = inst->iSeverity;
+ pThis->iFacility = inst->iFacility;
+ pThis->maxLinesAtOnce = inst->maxLinesAtOnce;
+ pThis->iPersistStateInterval = inst->iPersistStateInterval;
+ pThis->readMode = inst->readMode;
+ pThis->escapeLF = inst->escapeLF;
+ pThis->pRuleset = inst->pBindRuleset;
+ pThis->nRecords = 0;
++iFilPtr; /* we got a new file to monitor */
resetConfigVariables(NULL, NULL); /* values are both dummies */
@@ -665,9 +681,15 @@ BEGINactivateCnf
instanceConf_t *inst;
CODESTARTactivateCnf
runModConf = pModConf;
+ free(files); /* clear any previous instance */
+ CHKmalloc(files = (fileInfo_t*) malloc(sizeof(fileInfo_t) * INIT_FILE_TAB_SIZE));
+ currMaxFiles = INIT_FILE_TAB_SIZE;
+ iFilPtr = 0;
+
for(inst = runModConf->root ; inst != NULL ; inst = inst->next) {
addListner(inst);
}
+
/* if we could not set up any listeners, there is no point in running... */
if(iFilPtr == 0) {
errmsg.LogError(0, NO_ERRCODE, "imfile: no file monitors could be started, "
@@ -684,12 +706,15 @@ CODESTARTfreeCnf
for(inst = pModConf->root ; inst != NULL ; ) {
free(inst->pszBindRuleset);
free(inst->pszFileName);
+ free(inst->pszDirName);
+ free(inst->pszFileBaseName);
free(inst->pszTag);
free(inst->pszStateFile);
del = inst;
inst = inst->next;
free(del);
}
+ free(files);
ENDfreeCnf