From d92ad440da788fea9f17bfa4b0185f12644bf714 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 22 Aug 2012 14:30:12 +0200 Subject: bugfix: multiple main queues with same queue file name were not detected This lead to queue file corruption. While the root cause is a config error, it is a bug that this important and hard to find config error was not detected by rsyslog. --- tools/syslogd.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/syslogd.c b/tools/syslogd.c index 8fc1d1e1..d8e50327 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -231,6 +231,11 @@ typedef struct legacyOptsLL_s { } legacyOptsLL_t; legacyOptsLL_t *pLegacyOptsLL = NULL; +struct queuefilenames_s { + struct queuefilenames_s *next; + uchar *name; +} *queuefilenames = NULL; + /* global variables for config file state */ int iCompatibilityMode = 0; /* version we should be compatible with; 0 means sysklogd. It is the default, so if no -c option is given, we make ourselvs @@ -1031,6 +1036,14 @@ static void doDie(int sig) static void freeAllDynMemForTermination(void) { + struct queuefilenames_s *qfn, *qfnDel; + + for(qfn = queuefilenames ; qfn != NULL ; ) { + qfnDel = qfn; + qfn = qfn->next; + free(qfnDel->name); + free(qfnDel); + } free(pszMainMsgQFName); free(pModDir); free(pszConfDAGFile); @@ -1559,6 +1572,10 @@ startInputModules(void) */ rsRetVal createMainQueue(qqueue_t **ppQueue, uchar *pszQueueName) { + struct queuefilenames_s *qfn; + uchar *qfname = NULL; + static int qfn_renamenum = 0; + uchar qfrenamebuf[1024]; DEFiRet; /* switch the message object to threaded operation, if necessary */ @@ -1584,10 +1601,32 @@ rsRetVal createMainQueue(qqueue_t **ppQueue, uchar *pszQueueName) errmsg.LogError(0, NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ } + if(pszMainMsgQFName != NULL) { + /* check if the queue file name is unique, else emit an error */ + for(qfn = queuefilenames ; qfn != NULL ; qfn = qfn->next) { + dbgprintf("check queue file name '%s' vs '%s'\n", qfn->name, pszMainMsgQFName); + if(!ustrcmp(qfn->name, pszMainMsgQFName)) { + snprintf((char*)qfrenamebuf, sizeof(qfrenamebuf), "%d-%s-%s", + ++qfn_renamenum, pszMainMsgQFName, + (pszQueueName == NULL) ? "NONAME" : (char*)pszQueueName); + qfname = ustrdup(qfrenamebuf); + errmsg.LogError(0, NO_ERRCODE, "Error: queue file name '%s' already in use " + " - using '%s' instead", pszMainMsgQFName, qfname); + break; + } + } + if(qfname == NULL) + qfname = ustrdup(pszMainMsgQFName); + qfn = malloc(sizeof(struct queuefilenames_s)); + qfn->name = qfname; + qfn->next = queuefilenames; + queuefilenames = qfn; + } + setQPROP(qqueueSetMaxFileSize, "$MainMsgQueueFileSize", iMainMsgQueMaxFileSize); setQPROP(qqueueSetsizeOnDiskMax, "$MainMsgQueueMaxDiskSpace", iMainMsgQueMaxDiskSpace); setQPROP(qqueueSetiDeqBatchSize, "$MainMsgQueueDequeueBatchSize", iMainMsgQueDeqBatchSize); - setQPROPstr(qqueueSetFilePrefix, "$MainMsgQueueFileName", pszMainMsgQFName); + setQPROPstr(qqueueSetFilePrefix, "$MainMsgQueueFileName", qfname); setQPROP(qqueueSetiPersistUpdCnt, "$MainMsgQueueCheckpointInterval", iMainMsgQPersistUpdCnt); setQPROP(qqueueSetbSyncQueueFiles, "$MainMsgQueueSyncQueueFiles", bMainMsgQSyncQeueFiles); setQPROP(qqueueSettoQShutdown, "$MainMsgQueueTimeoutShutdown", iMainMsgQtoQShutdown ); -- cgit From 9faf2240c4a8f09f3f6c2c9bbd47e48520524e03 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 22 Aug 2012 15:29:02 +0200 Subject: changed TRUE/FALSE to RSTRUE/RSFALSE This is done to prevent name claches with libraries. --- tools/omfwd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/omfwd.c b/tools/omfwd.c index b456db17..812da109 100644 --- a/tools/omfwd.c +++ b/tools/omfwd.c @@ -207,12 +207,12 @@ static rsRetVal UDPSend(instanceData *pData, char *msg, size_t len) * call fails. Then, lsent has the error status, even though * the sendto() succeeded. -- rgerhards, 2007-06-22 */ - bSendSuccess = FALSE; + bSendSuccess = RSFALSE; for (r = pData->f_addr; r; r = r->ai_next) { for (i = 0; i < *pData->pSockArray; i++) { lsent = sendto(pData->pSockArray[i+1], msg, len, 0, r->ai_addr, r->ai_addrlen); if (lsent == len) { - bSendSuccess = TRUE; + bSendSuccess = RSTRUE; break; } else { int eno = errno; @@ -225,7 +225,7 @@ static rsRetVal UDPSend(instanceData *pData, char *msg, size_t len) break; } /* finished looping */ - if (bSendSuccess == FALSE) { + if (bSendSuccess == RSFALSE) { dbgprintf("error forwarding via udp, suspending\n"); iRet = RS_RET_SUSPENDED; } -- cgit