added an identifier to command handler table - need to identify which

command handler entries need to be removed when module is unloaded
This commit is contained in:
Rainer Gerhards 2007-11-21 10:52:19 +00:00
parent 214c7bd7f8
commit 8d606ea26d
7 changed files with 70 additions and 42 deletions

View File

@ -434,7 +434,7 @@ finalize_it:
/* set data members for this object /* set data members for this object
*/ */
rsRetVal cslchSetEntry(cslCmdHdlr_t *pThis, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData) rsRetVal cslchSetEntry(cslCmdHdlr_t *pThis, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData, void *pOwnerCookie)
{ {
assert(pThis != NULL); assert(pThis != NULL);
assert(eType != eCmdHdlrInvalid); assert(eType != eCmdHdlrInvalid);
@ -442,6 +442,8 @@ rsRetVal cslchSetEntry(cslCmdHdlr_t *pThis, ecslCmdHdrlType eType, rsRetVal (*pH
pThis->eType = eType; pThis->eType = eType;
pThis->cslCmdHdlr = pHdlr; pThis->cslCmdHdlr = pHdlr;
pThis->pData = pData; pThis->pData = pData;
pThis->pOwnerCookie = pOwnerCookie;
dbgprintf("handler owner cookie %x\n", pOwnerCookie);
return RS_RET_OK; return RS_RET_OK;
} }
@ -546,7 +548,7 @@ finalize_it:
/* add a handler entry to a known command /* add a handler entry to a known command
*/ */
static rsRetVal cslcAddHdlr(cslCmd_t *pThis, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData) static rsRetVal cslcAddHdlr(cslCmd_t *pThis, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData, void *pOwnerCookie)
{ {
DEFiRet; DEFiRet;
cslCmdHdlr_t *pCmdHdlr = NULL; cslCmdHdlr_t *pCmdHdlr = NULL;
@ -554,7 +556,7 @@ static rsRetVal cslcAddHdlr(cslCmd_t *pThis, ecslCmdHdrlType eType, rsRetVal (*p
assert(pThis != NULL); assert(pThis != NULL);
CHKiRet(cslchConstruct(&pCmdHdlr)); CHKiRet(cslchConstruct(&pCmdHdlr));
CHKiRet(cslchSetEntry(pCmdHdlr, eType, pHdlr, pData)); CHKiRet(cslchSetEntry(pCmdHdlr, eType, pHdlr, pData, pOwnerCookie));
CHKiRet(llAppend(&pThis->llCmdHdlrs, NULL, pCmdHdlr)); CHKiRet(llAppend(&pThis->llCmdHdlrs, NULL, pCmdHdlr));
finalize_it: finalize_it:
@ -587,7 +589,8 @@ finalize_it:
* caller does not need to take care of that. The caller must, however, * caller does not need to take care of that. The caller must, however,
* free pCmdName if he allocated it dynamically! -- rgerhards, 2007-08-09 * free pCmdName if he allocated it dynamically! -- rgerhards, 2007-08-09
*/ */
rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData) rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData,
void *pOwnerCookie)
{ {
cslCmd_t *pThis; cslCmd_t *pThis;
uchar *pMyCmdName; uchar *pMyCmdName;
@ -597,7 +600,7 @@ rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlTy
if(iRet == RS_RET_NOT_FOUND) { if(iRet == RS_RET_NOT_FOUND) {
/* new command */ /* new command */
CHKiRet(cslcConstruct(&pThis, bChainingPermitted)); CHKiRet(cslcConstruct(&pThis, bChainingPermitted));
CHKiRet_Hdlr(cslcAddHdlr(pThis, eType, pHdlr, pData)) { CHKiRet_Hdlr(cslcAddHdlr(pThis, eType, pHdlr, pData, pOwnerCookie)) {
cslcDestruct(pThis); cslcDestruct(pThis);
goto finalize_it; goto finalize_it;
} }
@ -617,7 +620,7 @@ rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlTy
if(pThis->bChainingPermitted == 0 || bChainingPermitted == 0) { if(pThis->bChainingPermitted == 0 || bChainingPermitted == 0) {
ABORT_FINALIZE(RS_RET_CHAIN_NOT_PERMITTED); ABORT_FINALIZE(RS_RET_CHAIN_NOT_PERMITTED);
} }
CHKiRet_Hdlr(cslcAddHdlr(pThis, eType, pHdlr, pData)) { CHKiRet_Hdlr(cslcAddHdlr(pThis, eType, pHdlr, pData, pOwnerCookie)) {
cslcDestruct(pThis); cslcDestruct(pThis);
goto finalize_it; goto finalize_it;
} }
@ -710,6 +713,7 @@ void dbgPrintCfSysLineHandlers(void)
printf("\t\ttype : %d\n", pCmdHdlr->eType); printf("\t\ttype : %d\n", pCmdHdlr->eType);
printf("\t\tpData: 0x%x\n", (unsigned) pCmdHdlr->pData); printf("\t\tpData: 0x%x\n", (unsigned) pCmdHdlr->pData);
printf("\t\tHdlr : 0x%x\n", (unsigned) pCmdHdlr->cslCmdHdlr); printf("\t\tHdlr : 0x%x\n", (unsigned) pCmdHdlr->cslCmdHdlr);
printf("\t\tOwner: 0x%x\n", (unsigned) pCmdHdlr->pOwnerCookie);
printf("\n"); printf("\n");
} }
} }

View File

@ -46,6 +46,10 @@ struct cslCmdHdlr_s { /* config file sysline parse entry */
ecslCmdHdrlType eType; /* which type of handler is this? */ ecslCmdHdrlType eType; /* which type of handler is this? */
rsRetVal (*cslCmdHdlr)(); /* function pointer to use with handler (params depending on eType) */ rsRetVal (*cslCmdHdlr)(); /* function pointer to use with handler (params depending on eType) */
void *pData; /* user-supplied data pointer */ void *pData; /* user-supplied data pointer */
void *pOwnerCookie; /* a pointer to the owner of this handler. This is important if
* the handler for a specifc owner needs to be removed. Most often, this
* is an actual pointer to a module - may be anything, but must be unique.
*/
}; };
typedef struct cslCmdHdlr_s cslCmdHdlr_t; typedef struct cslCmdHdlr_s cslCmdHdlr_t;
@ -61,7 +65,7 @@ struct cslCmd_s { /* config file sysline parse entry */
typedef struct cslCmd_s cslCmd_t; typedef struct cslCmd_s cslCmd_t;
/* prototypes */ /* prototypes */
rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData); rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData, void *pOwnerCookie);
rsRetVal unregCfSysLineHdlrs(void); rsRetVal unregCfSysLineHdlrs(void);
rsRetVal processCfSysLineCommand(uchar *pCmd, uchar **p); rsRetVal processCfSysLineCommand(uchar *pCmd, uchar **p);
rsRetVal cfsyslineInit(void); rsRetVal cfsyslineInit(void);

View File

@ -32,6 +32,18 @@
#define DEF_OMOD_STATIC_DATA \ #define DEF_OMOD_STATIC_DATA \
static rsRetVal (*omsdRegCFSLineHdlr)(); static rsRetVal (*omsdRegCFSLineHdlr)();
/* macro to define a unique module id. This must be able to fit in a void*. The
* module id must be unique inside a running rsyslogd application. It is used to
* track ownership of several objects. Most importantly, when the module is
* unloaded the module id value is used to find what needs to be destroyed.
* We currently use a pointer to modExit() as the module id. This sounds to be
* reasonable save, as each module must have this entry point AND there is no valid
* reason for twice this entry point being in memory.
* rgerhards, 2007-11-21
*/
#define STD_LOADABLE_MODULE_ID ((void*) modExit)
/* to following macros are used to generate function headers and standard /* to following macros are used to generate function headers and standard
* functionality. It works as follows (described on the sample case of * functionality. It works as follows (described on the sample case of
* createInstance()): * createInstance()):
@ -378,7 +390,6 @@ finalize_it:\
#define BEGINmodExit \ #define BEGINmodExit \
static rsRetVal modExit(void)\ static rsRetVal modExit(void)\
{\ {\
dbgprintf("in modExit\n");\
DEFiRet; DEFiRet;
#define CODESTARTmodExit #define CODESTARTmodExit

View File

@ -187,6 +187,16 @@ static rsRetVal modUnload(modInfo_t *pThis)
assert(pThis != NULL); assert(pThis != NULL);
/* WARNING - the current code does NOT work and causes an abort - this is acceptable right now
* as I am DEVELOPING the working code and will NOT release until it is there. If you use a
* CVS snapshot, be aware of this limitation. For now, you can just remove everything up to
* (but not including) the END DEVEL comment. That will do the trick. rgerhards, 2007-11-21
*/
dbgprintf("we are now calling modExit()\n");
/* END DEVEL */
pThis->modExit(); /* tell the module to get ready for unload */
if(pThis->eLinkType == eMOD_LINK_STATIC) { if(pThis->eLinkType == eMOD_LINK_STATIC) {
ABORT_FINALIZE(RS_RET_OK); ABORT_FINALIZE(RS_RET_OK);
} }
@ -195,7 +205,6 @@ static rsRetVal modUnload(modInfo_t *pThis)
/* There is a bunch of things we need to do: /* There is a bunch of things we need to do:
* - unregister this modules config handler * - unregister this modules config handler
* - unload the module itself * - unload the module itself
* - think about the instances freeInstance()
*/ */
ABORT_FINALIZE(RS_RET_NOT_IMPLEMENTED); ABORT_FINALIZE(RS_RET_NOT_IMPLEMENTED);

View File

@ -807,16 +807,16 @@ BEGINmodInit(File)
CODESTARTmodInit CODESTARTmodInit
*ipIFVersProvided = 1; /* so far, we only support the initial definition */ *ipIFVersProvided = 1; /* so far, we only support the initial definition */
CODEmodInit_QueryRegCFSLineHdlr CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(omsdRegCFSLineHdlr((uchar *)"dynafilecachesize", 0, eCmdHdlrInt, (void*) setDynaFileCacheSize, NULL)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"dynafilecachesize", 0, eCmdHdlrInt, (void*) setDynaFileCacheSize, NULL, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirowner", 0, eCmdHdlrUID, NULL, &dirUID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirowner", 0, eCmdHdlrUID, NULL, &dirUID, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirgroup", 0, eCmdHdlrGID, NULL, &dirGID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirgroup", 0, eCmdHdlrGID, NULL, &dirGID, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"fileowner", 0, eCmdHdlrUID, NULL, &fileUID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"fileowner", 0, eCmdHdlrUID, NULL, &fileUID, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"filegroup", 0, eCmdHdlrGID, NULL, &fileGID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"filegroup", 0, eCmdHdlrGID, NULL, &fileGID, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"dircreatemode", 0, eCmdHdlrFileCreateMode, NULL, &fDirCreateMode)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"dircreatemode", 0, eCmdHdlrFileCreateMode, NULL, &fDirCreateMode, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"filecreatemode", 0, eCmdHdlrFileCreateMode, NULL, &fCreateMode)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"filecreatemode", 0, eCmdHdlrFileCreateMode, NULL, &fCreateMode, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"createdirs", 0, eCmdHdlrBinary, NULL, &bCreateDirs)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"createdirs", 0, eCmdHdlrBinary, NULL, &bCreateDirs, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"failonchownfailure", 0, eCmdHdlrBinary, NULL, &bFailOnChown)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"failonchownfailure", 0, eCmdHdlrBinary, NULL, &bFailOnChown, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
ENDmodInit ENDmodInit
/* /*
* vi:set ai: * vi:set ai:

View File

@ -1182,9 +1182,9 @@ CODESTARTmodInit
*ipIFVersProvided = 1; /* so far, we only support the initial definition */ *ipIFVersProvided = 1; /* so far, we only support the initial definition */
CODEmodInit_QueryRegCFSLineHdlr CODEmodInit_QueryRegCFSLineHdlr
# ifdef USE_GSSAPI # ifdef USE_GSSAPI
CHKiRet(omsdRegCFSLineHdlr((uchar *)"gssforwardservicename", 0, eCmdHdlrGetWord, NULL, &gss_base_service_name)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"gssforwardservicename", 0, eCmdHdlrGetWord, NULL, &gss_base_service_name, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"gssmode", 0, eCmdHdlrGetWord, setGSSMode, &gss_mode)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"gssmode", 0, eCmdHdlrGetWord, setGSSMode, &gss_mode, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
# endif # endif
ENDmodInit ENDmodInit

