summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-04 16:44:41 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-04 16:44:41 +0000
commit3b8457d1da7f81f9d5c48ff9f1d84cb838942803 (patch)
tree457fc601c430a59d25c4a7466a2ebfdc1bdb5b14
parenteb9f97ee2d34f00ca823ebead26e133e4b9a8495 (diff)
downloadrsyslog-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.c12
-rw-r--r--msg.h2
-rw-r--r--obj.c3
-rw-r--r--obj.h2
-rw-r--r--queue.c13
-rw-r--r--syslogd.c5
6 files changed, 26 insertions, 11 deletions
diff --git a/msg.c b/msg.c
index ddf6004e..f6e015ac 100644
--- a/msg.c
+++ b/msg.c
@@ -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
/*
diff --git a/msg.h b/msg.h
index d919cc62..467562fa 100644
--- a/msg.h
+++ b/msg.h
@@ -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);
diff --git a/obj.c b/obj.c
index a03ae345..db9b5f24 100644
--- a/obj.c
+++ b/obj.c
@@ -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;
}
diff --git a/obj.h b/obj.h
index 5f0921f3..43d45bb6 100644
--- a/obj.h
+++ b/obj.h
@@ -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)
diff --git a/queue.c b/queue.c
index 8eb98d72..19e92e9c 100644
--- a/queue.c
+++ b/queue.c
@@ -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);
}
}
diff --git a/syslogd.c b/syslogd.c
index af4ec5bf..bb0526c7 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -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
}