diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-01-04 16:44:41 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-01-04 16:44:41 +0000 |
commit | 3b8457d1da7f81f9d5c48ff9f1d84cb838942803 (patch) | |
tree | 457fc601c430a59d25c4a7466a2ebfdc1bdb5b14 | |
parent | eb9f97ee2d34f00ca823ebead26e133e4b9a8495 (diff) | |
download | rsyslog-3b8457d1da7f81f9d5c48ff9f1d84cb838942803.tar.gz rsyslog-3b8457d1da7f81f9d5c48ff9f1d84cb838942803.tar.xz rsyslog-3b8457d1da7f81f9d5c48ff9f1d84cb838942803.zip |
utilized the new auto-destruction capability so that the queue can now
destruct user objects if needed
-rw-r--r-- | msg.c | 12 | ||||
-rw-r--r-- | msg.h | 2 | ||||
-rw-r--r-- | obj.c | 3 | ||||
-rw-r--r-- | obj.h | 2 | ||||
-rw-r--r-- | queue.c | 13 | ||||
-rw-r--r-- | syslogd.c | 5 |
6 files changed, 26 insertions, 11 deletions
@@ -132,13 +132,15 @@ msg_t* MsgConstruct(void) /* Destructor for a msg "object". Must be called to dispose * of a msg object. */ -void MsgDestruct(msg_t * pM) +rsRetVal MsgDestruct(msg_t * pM) { assert(pM != NULL); - /* DEV Debugging only ! dbgprintf("MsgDestruct\t0x%x, Ref now: %d\n", (int)pM, pM->iRefCount - 1); */ + dbgprintf("MsgDestruct\t0x%lx, Ref now: %d\n", (unsigned long)pM, pM->iRefCount - 1); + /* DEV Debugging only ! dbgprintf("MsgDestruct\t0x%lx, Ref now: %d\n", (unsigned long)pM, pM->iRefCount - 1); */ if(--pM->iRefCount == 0) { - /* DEV Debugging Only! dbgprintf("MsgDestruct\t0x%x, RefCount now 0, doing DESTROY\n", (int)pM); */ + dbgprintf("MsgDestruct\t0x%lx, RefCount now 0, doing DESTROY\n", (unsigned long)pM); + /* DEV Debugging Only! dbgprintf("MsgDestruct\t0x%lx, RefCount now 0, doing DESTROY\n", (unsigned long)pM); */ if(pM->pszUxTradMsg != NULL) free(pM->pszUxTradMsg); if(pM->pszRawMsg != NULL) @@ -189,6 +191,8 @@ void MsgDestruct(msg_t * pM) rsCStrDestruct(pM->pCSMSGID); free(pM); } + + return RS_RET_OK; } @@ -1934,8 +1938,6 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, */ BEGINObjClassInit(Msg) OBJSetMethodHandler(objMethod_SERIALIZE, MsgSerialize); -printf("MSgSerialize pointer: %lx\n", (unsigned long) MsgSerialize); -printf("Msg objInfo: %lx\n", pObjInfoOBJ ); ENDObjClassInit /* @@ -110,7 +110,7 @@ PROTOTYPEObjClassInit(Msg); char* getProgramName(msg_t*); msg_t* MsgConstruct(void); rsRetVal MsgSerialize(uchar **ppOutBuf, size_t *pLenBuf, void *pUsr); -void MsgDestruct(msg_t * pM); +rsRetVal MsgDestruct(msg_t * pM); msg_t* MsgDup(msg_t* pOld); msg_t *MsgAddRef(msg_t *pM); void setProtocolVersion(msg_t *pM, int iNewVersion); @@ -70,7 +70,8 @@ rsRetVal objInfoConstruct(objInfo_t **ppThis, objID_t objID, uchar *pszName, rsR pThis->pszName = pszName; pThis->objID = objID; - for(i = 0 ; i < OBJ_NUM_METHODS ; ++i) { + pThis->objMethods[0] = pDestruct; + for(i = 1 ; i < OBJ_NUM_METHODS ; ++i) { pThis->objMethods[i] = objInfoNotImplementedDummy; } @@ -57,7 +57,7 @@ typedef struct obj { /* the dummy struct that each derived class can be casted t #define BEGINobjInstance objInfo_t *pObjInfo /* must be called in Constructor: */ #define objConstructSetObjInfo(pThis) ((obj_t*) (pThis))->pObjInfo = pObjInfoOBJ; -#define objDestruct(pThis) (((obj_t*) (pThis))->pObjInfo->objMethods[objMethod_DESTRUCT]) +#define objDestruct(pThis) (((obj_t*) (pThis))->pObjInfo->objMethods[objMethod_DESTRUCT])(pThis) #define objSerialize(pThis) (((obj_t*) (pThis))->pObjInfo->objMethods[objMethod_SERIALIZE]) /* class initializer */ #define PROTOTYPEObjClassInit(objName) rsRetVal objName##ClassInit(void) @@ -235,7 +235,6 @@ rsRetVal qAddDisk(queue_t *pThis, void* pUsr) assert(pThis != NULL); dbgprintf("writing to file %d\n", pThis->tVars.disk.fd); -dbgprintf("objInfo: %lx\n", (unsigned long)pUsr); CHKiRet((objSerialize(pUsr))(pBuf, &lenBuf, pUsr)); // TODO: hier weiter machen! i = write(pThis->tVars.disk.fd, "entry\n", 6); dbgprintf("write wrote %d bytes, errno: %d, err %s\n", i, errno, strerror(errno)); @@ -338,8 +337,17 @@ queueWorker(void *arg) * rgerhards, 2008-01-03 */ if(iRet == RS_RET_OK) { + rsRetVal iRetLocal; dbgprintf("Worker for queue 0x%lx is running...\n", (unsigned long) pThis); - pThis->pConsumer(pUsr); + iRetLocal = pThis->pConsumer(pUsr); + if(iRetLocal != RS_RET_OK) + dbgprintf("Queue 0x%lx: Consumer returned iRet %d\n", + (unsigned long) pThis, iRetLocal); +dbgprintf("QUEUE: consumer done\n"); + iRetLocal = objDestruct(pUsr); + if(iRetLocal != RS_RET_OK) + dbgprintf("Queue 0x%lx: Destructor returned iRet %d\n", + (unsigned long) pThis, iRetLocal); } else { dbgprintf("Queue 0x%lx: error %d dequeueing element - ignoring, but strange things " "may happen\n", (unsigned long) pThis, iRet); @@ -487,6 +495,7 @@ queueEnqObj(queue_t *pThis, void *pUsr) if(pthread_cond_timedwait (pThis->notFull, pThis->mut, &t) != 0) { dbgprintf("Queue 0x%lx: enqueueMsg: cond timeout, dropping message!\n", (unsigned long) pThis); + objDestruct(pUsr); ABORT_FINALIZE(RS_RET_QUEUE_FULL); } } @@ -1858,6 +1858,7 @@ static void processMsg(msg_t *pMsg) * NOTE: Having more than one worker requires guarding of some * message object structures and potentially others - need to be checked * before we support multiple worker threads on the message queue. + * Please note: the message object is destructed by the queue itself! */ static rsRetVal msgConsumer(void *pUsr) @@ -1867,7 +1868,6 @@ msgConsumer(void *pUsr) assert(pMsg != NULL); processMsg(pMsg); - MsgDestruct(pMsg); return RS_RET_OK; } @@ -2338,10 +2338,13 @@ logmsg(int pri, msg_t *pMsg, int flags) */ pMsg->msgFlags = flags; + queueEnqObj(pMsgQueue, (void*) pMsg); +#if 0 CHKiRet_Hdlr(queueEnqObj(pMsgQueue, (void*) pMsg)) { /* if we have an error return, the pMsg was not destructed */ MsgDestruct(pMsg); } +#endif } |