summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-09-26 19:41:59 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-09-26 19:41:59 +0200
commit9a1d7044b9d300dd957a046b79629ddd26a76a2c (patch)
treeced9913f124e5a1cbc8cd000b48daced732cfb4f /plugins
parente1b9a3a25b4cc330faabe4ec7b4b010ba2fcf697 (diff)
downloadrsyslog-9a1d7044b9d300dd957a046b79629ddd26a76a2c.tar.gz
rsyslog-9a1d7044b9d300dd957a046b79629ddd26a76a2c.tar.xz
rsyslog-9a1d7044b9d300dd957a046b79629ddd26a76a2c.zip
milestone: port imfile to v6 config system
Diffstat (limited to 'plugins')
-rw-r--r--plugins/imfile/imfile.c408
-rw-r--r--plugins/imudp/imudp.c20
2 files changed, 279 insertions, 149 deletions
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c
index 440f5991..c2d0db51 100644
--- a/plugins/imfile/imfile.c
+++ b/plugins/imfile/imfile.c
@@ -81,25 +81,48 @@ typedef struct fileInfo_s {
multi_submit_t multiSub;
} fileInfo_t;
+static struct configSettings_s {
+ uchar *pszFileName;
+ uchar *pszFileTag;
+ uchar *pszStateFile;
+ uchar *pszBindRuleset;
+ int iPollInterval; /* number of seconds to sleep when there was no file activity */
+ int iPersistStateInterval; /* how often if state file to be persisted? (default 0->never) */
+ int iFacility; /* local0 */
+ int iSeverity; /* notice, as of rfc 3164 */
+ int readMode; /* mode to use for ReadMultiLine call */
+ int maxLinesAtOnce; /* how many lines to process in a row? */
+ ruleset_t *pBindRuleset; /* ruleset to bind listener to (use system default if unspecified) */
+} cs;
+
+struct instanceConf_s {
+ uchar *pszFileName;
+ uchar *pszTag;
+ uchar *pszStateFile;
+ uchar *pszBindRuleset;
+ int nMultiSub;
+ int iPersistStateInterval;
+ int iFacility;
+ int iSeverity;
+ int readMode;
+ int maxLinesAtOnce;
+ ruleset_t *pBindRuleset; /* ruleset to bind listener to (use system default if unspecified) */
+ struct instanceConf_s *next;
+};
+
/* forward definitions */
static rsRetVal persistStrmState(fileInfo_t *pInfo);
+static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal);
/* config variables */
struct modConfData_s {
- EMPTY_STRUCT;
+ rsconf_t *pConf; /* our overall config object */
+ instanceConf_t *root, *tail;
+ sbool configSetViaV2Method;
};
-
-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 */
-static int readMode = 0; /* mode to use for ReadMultiLine call */
-static int maxLinesAtOnce = 10240; /* how many lines to process in a row? */
-static ruleset_t *pBindRuleset = NULL; /* ruleset to bind listener to (use system default if unspecified) */
+static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
+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
@@ -107,6 +130,8 @@ static fileInfo_t files[MAX_INPUT_FILES];
static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this input */
+#include "im-helper.h" /* must be included AFTER the type definitions! */
+
/* enqueue the read file line as a message. The provided string is
* not freed - thuis must be done by the caller.
*/
@@ -268,6 +293,210 @@ finalize_it:
#pragma GCC diagnostic warning "-Wempty-body"
+/* create input instance, set default paramters, and
+ * add it to the list of instances.
+ */
+static rsRetVal
+createInstance(instanceConf_t **pinst)
+{
+ instanceConf_t *inst;
+ DEFiRet;
+ CHKmalloc(inst = MALLOC(sizeof(instanceConf_t)));
+ inst->next = NULL;
+ inst->pBindRuleset = NULL;
+
+ inst->pszBindRuleset = NULL;
+ inst->pszFileName = NULL;
+ inst->pszTag = NULL;
+ inst->pszStateFile = NULL;
+ inst->nMultiSub = NUM_MULTISUB;
+ inst->iSeverity = 5;
+ inst->iFacility = 128;
+ inst->maxLinesAtOnce = 10240;
+ inst->iPersistStateInterval = 0;
+ inst->readMode = 0;
+
+ /* node created, let's add to config */
+ if(loadModConf->tail == NULL) {
+ loadModConf->tail = loadModConf->root = inst;
+ } else {
+ loadModConf->tail->next = inst;
+ loadModConf->tail = inst;
+ }
+
+ *pinst = inst;
+finalize_it:
+ RETiRet;
+}
+
+
+/* add a new monitor */
+static rsRetVal addInstance(void __attribute__((unused)) *pVal, uchar *pNewVal)
+{
+ instanceConf_t *inst;
+ DEFiRet;
+
+ if(cs.pszFileName == NULL) {
+ errmsg.LogError(0, RS_RET_CONFIG_ERROR, "imfile error: no file name given, file monitor can not be created");
+ ABORT_FINALIZE(RS_RET_CONFIG_ERROR);
+ }
+ if(cs.pszFileTag == NULL) {
+ errmsg.LogError(0, RS_RET_CONFIG_ERROR, "imfile error: no tag value given , file monitor can not be created");
+ ABORT_FINALIZE(RS_RET_CONFIG_ERROR);
+ }
+ if(cs.pszStateFile == NULL) {
+ errmsg.LogError(0, RS_RET_CONFIG_ERROR, "imfile error: not state file name given, file monitor can not be created");
+ ABORT_FINALIZE(RS_RET_CONFIG_ERROR);
+ }
+
+ CHKiRet(createInstance(&inst));
+ if((cs.pszBindRuleset == NULL) || (cs.pszBindRuleset[0] == '\0')) {
+ inst->pszBindRuleset = NULL;
+ } else {
+ CHKmalloc(inst->pszBindRuleset = ustrdup(cs.pszBindRuleset));
+ }
+ inst->pszFileName = (uchar*) strdup((char*) cs.pszFileName);
+ inst->pszTag = (uchar*) strdup((char*) cs.pszFileTag);
+ inst->pszStateFile = (uchar*) strdup((char*) cs.pszStateFile);
+ inst->nMultiSub = NUM_MULTISUB;
+ inst->iSeverity = cs.iSeverity;
+ inst->iFacility = cs.iFacility;
+ inst->maxLinesAtOnce = cs.maxLinesAtOnce;
+ inst->iPersistStateInterval = cs.iPersistStateInterval;
+ inst->readMode = cs.readMode;
+
+ /* reset legacy system */
+ cs.iPersistStateInterval = 0;
+ resetConfigVariables(NULL, NULL); /* values are both dummies */
+
+finalize_it:
+ free(pNewVal); /* we do not need it, but we must free it! */
+ RETiRet;
+}
+
+
+/* This function is called when a new listener (monitor) shall be added. */
+static inline rsRetVal
+addListner(instanceConf_t *inst)
+{
+ DEFiRet;
+ fileInfo_t *pThis;
+
+ if(iFilPtr < MAX_INPUT_FILES) {
+ pThis = &files[iFilPtr];
+ //TODO: optimize, save strdup?
+ 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);
+
+ 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->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);
+ }
+ ++iFilPtr; /* we got a new file to monitor */
+
+ resetConfigVariables(NULL, NULL); /* values are both dummies */
+finalize_it:
+ RETiRet;
+}
+
+BEGINbeginCnfLoad
+CODESTARTbeginCnfLoad
+ loadModConf = pModConf;
+ pModConf->pConf = pConf;
+ /* init our settings */
+ loadModConf->configSetViaV2Method = 0;
+ /* init legacy config vars */
+ cs.pszFileName = NULL;
+ cs.pszFileTag = NULL;
+ cs.pszStateFile = NULL;
+ cs.iPollInterval = 10;
+ cs.iPersistStateInterval = 0;
+ cs.iFacility = 128;
+ cs.iSeverity = 5;
+ cs.readMode = 0;
+ cs.maxLinesAtOnce = 10240;
+ cs.pBindRuleset = NULL;
+ENDbeginCnfLoad
+
+
+BEGINendCnfLoad
+CODESTARTendCnfLoad
+ if(!loadModConf->configSetViaV2Method) {
+ /* persist module-specific settings from legacy config system */
+ }
+
+//finalize_it:
+ loadModConf = NULL; /* done loading */
+ /* free legacy config vars */
+ free(cs.pszFileName);
+ free(cs.pszFileTag);
+ free(cs.pszStateFile);
+ENDendCnfLoad
+
+
+BEGINcheckCnf
+ instanceConf_t *inst;
+CODESTARTcheckCnf
+ for(inst = pModConf->root ; inst != NULL ; inst = inst->next) {
+ std_checkRuleset(pModConf, inst);
+ }
+ if(pModConf->root == NULL) {
+ errmsg.LogError(0, RS_RET_NO_LISTNERS,
+ "imfile: no files configured to be monitored - "
+ "no input will be gathered");
+ iRet = RS_RET_NO_LISTNERS;
+ }
+ENDcheckCnf
+
+
+/* note: we do access files AFTER we have dropped privileges. This is
+ * intentional, user must make sure the files have the right permissions.
+ */
+BEGINactivateCnf
+ instanceConf_t *inst;
+CODESTARTactivateCnf
+ runModConf = pModConf;
+ for(inst = runModConf->root ; inst != NULL ; inst = inst->next) {
+ addListner(inst);
+ }
+ /* if we could not set up any listners, there is no point in running... */
+ //if(lcnfRoot == NULL) {
+ if(iFilPtr == 0) {
+ errmsg.LogError(0, NO_ERRCODE, "imfile: no file monitors could be started, "
+ "input not activated.\n");
+ ABORT_FINALIZE(RS_RET_NO_RUN);
+ }
+finalize_it:
+ENDactivateCnf
+
+
+BEGINfreeCnf
+ instanceConf_t *inst, *del;
+CODESTARTfreeCnf
+ for(inst = pModConf->root ; inst != NULL ; ) {
+ // free(inst->pszBindPort);
+ del = inst;
+ inst = inst->next;
+ free(del);
+ }
+ENDfreeCnf
+
+
+
/* This function is the cancel cleanup handler. It is called when rsyslog decides the
* module must be stopped, what most probably happens during shutdown of rsyslogd. When
* this function is called, the runInput() function (below) is already terminated - somewhere
@@ -328,7 +557,7 @@ CODESTARTrunInput
* other valid scenario. So do not remove. -- rgerhards, 2008-02-14
*/
if(glbl.GetGlobalInputTermState() == 0)
- srSleep(iPollInterval, 10);
+ srSleep(cs.iPollInterval, 10);
}
DBGPRINTF("imfile: terminating upon request of rsyslog core\n");
@@ -350,16 +579,6 @@ ENDrunInput
*/
BEGINwillRun
CODESTARTwillRun
- /* free config variables we do no longer needed */
- free(pszFileName);
- free(pszFileTag);
- free(pszStateFile);
-
- if(iFilPtr == 0) {
- errmsg.LogError(0, RS_RET_NO_RUN, "No files configured to be monitored");
- ABORT_FINALIZE(RS_RET_NO_RUN);
- }
-
/* we need to create the inputName property (only once during our lifetime) */
CHKiRet(prop.Construct(&pInputName));
CHKiRet(prop.SetString(pInputName, UCHAR_CONSTANT("imfile"), sizeof("imfile") - 1));
@@ -458,6 +677,7 @@ ENDmodExit
BEGINqueryEtryPt
CODESTARTqueryEtryPt
CODEqueryEtryPt_STD_IMOD_QUERIES
+CODEqueryEtryPt_STD_CONF2_QUERIES
CODEqueryEtryPt_IsCompatibleWithFeature_IF_OMOD_QUERIES
ENDqueryEtryPt
@@ -468,119 +688,37 @@ ENDqueryEtryPt
* but in general this is not necessary. Once runInput() has been called, this
* function here is never again called.
*/
-static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
+static rsRetVal
+resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
{
DEFiRet;
- if(pszFileName != NULL) {
- free(pszFileName);
- pszFileName = NULL;
- }
-
- if(pszFileTag != NULL) {
- free(pszFileTag);
- pszFileTag = NULL;
- }
-
- if(pszStateFile != NULL) {
- free(pszFileTag);
- pszFileTag = NULL;
- }
-
+ free(cs.pszFileName);
+ cs.pszFileName = NULL;
+ free(cs.pszFileTag);
+ cs.pszFileTag = NULL;
+ free(cs.pszFileTag);
+ cs.pszFileTag = NULL;
/* set defaults... */
- iPollInterval = 10;
- iFacility = 128; /* local0 */
- iSeverity = 5; /* notice, as of rfc 3164 */
- readMode = 0;
- pBindRuleset = NULL;
- maxLinesAtOnce = 10240;
+ cs.iPollInterval = 10;
+ cs.iFacility = 128; /* local0 */
+ cs.iSeverity = 5; /* notice, as of rfc 3164 */
+ cs.readMode = 0;
+ cs.pBindRuleset = NULL;
+ cs.maxLinesAtOnce = 10240;
RETiRet;
}
-
-/* add a new monitor */
-static rsRetVal addMonitor(void __attribute__((unused)) *pVal, uchar *pNewVal)
+static inline void
+std_checkRuleset_genErrMsg(__attribute__((unused)) modConfData_t *modConf, instanceConf_t *inst)
{
- DEFiRet;
- fileInfo_t *pThis;
-
- free(pNewVal); /* we do not need it, but we must free it! */
-
- if(iFilPtr < MAX_INPUT_FILES) {
- pThis = &files[iFilPtr];
- /* TODO: check for strdup() NULL return */
- if(pszFileName == NULL) {
- errmsg.LogError(0, RS_RET_CONFIG_ERROR, "imfile error: no file name given, file monitor can not be created");
- ABORT_FINALIZE(RS_RET_CONFIG_ERROR);
- } else {
- pThis->pszFileName = (uchar*) strdup((char*) pszFileName);
- }
-
- if(pszFileTag == NULL) {
- errmsg.LogError(0, RS_RET_CONFIG_ERROR, "imfile error: no tag value given , file monitor can not be created");
- ABORT_FINALIZE(RS_RET_CONFIG_ERROR);
- } else {
- pThis->pszTag = (uchar*) strdup((char*) pszFileTag);
- pThis->lenTag = ustrlen(pThis->pszTag);
- }
-
- if(pszStateFile == NULL) {
- errmsg.LogError(0, RS_RET_CONFIG_ERROR, "imfile error: not state file name given, file monitor can not be created");
- ABORT_FINALIZE(RS_RET_CONFIG_ERROR);
- } else {
- pThis->pszStateFile = (uchar*) strdup((char*) pszStateFile);
- }
-
- CHKmalloc(pThis->multiSub.ppMsgs = MALLOC(NUM_MULTISUB * sizeof(msg_t*)));
- pThis->multiSub.maxElem = NUM_MULTISUB;
- pThis->multiSub.nElem = 0;
- pThis->iSeverity = iSeverity;
- pThis->iFacility = iFacility;
- pThis->maxLinesAtOnce = maxLinesAtOnce;
- pThis->iPersistStateInterval = iPersistStateInterval;
- pThis->nRecords = 0;
- pThis->readMode = readMode;
- pThis->pRuleset = pBindRuleset;
- 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);
- }
-
- CHKiRet(resetConfigVariables((uchar*) "dummy", (void*) pThis)); /* values are both dummies */
-
-finalize_it:
- if(iRet == RS_RET_OK)
- ++iFilPtr; /* we got a new file to monitor */
-
- RETiRet;
+ errmsg.LogError(0, NO_ERRCODE, "imfile: ruleset '%s' for %s not found - "
+ "using default ruleset instead", inst->pszBindRuleset,
+ inst->pszFileName);
}
-
-/* accept a new ruleset to bind. Checks if it exists and complains, if not */
-static rsRetVal
-setRuleset(void __attribute__((unused)) *pVal, uchar *pszName)
-{
- ruleset_t *pRuleset;
- rsRetVal localRet;
- DEFiRet;
-
- localRet = ruleset.GetRuleset(ourConf, &pRuleset, pszName);
- if(localRet == RS_RET_NOT_FOUND) {
- errmsg.LogError(0, NO_ERRCODE, "error: ruleset '%s' not found - ignored", pszName);
- }
- CHKiRet(localRet);
- pBindRuleset = pRuleset;
- DBGPRINTF("imfile current bind ruleset %p: '%s'\n", pRuleset, pszName);
-
-finalize_it:
- free(pszName); /* no longer needed */
- RETiRet;
-}
-
-
/* modInit() is called once the module is loaded. It must perform all module-wide
* initialization tasks. There are also a number of housekeeping tasks that the
* framework requires. These are handled by the macros. Please note that the
@@ -603,28 +741,28 @@ CODEmodInit_QueryRegCFSLineHdlr
DBGPRINTF("imfile: version %s initializing\n", VERSION);
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilename", 0, eCmdHdlrGetWord,
- NULL, &pszFileName, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.pszFileName, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfiletag", 0, eCmdHdlrGetWord,
- NULL, &pszFileTag, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.pszFileTag, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilestatefile", 0, eCmdHdlrGetWord,
- NULL, &pszStateFile, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.pszStateFile, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfileseverity", 0, eCmdHdlrSeverity,
- NULL, &iSeverity, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.iSeverity, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilefacility", 0, eCmdHdlrFacility,
- NULL, &iFacility, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.iFacility, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilepollinterval", 0, eCmdHdlrInt,
- NULL, &iPollInterval, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.iPollInterval, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilereadmode", 0, eCmdHdlrInt,
- NULL, &readMode, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.readMode, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilemaxlinesatonce", 0, eCmdHdlrSize,
- NULL, &maxLinesAtOnce, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.maxLinesAtOnce, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilepersiststateinterval", 0, eCmdHdlrInt,
- NULL, &iPersistStateInterval, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.iPersistStateInterval, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilebindruleset", 0, eCmdHdlrGetWord,
- setRuleset, NULL, STD_LOADABLE_MODULE_ID));
+ NULL, &cs.pszBindRuleset, STD_LOADABLE_MODULE_ID));
/* that command ads a new file! */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputrunfilemonitor", 0, eCmdHdlrGetWord,
- addMonitor, NULL, STD_LOADABLE_MODULE_ID));
+ addInstance, NULL, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
ENDmodInit
diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c
index 2daf9678..20425d79 100644
--- a/plugins/imudp/imudp.c
+++ b/plugins/imudp/imudp.c
@@ -202,8 +202,6 @@ static rsRetVal addInstance(void __attribute__((unused)) *pVal, uchar *pNewVal)
} else {
CHKmalloc(inst->pszBindRuleset = ustrdup(cs.pszBindRuleset));
}
- inst->pBindRuleset = NULL;
- inst->next = NULL;
finalize_it:
free(pNewVal);
@@ -917,18 +915,12 @@ ENDqueryEtryPt
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
{
- if(cs.pszBindAddr != NULL) {
- free(cs.pszBindAddr);
- cs.pszBindAddr = NULL;
- }
- if(cs.pszSchedPolicy != NULL) {
- free(cs.pszSchedPolicy);
- cs.pszSchedPolicy = NULL;
- }
- if(cs.pszBindRuleset != NULL) {
- free(cs.pszBindRuleset);
- cs.pszBindRuleset = NULL;
- }
+ free(cs.pszBindAddr);
+ cs.pszBindAddr = NULL;
+ free(cs.pszSchedPolicy);
+ cs.pszSchedPolicy = NULL;
+ free(cs.pszBindRuleset);
+ cs.pszBindRuleset = NULL;
cs.iSchedPrio = SCHED_PRIO_UNSET;
cs.iTimeRequery = TIME_REQUERY_DFLT;/* the default is to query only every second time */
return RS_RET_OK;