diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-10-11 09:12:20 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-10-11 09:12:20 +0200 |
commit | f85690620b74c076de8f26059e5914f72a8bd912 (patch) | |
tree | 2b03f3b2d8ce22b90e2239d87459074819dcfd2b | |
parent | dc724fcd2e1a8fcd8c2b3c309fa1c1a3f7bc73ea (diff) | |
download | rsyslog-f85690620b74c076de8f26059e5914f72a8bd912.tar.gz rsyslog-f85690620b74c076de8f26059e5914f72a8bd912.tar.xz rsyslog-f85690620b74c076de8f26059e5914f72a8bd912.zip |
do "template date call" only when actually needed
-rw-r--r-- | action.c | 23 | ||||
-rw-r--r-- | action.h | 1 | ||||
-rw-r--r-- | template.c | 32 | ||||
-rw-r--r-- | template.h | 1 |
4 files changed, 56 insertions, 1 deletions
@@ -1230,7 +1230,10 @@ prepareBatch(action_t *pAction, batch_t *pBatch, sbool **activeSave, int *bMustR struct syslogTime ttNow; DEFiRet; - datetime.getCurrTime(&ttNow, NULL); // TODO: query time only if required 2012-10-10 rger + if(pAction->requiresDateCall) { + datetime.getCurrTime(&ttNow, NULL); + } + pBatch->iDoneUpTo = 0; for(i = 0 ; i < batchNumMsgs(pBatch) && !*(pBatch->pbShutdownImmediate) ; ++i) { pElem = &(pBatch->pElem[i]); @@ -1878,6 +1881,23 @@ actionApplyCnfParam(action_t *pAction, struct cnfparamvals *pvals) return RS_RET_OK; } +/* check if the templates used in this action require a date call + * ($NOW family of properties). + */ +static inline int +actionRequiresDateCall(action_t *pAction) +{ + int i; + int r = 0; + + for(i = 0 ; i < pAction->iNumTpls ; ++i) { + if(tplRequiresDateCall(pAction->ppTpl[i])) { + r = 1; + break; + } + } + return r; +} /* add an Action to the current selector @@ -1983,6 +2003,7 @@ addAction(action_t **ppAction, modInfo_t *pMod, void *pModData, pAction->f_ReduceRepeated = 0; } pAction->eState = ACT_STATE_RDY; /* action is enabled */ + pAction->requiresDateCall = actionRequiresDateCall(pAction); if(bSuspended) actionSuspend(pAction, datetime.GetTime(NULL)); /* "good" time call, only during init and unavoidable */ @@ -70,6 +70,7 @@ struct action_s { void *pModData; /* pointer to module data - content is module-specific */ sbool bRepMsgHasMsg; /* "message repeated..." has msg fragment in it (0-no, 1-yes) */ short f_ReduceRepeated;/* reduce repeated lines 0 - no, 1 - yes */ + sbool requiresDateCall;/* do we need to do a date call before creating templates? */ int f_prevcount; /* repetition cnt of prevline */ int f_repeatcount; /* number of "repeated" msgs */ rsRetVal (*submitToActQ)(action_t *, batch_t *);/* function submit message to action queue */ @@ -380,6 +380,38 @@ finalize_it: } +/* Check if the template requires a date call (actually a cached + * date structure). This currently is the case for the $NOW family + * of properties. + */ +int +tplRequiresDateCall(struct template *pTpl) +{ + struct templateEntry *pTpe; + int r = 0; + + if(pTpl->subtree != NULL) + goto done; + + for(pTpe = pTpl->pEntryRoot ; pTpe != NULL ; pTpe = pTpe->pNext) { + switch(pTpe->data.field.propid) { + case PROP_SYS_NOW: + case PROP_SYS_YEAR: + case PROP_SYS_MONTH: + case PROP_SYS_DAY: + case PROP_SYS_HOUR: + case PROP_SYS_HHOUR: + case PROP_SYS_QHOUR: + case PROP_SYS_MINUTE: + r = 1; + goto done; + default:break; + } + } +done: return r; +} + + /* Helper to doEscape. This is called if doEscape * runs out of memory allocating the escaped string. * Then we are in trouble. We can @@ -142,6 +142,7 @@ void tplDeleteNew(rsconf_t *conf); void tplPrintList(rsconf_t *conf); void tplLastStaticInit(rsconf_t *conf, struct template *tpl); rsRetVal ExtendBuf(uchar **pBuf, size_t *pLenBuf, size_t iMinSize); +int tplRequiresDateCall(struct template *pTpl); /* note: if a compiler warning for undefined type tells you to look at this * code line below, the actual cause is that you currently MUST include template.h * BEFORE msg.h, even if your code file does not actually need it. |