View File

@ -6032,29 +6032,29 @@ static rsRetVal loadBuildInModules(void)
* This, I think, is the right thing to do. -- rgerhards, 2007-07-31 * This, I think, is the right thing to do. -- rgerhards, 2007-07-31
*/ */
#ifdef USE_PTHREADS #ifdef USE_PTHREADS
CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuesize", 0, eCmdHdlrInt, NULL, &iMainMsgQueueSize)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuesize", 0, eCmdHdlrInt, NULL, &iMainMsgQueueSize, NULL));
#endif #endif
CHKiRet(regCfSysLineHdlr((uchar *)"repeatedmsgreduction", 0, eCmdHdlrBinary, NULL, &bReduceRepeatMsgs)); CHKiRet(regCfSysLineHdlr((uchar *)"repeatedmsgreduction", 0, eCmdHdlrBinary, NULL, &bReduceRepeatMsgs, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"actionexeconlywhenpreviousissuspended", 0, eCmdHdlrBinary, NULL, &bActExecWhenPrevSusp)); CHKiRet(regCfSysLineHdlr((uchar *)"actionexeconlywhenpreviousissuspended", 0, eCmdHdlrBinary, NULL, &bActExecWhenPrevSusp, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"actionresumeinterval", 0, eCmdHdlrInt, setActionResumeInterval, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"actionresumeinterval", 0, eCmdHdlrInt, setActionResumeInterval, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"controlcharacterescapeprefix", 0, eCmdHdlrGetChar, NULL, &cCCEscapeChar)); CHKiRet(regCfSysLineHdlr((uchar *)"controlcharacterescapeprefix", 0, eCmdHdlrGetChar, NULL, &cCCEscapeChar, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactersonreceive", 0, eCmdHdlrBinary, NULL, &bEscapeCCOnRcv)); CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactersonreceive", 0, eCmdHdlrBinary, NULL, &bEscapeCCOnRcv, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"dropmsgswithmaliciousdnsptrrecords", 0, eCmdHdlrBinary, NULL, &bDropMalPTRMsgs)); CHKiRet(regCfSysLineHdlr((uchar *)"dropmsgswithmaliciousdnsptrrecords", 0, eCmdHdlrBinary, NULL, &bDropMalPTRMsgs, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"droptrailinglfonreception", 0, eCmdHdlrBinary, NULL, &bDropTrailingLF)); CHKiRet(regCfSysLineHdlr((uchar *)"droptrailinglfonreception", 0, eCmdHdlrBinary, NULL, &bDropTrailingLF, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"template", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_TEMPLATE)); CHKiRet(regCfSysLineHdlr((uchar *)"template", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_TEMPLATE, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"outchannel", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_OUTCHANNEL)); CHKiRet(regCfSysLineHdlr((uchar *)"outchannel", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_OUTCHANNEL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"allowedsender", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_ALLOWEDSENDER)); CHKiRet(regCfSysLineHdlr((uchar *)"allowedsender", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_ALLOWEDSENDER, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"modload", 0, eCmdHdlrCustomHandler, doModLoad, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"modload", 0, eCmdHdlrCustomHandler, doModLoad, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"includeconfig", 0, eCmdHdlrCustomHandler, doIncludeLine, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"includeconfig", 0, eCmdHdlrCustomHandler, doIncludeLine, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"umask", 0, eCmdHdlrFileCreateMode, setUmask, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"umask", 0, eCmdHdlrFileCreateMode, setUmask, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"debugprinttemplatelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintTemplateList)); CHKiRet(regCfSysLineHdlr((uchar *)"debugprinttemplatelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintTemplateList, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"debugprintmodulelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintModuleList)); CHKiRet(regCfSysLineHdlr((uchar *)"debugprintmodulelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintModuleList, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"debugprintcfsyslinehandlerlist", 0, eCmdHdlrBinary, CHKiRet(regCfSysLineHdlr((uchar *)"debugprintcfsyslinehandlerlist", 0, eCmdHdlrBinary,
NULL, &bDebugPrintCfSysLineHandlerList)); NULL, &bDebugPrintCfSysLineHandlerList, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"moddir", 0, eCmdHdlrGetWord, NULL, &pModDir)); CHKiRet(regCfSysLineHdlr((uchar *)"moddir", 0, eCmdHdlrGetWord, NULL, &pModDir, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, NULL));
#if defined(SYSLOG_INET) && defined(USE_GSSAPI) #if defined(SYSLOG_INET) && defined(USE_GSSAPI)
CHKiRet(regCfSysLineHdlr((uchar *)"gsslistenservicename", 0, eCmdHdlrGetWord, NULL, &gss_listen_service_name)); CHKiRet(regCfSysLineHdlr((uchar *)"gsslistenservicename", 0, eCmdHdlrGetWord, NULL, &gss_listen_service_name, NULL));
#endif #endif
finalize_it: finalize_it: