mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-19 02:10:42 +01:00
omuxsock: support for module() global config parameters added
This commit is contained in:
parent
9f3dfc0efe
commit
4ed4e8c287
@ -71,6 +71,26 @@ typedef struct configSettings_s {
|
||||
} configSettings_t;
|
||||
static configSettings_t cs;
|
||||
|
||||
/* module-global parameters */
|
||||
static struct cnfparamdescr modpdescr[] = {
|
||||
{ "template", eCmdHdlrGetWord, 0 },
|
||||
};
|
||||
static struct cnfparamblk modpblk =
|
||||
{ CNFPARAMBLK_VERSION,
|
||||
sizeof(modpdescr)/sizeof(struct cnfparamdescr),
|
||||
modpdescr
|
||||
};
|
||||
|
||||
struct modConfData_s {
|
||||
rsconf_t *pConf; /* our overall config object */
|
||||
uchar *tplName; /* default template */
|
||||
};
|
||||
|
||||
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 exec process */
|
||||
|
||||
|
||||
|
||||
BEGINinitConfVars /* (re)set config variables to default values */
|
||||
CODESTARTinitConfVars
|
||||
cs.tplName = NULL;
|
||||
@ -80,8 +100,45 @@ ENDinitConfVars
|
||||
|
||||
static rsRetVal doTryResume(instanceData *pData);
|
||||
|
||||
/* Close socket.
|
||||
|
||||
/* this function gets the default template. It coordinates action between
|
||||
* old-style and new-style configuration parts.
|
||||
*/
|
||||
static inline uchar*
|
||||
getDfltTpl(void)
|
||||
{
|
||||
if(loadModConf != NULL && loadModConf->tplName != NULL)
|
||||
return loadModConf->tplName;
|
||||
else if(cs.tplName == NULL)
|
||||
return (uchar*)"RSYSLOG_TraditionalForwardFormat";
|
||||
else
|
||||
return cs.tplName;
|
||||
}
|
||||
|
||||
/* set the default template to be used
|
||||
* This is a module-global parameter, and as such needs special handling. It needs to
|
||||
* be coordinated with values set via the v2 config system (rsyslog v6+). What we do
|
||||
* is we do not permit this directive after the v2 config system has been used to set
|
||||
* the parameter.
|
||||
*/
|
||||
rsRetVal
|
||||
setLegacyDfltTpl(void __attribute__((unused)) *pVal, uchar* newVal)
|
||||
{
|
||||
DEFiRet;
|
||||
|
||||
if(loadModConf != NULL && loadModConf->tplName != NULL) {
|
||||
free(newVal);
|
||||
errmsg.LogError(0, RS_RET_ERR, "omuxsock default template already set via module "
|
||||
"global parameter - can no longer be changed");
|
||||
ABORT_FINALIZE(RS_RET_ERR);
|
||||
}
|
||||
free(cs.tplName);
|
||||
cs.tplName = newVal;
|
||||
finalize_it:
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
|
||||
static inline rsRetVal
|
||||
closeSocket(instanceData *pData)
|
||||
{
|
||||
@ -96,6 +153,72 @@ pData->bIsConnected = 0; // TODO: remove this variable altogether
|
||||
|
||||
|
||||
|
||||
|
||||
BEGINbeginCnfLoad
|
||||
CODESTARTbeginCnfLoad
|
||||
loadModConf = pModConf;
|
||||
pModConf->pConf = pConf;
|
||||
pModConf->tplName = NULL;
|
||||
ENDbeginCnfLoad
|
||||
|
||||
BEGINsetModCnf
|
||||
struct cnfparamvals *pvals = NULL;
|
||||
int i;
|
||||
CODESTARTsetModCnf
|
||||
pvals = nvlstGetParams(lst, &modpblk, NULL);
|
||||
if(pvals == NULL) {
|
||||
errmsg.LogError(0, RS_RET_MISSING_CNFPARAMS, "error processing module "
|
||||
"config parameters [module(...)]");
|
||||
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
||||
}
|
||||
|
||||
if(Debug) {
|
||||
dbgprintf("module (global) param blk for omuxsock:\n");
|
||||
cnfparamsPrint(&modpblk, pvals);
|
||||
}
|
||||
|
||||
for(i = 0 ; i < modpblk.nParams ; ++i) {
|
||||
if(!pvals[i].bUsed)
|
||||
continue;
|
||||
if(!strcmp(modpblk.descr[i].name, "template")) {
|
||||
loadModConf->tplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
|
||||
if(cs.tplName != NULL) {
|
||||
errmsg.LogError(0, RS_RET_DUP_PARAM, "omuxsock: warning: default template "
|
||||
"was already set via legacy directive - may lead to inconsistent "
|
||||
"results.");
|
||||
}
|
||||
} else {
|
||||
dbgprintf("omuxsock: program error, non-handled "
|
||||
"param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
|
||||
}
|
||||
}
|
||||
finalize_it:
|
||||
if(pvals != NULL)
|
||||
cnfparamvalsDestruct(pvals, &modpblk);
|
||||
ENDsetModCnf
|
||||
|
||||
BEGINendCnfLoad
|
||||
CODESTARTendCnfLoad
|
||||
loadModConf = NULL; /* done loading */
|
||||
/* free legacy config vars */
|
||||
free(cs.tplName);
|
||||
cs.tplName = NULL;
|
||||
ENDendCnfLoad
|
||||
|
||||
BEGINcheckCnf
|
||||
CODESTARTcheckCnf
|
||||
ENDcheckCnf
|
||||
|
||||
BEGINactivateCnf
|
||||
CODESTARTactivateCnf
|
||||
runModConf = pModConf;
|
||||
ENDactivateCnf
|
||||
|
||||
BEGINfreeCnf
|
||||
CODESTARTfreeCnf
|
||||
free(pModConf->tplName);
|
||||
ENDfreeCnf
|
||||
|
||||
BEGINcreateInstance
|
||||
CODESTARTcreateInstance
|
||||
pData->sock = INVLD_SOCK;
|
||||
@ -250,8 +373,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1)
|
||||
/* check if a non-standard template is to be applied */
|
||||
if(*(p-1) == ';')
|
||||
--p;
|
||||
CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, 0, cs.tplName == NULL ? UCHAR_CONSTANT("RSYSLOG_TraditionalForwardFormat")
|
||||
: cs.tplName ));
|
||||
CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, 0, getDfltTpl()));
|
||||
|
||||
if(cs.sockName == NULL) {
|
||||
errmsg.LogError(0, RS_RET_NO_SOCK_CONFIGURED, "No output socket configured for omuxsock\n");
|
||||
@ -291,6 +413,8 @@ ENDmodExit
|
||||
BEGINqueryEtryPt
|
||||
CODESTARTqueryEtryPt
|
||||
CODEqueryEtryPt_STD_OMOD_QUERIES
|
||||
CODEqueryEtryPt_STD_CONF2_QUERIES
|
||||
CODEqueryEtryPt_STD_CONF2_setModCnf_QUERIES
|
||||
ENDqueryEtryPt
|
||||
|
||||
|
||||
@ -312,7 +436,7 @@ CODEmodInit_QueryRegCFSLineHdlr
|
||||
CHKiRet(objUse(glbl, CORE_COMPONENT));
|
||||
CHKiRet(objUse(errmsg, CORE_COMPONENT));
|
||||
|
||||
CHKiRet(regCfSysLineHdlr((uchar *)"omuxsockdefaulttemplate", 0, eCmdHdlrGetWord, NULL, &cs.tplName, NULL));
|
||||
CHKiRet(regCfSysLineHdlr((uchar *)"omuxsockdefaulttemplate", 0, eCmdHdlrGetWord, setLegacyDfltTpl, NULL, NULL));
|
||||
CHKiRet(regCfSysLineHdlr((uchar *)"omuxsocksocket", 0, eCmdHdlrGetWord, NULL, &cs.sockName, NULL));
|
||||
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
|
||||
ENDmodInit
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user