summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-12-17 14:34:22 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-12-17 14:34:22 +0000
commit653ec62b23346eaab4f2f3830eeb7f1634a924c5 (patch)
treebea302747c51827905f2c8fc7eb8e4e243474149
parent8132d66186c8c08c44bb3504cb91e2e12bee11c1 (diff)
downloadrsyslog-653ec62b23346eaab4f2f3830eeb7f1634a924c5.tar.gz
rsyslog-653ec62b23346eaab4f2f3830eeb7f1634a924c5.tar.xz
rsyslog-653ec62b23346eaab4f2f3830eeb7f1634a924c5.zip
- implemented afterRun input module interface function
- implemented $klogSymbolsTwice config directive
-rw-r--r--module-template.h21
-rw-r--r--modules.c1
-rw-r--r--modules.h1
-rw-r--r--plugins/imklog/imklog.c54
-rw-r--r--plugins/immark/immark.c5
-rw-r--r--rsyslog.h1
-rw-r--r--syslogd.c3
-rw-r--r--threads.c9
-rw-r--r--threads.h3
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) \
diff --git a/modules.c b/modules.c
index 5381a036..d2973018 100644
--- a/modules.c
+++ b/modules.c
@@ -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));
diff --git a/modules.h b/modules.h
index 83fa641f..cf6eda24 100644
--- a/modules.h
+++ b/modules.h
@@ -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
diff --git a/rsyslog.h b/rsyslog.h
index 1f18f10c..91d781ee 100644
--- a/rsyslog.h
+++ b/rsyslog.h
@@ -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 */
diff --git a/syslogd.c b/syslogd.c
index f3b3042f..3a35f732 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -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) {
diff --git a/threads.c b/threads.c
index 70271ab1..88b4ce8f 100644
--- a/threads.c
+++ b/threads.c
@@ -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));
diff --git a/threads.h b/threads.h
index 30551505..51ae52cf 100644
--- a/threads.h
+++ b/threads.h
@@ -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);