diff options
-rw-r--r-- | module-template.h | 21 | ||||
-rw-r--r-- | modules.c | 1 | ||||
-rw-r--r-- | modules.h | 1 | ||||
-rw-r--r-- | plugins/imklog/imklog.c | 54 | ||||
-rw-r--r-- | plugins/immark/immark.c | 5 | ||||
-rw-r--r-- | rsyslog.h | 1 | ||||
-rw-r--r-- | syslogd.c | 3 | ||||
-rw-r--r-- | threads.c | 9 | ||||
-rw-r--r-- | threads.h | 3 |
9 files changed, 68 insertions, 30 deletions
diff --git a/module-template.h b/module-template.h index 96af4d83..ec727a45 100644 --- a/module-template.h +++ b/module-template.h @@ -385,6 +385,8 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())\ *pEtryPoint = modGetTermSyncType;\ } else if(!strcmp((char*) name, "willRun")) {\ *pEtryPoint = willRun;\ + } else if(!strcmp((char*) name, "afterRun")) {\ + *pEtryPoint = afterRun;\ } /* modInit() @@ -497,6 +499,25 @@ static rsRetVal willRun(void)\ } +/* afterRun() + * This function is called after an input module has been run and its thread has + * been terminated. It shall do any necessary cleanup. + * This is expected to evolve into a freeInstance type of call once the input module + * interface evolves to support multiple instances. + * rgerhards, 2007-12-17 + */ +#define BEGINafterRun \ +static rsRetVal afterRun(void)\ +{\ + DEFiRet; + +#define CODESTARTafterRun + +#define ENDafterRun \ + return iRet;\ +} + + /* method to return which termination sync method is used by this module. */ #define TERM_SYNC_TYPE(x) \ @@ -260,6 +260,7 @@ rsRetVal doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)()) CHKiRet((iRet = (*modGetTermSyncType)(&pNew->mod.im.eTermSyncType)) != RS_RET_OK); CHKiRet((*pNew->modQueryEtryPt)((uchar*)"runInput", &pNew->mod.im.runInput)); CHKiRet((*pNew->modQueryEtryPt)((uchar*)"willRun", &pNew->mod.im.willRun)); + CHKiRet((*pNew->modQueryEtryPt)((uchar*)"afterRun", &pNew->mod.im.afterRun)); break; case eMOD_OUT: CHKiRet((*pNew->modQueryEtryPt)((uchar*)"doAction", &pNew->mod.om.doAction)); @@ -80,6 +80,7 @@ typedef struct moduleInfo { eTermSyncType_t eTermSyncType; rsRetVal (*runInput)(thrdInfo_t*); /* function to gather input and submit to queue */ rsRetVal (*willRun)(void); /* function to gather input and submit to queue */ + rsRetVal (*afterRun)(void); /* function to gather input and submit to queue */ } im; struct {/* data for output modules */ /* below: perform the configured action diff --git a/plugins/imklog/imklog.c b/plugins/imklog/imklog.c index 376d337f..157dee73 100644 --- a/plugins/imklog/imklog.c +++ b/plugins/imklog/imklog.c @@ -97,11 +97,6 @@ int symbols_twice = 0; /* Function prototypes. */ extern int ksyslog(int type, char *buf, int len); -static enum LOGSRC GetKernelLogSrc(void); -static void LogLine(char *ptr, int len); -static void LogKernelLine(void); -static void LogProcLine(void); - /* Write a message to the message queue. @@ -315,7 +310,7 @@ static int copyin( char *line, int space, *line++ = *ptr++; } - return( i ); + return(i); } /* @@ -591,8 +586,7 @@ static void LogProcLine(void) { if ( errno == EINTR ) return; - Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.", \ - errno, strerror(errno)); + Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.", errno, strerror(errno)); } else LogLine(log_buffer, rdcnt); @@ -603,16 +597,6 @@ static void LogProcLine(void) BEGINrunInput CODESTARTrunInput - /* Determine where kernel logging information is to come from. */ - logsrc = GetKernelLogSrc(); - if (symbol_lookup) { - symbol_lookup = (InitKsyms(symfile) == 1); - symbol_lookup |= InitMsyms(); - if (symbol_lookup == 0) { - Syslog(LOG_WARNING, "cannot find any symbols, turning off symbol lookups\n"); - } - } - /* this is an endless loop - it is terminated when the thread is * signalled to do so. This, however, is handled by the framework, * right into the sleep below. @@ -632,24 +616,45 @@ CODESTARTrunInput LogProcLine(); break; case none: - /* TODO: We need to handle this case here somewhat more intelligent */ + /* TODO: We need to handle this case here somewhat more intelligent + * This is now at least partly done - code should never reach this point + * as willRun() already checked for the "none" status -- rgerhards, 2007-12-17 + */ pause(); break; } } -finalize_it: - /* cleanup here */ - CloseLogSrc(); - return iRet; ENDrunInput BEGINwillRun + /* Initialize this module. If that fails, we tell the engine we don't like to run */ + /* Determine where kernel logging information is to come from. */ + logsrc = GetKernelLogSrc(); + if(logsrc == none) { + iRet = RS_RET_NO_KERNEL_LOGSRC; + } else { + if (symbol_lookup) { + symbol_lookup = (InitKsyms(symfile) == 1); + symbol_lookup |= InitMsyms(); + if (symbol_lookup == 0) { + Syslog(LOG_WARNING, "cannot find any symbols, turning off symbol lookups\n"); + } + } + } CODESTARTwillRun ENDwillRun +BEGINafterRun +CODESTARTafterRun + /* cleanup here */ + if(logsrc != none) + CloseLogSrc(); +ENDafterRun + + BEGINfreeInstance CODESTARTfreeInstance ENDfreeInstance @@ -673,6 +678,7 @@ ENDqueryEtryPt static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal) { dbgPrintSymbols = 0; + symbols_twice = 0; return RS_RET_OK; } @@ -680,8 +686,8 @@ BEGINmodInit() CODESTARTmodInit *ipIFVersProvided = 1; /* so far, we only support the initial definition */ CODEmodInit_QueryRegCFSLineHdlr - //CHKiRet(omsdRegCFSLineHdlr((uchar *)"markmessageperiod", 0, eCmdHdlrInt, NULL, &iMarkMessagePeriod, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"debugprintkernelsymbols", 0, eCmdHdlrBinary, NULL, &dbgPrintSymbols, STD_LOADABLE_MODULE_ID)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbolstwice", 0, eCmdHdlrBinary, NULL, &symbols_twice, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID)); ENDmodInit /* diff --git a/plugins/immark/immark.c b/plugins/immark/immark.c index 78adcbac..b7b816b6 100644 --- a/plugins/immark/immark.c +++ b/plugins/immark/immark.c @@ -94,6 +94,11 @@ CODESTARTwillRun ENDwillRun +BEGINafterRun +CODESTARTafterRun +ENDafterRun + + BEGINfreeInstance CODESTARTfreeInstance ENDfreeInstance @@ -92,6 +92,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_INVALID_SOURCE = -2019, /**< source (address) invalid for some reason */ RS_RET_ADDRESS_UNKNOWN = -2020, /**< an address is unknown - not necessarily an error */ RS_RET_MALICIOUS_ENTITY = -2021, /**< there is an malicious entity involved */ + RS_RET_NO_KERNEL_LOGSRC = -2022, /**< no source for kernel logs can be obtained */ RS_RET_OK_DELETE_LISTENTRY = 1, /**< operation successful, but callee requested the deletion of an entry (special state) */ RS_RET_TERMINATE_NOW = 2, /**< operation successful, function is requested to terminate (mostly used with threads) */ RS_RET_NO_RUN = 3, /**< operation successful, but function does not like to be executed */ @@ -4214,7 +4214,7 @@ startInputModules(void) while(pMod != NULL) { if((iRet = pMod->mod.im.willRun()) == RS_RET_OK) { /* activate here */ - thrdCreate(pMod->mod.im.runInput, pMod->mod.im.eTermSyncType); + thrdCreate(pMod->mod.im.runInput, pMod->mod.im.eTermSyncType, pMod->mod.im.afterRun); } else { dbgprintf("module %lx will not run, iRet %d\n", (unsigned long) pMod, iRet); } @@ -4248,7 +4248,6 @@ init(void) eDfltHostnameCmpMode = HN_NO_COMP; Forwarding = 0; -dbgprintf("init()\n"); thrdTerminateAll(); /* stop all running threads - TODO: reconsider location! */ #ifdef SYSLOG_INET if (restart) { @@ -99,6 +99,10 @@ dbgprintf("Terminate thread %lx via method %d\n", pThis->thrdID, pThis->eTermToo pthread_cancel(pThis->thrdID); } pThis->bIsActive = 0; + + /* call cleanup function, if any */ + if(pThis->pAfterRun != NULL) + pThis->pAfterRun(pThis); return RS_RET_OK; } @@ -108,9 +112,7 @@ dbgprintf("Terminate thread %lx via method %d\n", pThis->thrdID, pThis->eTermToo */ rsRetVal thrdTerminateAll(void) { -dbgprintf("thrdTerminateAll in\n"); llDestroy(&llThrds); -dbgprintf("thrdTerminateAll out\n"); return RS_RET_OK; } @@ -151,7 +153,7 @@ static void* thrdStarter(void *arg) * executing threads. It is added at the end of the list. * rgerhards, 2007-12-14 */ -rsRetVal thrdCreate(rsRetVal (*thrdMain)(thrdInfo_t*), eTermSyncType_t eTermSyncType) +rsRetVal thrdCreate(rsRetVal (*thrdMain)(thrdInfo_t*), eTermSyncType_t eTermSyncType, rsRetVal(*afterRun)(thrdInfo_t *)) { DEFiRet; thrdInfo_t *pThis; @@ -163,6 +165,7 @@ rsRetVal thrdCreate(rsRetVal (*thrdMain)(thrdInfo_t*), eTermSyncType_t eTermSync pThis->eTermTool = eTermSyncType; pThis->bIsActive = 1; pThis->pUsrThrdMain = thrdMain; + pThis->pAfterRun = afterRun; i = pthread_create(&pThis->thrdID, NULL, thrdStarter, pThis); CHKiRet(llAppend(&llThrds, NULL, pThis)); @@ -36,6 +36,7 @@ typedef struct thrdInfo { int bIsActive; /* Is thread running? */ int bShallStop; /* set to 1 if the thread should be stopped ? */ rsRetVal (*pUsrThrdMain)(struct thrdInfo*); /* user thread main to be called in new thread */ + rsRetVal (*pAfterRun)(struct thrdInfo*); /* cleanup function */ pthread_t thrdID; } thrdInfo_t; @@ -55,7 +56,7 @@ rsRetVal thrdExit(void); rsRetVal thrdInit(void); rsRetVal thrdTerminate(thrdInfo_t *pThis); rsRetVal thrdTerminateAll(void); -rsRetVal thrdCreate(rsRetVal (*thrdMain)(thrdInfo_t*), eTermSyncType_t eTermSyncType); +rsRetVal thrdCreate(rsRetVal (*thrdMain)(thrdInfo_t*), eTermSyncType_t eTermSyncType, rsRetVal(*afterRun)(thrdInfo_t *)); rsRetVal thrdSleep(thrdInfo_t *pThis, int iSeconds, int iuSeconds); msgQueue *queueInit (void); void queueDelete (msgQueue *q); |