diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2007-07-23 17:24:41 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2007-07-23 17:24:41 +0000 |
commit | 9ee5888309e1f39f52546deaea4bcd3bdc216d8d (patch) | |
tree | a46550eb83762539b375063e6e74d828d1ebb42f /modules.c | |
parent | 8f236abd49739c0f791c5b893433f7dfa40d3dd8 (diff) | |
download | rsyslog-9ee5888309e1f39f52546deaea4bcd3bdc216d8d.tar.gz rsyslog-9ee5888309e1f39f52546deaea4bcd3bdc216d8d.tar.xz rsyslog-9ee5888309e1f39f52546deaea4bcd3bdc216d8d.zip |
continued working on modularization; begun to create interface for
configuring actions selector lines; begun basic functionality for
module initialization and loading built-in modules.
Diffstat (limited to 'modules.c')
-rw-r--r-- | modules.c | 98 |
1 files changed, 94 insertions, 4 deletions
@@ -23,6 +23,7 @@ * A copy of the GPL can be found in the file "COPYING" in this distribution. */ #include "config.h" +#include "rsyslog.h" #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -34,7 +35,7 @@ #include <unistd.h> #include <sys/file.h> -#include "rsyslog.h" +#include "syslogd.h" #include "modules.h" static modInfo_t *pLoadedModules = NULL; /* list of currently-loaded modules */ @@ -59,6 +60,15 @@ static rsRetVal moduleConstruct(modInfo_t **pThis) } +/* Destructs a module objects. The object must not be linked to the + * linked list of modules. + */ +static void moduleDestruct(modInfo_t *pThis) +{ + free(pThis); +} + + /* Add a module to the loaded module linked list */ static inline void addModToList(modInfo_t *pThis) @@ -75,28 +85,108 @@ static inline void addModToList(modInfo_t *pThis) } +/* Get the next module pointer - this is used to traverse the list. + * The function returns the next pointer or NULL, if there is no next one. + * The last object must be provided to the function. If NULL is provided, + * it starts at the root of the list. Even in this case, NULL may be + * returned - then, the list is empty. + * rgerhards, 2007-07-23 + */ +modInfo_t *modGetNxt(modInfo_t *pThis) +{ + modInfo_t *pNew; + + if(pThis == NULL) + pNew = pLoadedModules; + else + pNew = pThis->pNext; + + return(pNew); +} + + /* Add an already-loaded module to the module linked list. This function does * anything that is needed to fully initialize the module. */ -rsRetVal doModInit(rsRetVal *doInit(), uchar *name) +rsRetVal doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)()), uchar *name) { modInfo_t *pNew; rsRetVal iRet; + assert(modInit != NULL); + + printf("Enter doModInit for module '%s'\n", (char*)name); + if((iRet = moduleConstruct(&pNew)) != RS_RET_OK) return iRet; - if((iRet = *doInit()) != RS_RET_OK) + if((iRet = (*modInit)(1, &pNew->iIFVers, &pNew->modQueryEtryPt)) != RS_RET_OK) { + moduleDestruct(pNew); return iRet; + } + + if(pNew->iIFVers != 1) { + moduleDestruct(pNew); + return RS_RET_MISSING_INTERFACE; + } /* OK, we know we can successfully work with the module. So we now fill the * rest of the data elements. */ + if((iRet = (*pNew->modQueryEtryPt)((uchar*)"doAction", &pNew->mod.om.doAction)) != RS_RET_OK) { + moduleDestruct(pNew); + return iRet; + } +/* later... + if((iRet = (*pNew->modQueryEtryPt)((uchar*)"freeInstance", &pNew->freeInstance)) != RS_RET_OK) { + moduleDestruct(pNew); + return iRet; + } +*/ + + pNew->pszName = (uchar*) strdup((char*)name); /* we do not care if strdup() fails, we can accept that */ + pNew->eType = eMOD_OUT; /* TODO: take this from module */ - pNew->pszModName = (uchar*) strdup((char*)name); /* we do not care if strdup() fails, we can accept that */ + /* we initialized the structure, now let's add it to the linked list of modules */ + addModToList(pNew); return RS_RET_OK; } + +/* Print loaded modules. This is more or less a + * debug or test aid, but anyhow I think it's worth it... + * This only works if the dprintf() subsystem is initialized. + */ +void modPrintList(void) +{ + modInfo_t *pMod; + + pMod = modGetNxt(NULL); + while(pMod != NULL) { + dprintf("Loaded Module: Name='%s', IFVersion=%d, ", + (pMod->pszName == NULL) ? "NULL" : (char*)pMod->pszName, + pMod->iIFVers); + dprintf("type="); + switch(pMod->eType) { + case eMOD_OUT: + dprintf("output"); + break; + case eMOD_IN: + dprintf("input"); + break; + case eMOD_FILTER: + dprintf("filter"); + break; + } + dprintf(" module.\n"); + dprintf("Entry points:\n"); + dprintf("\tqueryEtryPt: 0x%x\n", (unsigned) pMod->modQueryEtryPt); + dprintf("\tdoAction: 0x%x\n", (unsigned) pMod->mod.om.doAction); + dprintf("\tfreeInstance: 0x%x\n", (unsigned) pMod->freeInstance); + dprintf("\n"); + pMod = modGetNxt(pMod); /* done, go next */ + } +} /* * vi:set ai: */ |