diff options
Diffstat (limited to 'plugins/imdiag/imdiag.c')
-rw-r--r-- | plugins/imdiag/imdiag.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/plugins/imdiag/imdiag.c b/plugins/imdiag/imdiag.c index 5fdc6ef..023d6f3 100644 --- a/plugins/imdiag/imdiag.c +++ b/plugins/imdiag/imdiag.c @@ -1,13 +1,11 @@ /* imdiag.c - * This is a diagnostics module, primarily meant for troubleshooting - * and information about the runtime state of rsyslog. It is implemented - * as an input plugin, because that interface best suits our needs - * and also enables us to inject test messages (something not yet - * implemented). + * This is a testbench tool. It started out with a broader scope, + * but we dropped this idea. To learn about rsyslog runtime statistics + * have a look at impstats. * * File begun on 2008-07-25 by RGerhards * - * Copyright 2008-2012 Adiscon GmbH. + * Copyright 2008-2014 Adiscon GmbH. * * This file is part of rsyslog. * @@ -54,6 +52,7 @@ #include "msg.h" #include "datetime.h" #include "ratelimit.h" +#include "queue.h" #include "net.h" /* for permittedPeers, may be removed when this is removed */ MODULE_TYPE_INPUT @@ -238,7 +237,7 @@ injectMsg(uchar *pszCmd, tcps_sess_t *pSess) int iFrom; int nMsgs; int i; - ratelimit_t *ratelimit; + ratelimit_t *ratelimit = NULL; DEFiRet; /* we do not check errors here! */ @@ -246,7 +245,7 @@ injectMsg(uchar *pszCmd, tcps_sess_t *pSess) iFrom = atoi((char*)wordBuf); getFirstWord(&pszCmd, wordBuf, sizeof(wordBuf)/sizeof(uchar), TO_LOWERCASE); nMsgs = atoi((char*)wordBuf); - ratelimitNew(&ratelimit, "imdiag", "injectmsg"); + CHKiRet(ratelimitNew(&ratelimit, "imdiag", "injectmsg")); for(i = 0 ; i < nMsgs ; ++i) { doInjectMsg(i + iFrom, ratelimit); @@ -254,41 +253,41 @@ injectMsg(uchar *pszCmd, tcps_sess_t *pSess) CHKiRet(sendResponse(pSess, "%d messages injected\n", nMsgs)); DBGPRINTF("imdiag: %d messages injected\n", nMsgs); - ratelimitDestruct(ratelimit); finalize_it: + if(ratelimit != NULL) + ratelimitDestruct(ratelimit); RETiRet; } -/* This function waits until the main queue is drained (size = 0) +/* This function waits until all queues are drained (size = 0) * To make sure it really is drained, we check three times. Otherwise we * may just see races. + * Note: until 2014--07-13, this checked just the main queue. However, + * the testbench was the sole user and checking all queues makes much more + * sense. So we change function semantics instead of carrying the old + * semantics over and crafting a new function. -- rgerhards */ static rsRetVal waitMainQEmpty(tcps_sess_t *pSess) { - int iMsgQueueSize; int iPrint = 0; DEFiRet; - CHKiRet(diagGetMainMsgQSize(&iMsgQueueSize)); while(1) { - if(iMsgQueueSize == 0) { + if(iOverallQueueSize == 0) { /* verify that queue is still empty (else it could just be a race!) */ srSleep(0,250000);/* wait a little bit */ - CHKiRet(diagGetMainMsgQSize(&iMsgQueueSize)); - if(iMsgQueueSize == 0) { + if(iOverallQueueSize == 0) { srSleep(0,500000);/* wait a little bit */ - CHKiRet(diagGetMainMsgQSize(&iMsgQueueSize)); } } - if(iMsgQueueSize == 0) + if(iOverallQueueSize == 0) break; if(iPrint++ % 500 == 0) - dbgprintf("imdiag sleeping, wait mainq drain, curr size %d\n", iMsgQueueSize); + dbgprintf("imdiag sleeping, wait queues drain, curr size %d\n", iOverallQueueSize); srSleep(0,200000);/* wait a little bit */ - CHKiRet(diagGetMainMsgQSize(&iMsgQueueSize)); } CHKiRet(sendResponse(pSess, "mainqueue empty\n")); @@ -304,7 +303,6 @@ finalize_it: static rsRetVal OnMsgReceived(tcps_sess_t *pSess, uchar *pRcv, int iLenMsg) { - int iMsgQueueSize; uchar *pszMsg; uchar *pToFree = NULL; uchar cmdBuf[1024]; @@ -326,9 +324,8 @@ OnMsgReceived(tcps_sess_t *pSess, uchar *pRcv, int iLenMsg) dbgprintf("imdiag received command '%s'\n", cmdBuf); if(!ustrcmp(cmdBuf, UCHAR_CONSTANT("getmainmsgqueuesize"))) { - CHKiRet(diagGetMainMsgQSize(&iMsgQueueSize)); - CHKiRet(sendResponse(pSess, "%d\n", iMsgQueueSize)); - DBGPRINTF("imdiag: %d messages in main queue\n", iMsgQueueSize); + CHKiRet(sendResponse(pSess, "%d\n", iOverallQueueSize)); + DBGPRINTF("imdiag: %d messages in main queue\n", iOverallQueueSize); } else if(!ustrcmp(cmdBuf, UCHAR_CONSTANT("waitmainqueueempty"))) { CHKiRet(waitMainQEmpty(pSess)); } else if(!ustrcmp(cmdBuf, UCHAR_CONSTANT("injectmsg"))) { |