From 74135da95971c8d03e4e45f7d3f703e1d40f76f4 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 10 Jun 2010 12:24:22 +0200 Subject: some cleanup as well as some work in preparation of storing doAction params inside the batch --- action.c | 74 +++++++++++++------------------------------------------ action.h | 2 -- runtime/batch.h | 6 +++++ runtime/rsyslog.h | 1 + tools/omfile.c | 1 - 5 files changed, 24 insertions(+), 60 deletions(-) diff --git a/action.c b/action.c index bd1920a8..dc6cdaaf 100644 --- a/action.c +++ b/action.c @@ -191,7 +191,6 @@ actionResetQueueParams(void) */ rsRetVal actionDestruct(action_t *pThis) { - int i; DEFiRet; ASSERT(pThis != NULL); @@ -210,37 +209,6 @@ rsRetVal actionDestruct(action_t *pThis) d_free(pThis->pszName); d_free(pThis->ppTpl); - /* message ptr cleanup */ -#if 0 - for(i = 0 ; i < pThis->iNumTpls ; ++i) { - if(((uchar**)pThis->ppMsgs)[i] != NULL) { - switch(pThis->eParamPassing) { - case ACT_ARRAY_PASSING: -#if 0 /* later, as an optimization. So far, we do the cleanup after each message */ - iArr = 0; - while(((char **)pThis->ppMsgs[i])[iArr] != NULL) { - d_free(((char **)pThis->ppMsgs[i])[iArr++]); - ((char **)pThis->ppMsgs[i])[iArr++] = NULL; - } - d_free(pThis->ppMsgs[i]); - pThis->ppMsgs[i] = NULL; -#endif - break; - case ACT_STRING_PASSING: - d_free(((uchar**)pThis->ppMsgs)[i]); - break; - case ACT_MSG_PASSING: - /* No cleanup needed in this case */ - break; - default: - assert(0); - } - } - } - d_free(pThis->ppMsgs); -#endif - d_free(pThis->lenMsgs); - d_free(pThis); RETiRet; @@ -721,36 +689,26 @@ finalize_it: /* cleanup doAction calling parameters * rgerhards, 2009-05-07 */ -static rsRetVal cleanupDoActionParams(action_t *pAction) +//TODO: check if this is still needed! +static rsRetVal cleanupDoActionParams(action_t *pAction, uchar **ppMsgs) { - int i; int iArr; + int i; DEFiRet; ASSERT(pAction != NULL); -#if 0 for(i = 0 ; i < pAction->iNumTpls ; ++i) { - if(((uchar**)pAction->ppMsgs)[i] != NULL) { - switch(pAction->eParamPassing) { - case ACT_ARRAY_PASSING: - iArr = 0; - while((((uchar***)pAction->ppMsgs)[i][iArr]) != NULL) { - d_free(((uchar ***)pAction->ppMsgs)[i][iArr++]); - ((uchar ***)pAction->ppMsgs)[i][iArr++] = NULL; - } - d_free(((uchar**)pAction->ppMsgs)[i]); - ((uchar**)pAction->ppMsgs)[i] = NULL; - break; - case ACT_MSG_PASSING: - case ACT_STRING_PASSING: - break; - default: - assert(0); + if(((uchar**)ppMsgs)[i] != NULL) { + iArr = 0; + while((((uchar***)ppMsgs)[i][iArr]) != NULL) { + d_free(((uchar ***)ppMsgs)[i][iArr++]); + ((uchar ***)ppMsgs)[i][iArr++] = NULL; } + d_free(((uchar**)ppMsgs)[i]); + ((uchar**)ppMsgs)[i] = NULL; } } -#endif RETiRet; } @@ -824,13 +782,18 @@ iRet = RS_RET_OK; iRet = getReturnCode(pThis); finalize_it: - cleanupDoActionParams(pThis); /* iRet ignored! */ - + switch(pThis->eParamPassing) { case ACT_STRING_PASSING: for(i = 0 ; i < 10 ; ++i) free(ppMsgs[i]); break; + case ACT_ARRAY_PASSING: + cleanupDoActionParams(pThis, ppMsgs); /* iRet ignored! */ + break; + case ACT_MSG_PASSING: + /* nothing to do in that case */ + break; } @@ -1384,7 +1347,6 @@ doSubmitToActionQ(action_t *pAction, msg_t *pMsg) } - /* Call configured action, most complex case with all features supported (and thus slow). * rgerhards, 2010-06-08 */ @@ -1453,8 +1415,6 @@ addAction(action_t **ppAction, modInfo_t *pMod, void *pModData, omodStringReques if(pAction->iNumTpls > 0) { /* we first need to create the template pointer array */ CHKmalloc(pAction->ppTpl = (struct template **)calloc(pAction->iNumTpls, sizeof(struct template *))); -//TODO: remove //CHKmalloc(pAction->ppMsgs = (uchar**) calloc(pAction->iNumTpls, sizeof(uchar *))); - CHKmalloc(pAction->lenMsgs = (size_t*) calloc(pAction->iNumTpls, sizeof(size_t))); } for(i = 0 ; i < pAction->iNumTpls ; ++i) { diff --git a/action.h b/action.h index 1f750da1..509eada4 100644 --- a/action.h +++ b/action.h @@ -89,8 +89,6 @@ struct action_s { pthread_mutex_t mutActExec; /* mutex to guard actual execution of doAction for single-threaded modules */ uchar *pszName; /* action name (for documentation) */ int *pbShutdownImmediate;/* to facilitate shutdown, if var is 1, shut down immediately */ -// void *ppMsgs; /* pointer to action-calling parameters (kept in structure to save alloc() time!) */ - size_t *lenMsgs; /* length of message in ppMsgs */ }; diff --git a/runtime/batch.h b/runtime/batch.h index 2b3aa83e..ec257125 100644 --- a/runtime/batch.h +++ b/runtime/batch.h @@ -45,6 +45,12 @@ typedef enum { struct batch_obj_s { obj_t *pUsrp; /* pointer to user object (most often message) */ batch_state_t state; /* associated state */ + void *pActParams; /* parameters to be passed to action */ + size_t *pLenParams; /* length of the parameter in question */ + void *staticActParams[CONF_OMOD_NUMSTRINGS_BUFSIZE]; + /* a cache to save malloc(), if not absolutely necessary */ + size_t staticLenParams[CONF_OMOD_NUMSTRINGS_BUFSIZE]; + /* and the same for the message length (if used) */ }; /* the batch diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 6a717403..ab9fb738 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -58,6 +58,7 @@ * rgerhards, 2006-11-30 */ +#define CONF_OMOD_NUMSTRINGS_BUFSIZE 2 /* cache for pointers to output module buffer pointers */ /* ############################################################# * * # End Config Settings # * diff --git a/tools/omfile.c b/tools/omfile.c index 188b651b..57089cfd 100644 --- a/tools/omfile.c +++ b/tools/omfile.c @@ -555,7 +555,6 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts) iFirstFree = pData->iCurrCacheSize++; } -// RG: this is the begin of a potential problem area /* Note that the following code sequence does not work with the cache entry itself, * but rather with pData->pStrm, the (sole) stream pointer in the non-dynafile case. * The cache array is only updated after the open was successful. -- rgerhards, 2010-03-21 -- cgit