From f9b6b94b802c653e6c588f42af0997682e75f267 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 21 Feb 2012 16:52:36 +0100 Subject: added configuration directives to customize queue light delay marks $MainMsgQueueLightDelayMark, $ActionQueueLightDelayMark; both specify number of messages starting at which a delay happens. --- tools/syslogd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tools/syslogd.c') diff --git a/tools/syslogd.c b/tools/syslogd.c index 0b7bbc96..4c537570 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -262,6 +262,7 @@ static uchar *pszConfDAGFile = NULL; /* name of config DAG file, non-NULL mea qqueue_t *pMsgQueue = NULL; /* the main message queue */ static int iMainMsgQueueSize = 10000; /* size of the main message queue above */ static int iMainMsgQHighWtrMark = 8000; /* high water mark for disk-assisted queues */ +static int iMainMsgQLightDlyMark = 7000; /* light delay mark for disk-assisted queues */ static int iMainMsgQLowWtrMark = 2000; /* low water mark for disk-assisted queues */ static int iMainMsgQDiscardMark = 9800; /* begin to discard messages */ static int iMainMsgQDiscardSeverity = 8; /* by default, discard nothing to prevent unintentional loss */ @@ -300,6 +301,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a pszMainMsgQFName = NULL; iMainMsgQueueSize = 10000; iMainMsgQHighWtrMark = 8000; + iMainMsgQLightDlyMark = 7000; iMainMsgQLowWtrMark = 2000; iMainMsgQDiscardMark = 9800; iMainMsgQDiscardSeverity = 8; @@ -1457,8 +1459,8 @@ static void dbgPrintInitInfo(void) iMainMsgQueueNumWorkers, iMainMsgQtoWrkShutdown, iMainMsgQPersistUpdCnt); DBGPRINTF("Main queue timeouts: shutdown: %d, action completion shutdown: %d, enq: %d\n", iMainMsgQtoQShutdown, iMainMsgQtoActShutdown, iMainMsgQtoEnq); - DBGPRINTF("Main queue watermarks: high: %d, low: %d, discard: %d, discard-severity: %d\n", - iMainMsgQHighWtrMark, iMainMsgQLowWtrMark, iMainMsgQDiscardMark, iMainMsgQDiscardSeverity); + DBGPRINTF("Main queue watermarks: high: %d, low: %d, discard: %d, discard-severity: %d, light-delay %d\n", + iMainMsgQHighWtrMark, iMainMsgQLowWtrMark, iMainMsgQDiscardMark, iMainMsgQDiscardSeverity, iMainMsgQLightDlyMark); DBGPRINTF("Main queue save on shutdown %d, max disk space allowed %lld\n", bMainMsgQSaveOnShutdown, iMainMsgQueMaxDiskSpace); /* TODO: add @@ -1574,6 +1576,7 @@ rsRetVal createMainQueue(qqueue_t **ppQueue, uchar *pszQueueName) setQPROP(qqueueSetiHighWtrMrk, "$MainMsgQueueHighWaterMark", iMainMsgQHighWtrMark); setQPROP(qqueueSetiLowWtrMrk, "$MainMsgQueueLowWaterMark", iMainMsgQLowWtrMark); setQPROP(qqueueSetiDiscardMrk, "$MainMsgQueueDiscardMark", iMainMsgQDiscardMark); + setQPROP(qqueueSetiLightDlyMrk, "$MainMsgQueueLightDelayMark", iMainMsgQLightDlyMark); setQPROP(qqueueSetiDiscardSeverity, "$MainMsgQueueDiscardSeverity", iMainMsgQDiscardSeverity); setQPROP(qqueueSetiMinMsgsPerWrkr, "$MainMsgQueueWorkerThreadMinimumMessages", iMainMsgQWrkMinMsgs); setQPROP(qqueueSetbSaveOnShutdown, "$MainMsgQueueSaveOnShutdown", bMainMsgQSaveOnShutdown); @@ -2051,6 +2054,7 @@ static rsRetVal loadBuildInModules(void) CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuehighwatermark", 0, eCmdHdlrInt, NULL, &iMainMsgQHighWtrMark, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuelowwatermark", 0, eCmdHdlrInt, NULL, &iMainMsgQLowWtrMark, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuediscardmark", 0, eCmdHdlrInt, NULL, &iMainMsgQDiscardMark, NULL)); + CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuelightdelaymark", 0, eCmdHdlrInt, NULL, &iMainMsgQLightDlyMark, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuediscardseverity", 0, eCmdHdlrSeverity, NULL, &iMainMsgQDiscardSeverity, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuecheckpointinterval", 0, eCmdHdlrInt, NULL, &iMainMsgQPersistUpdCnt, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuesyncqueuefiles", 0, eCmdHdlrBinary, NULL, &bMainMsgQSyncQeueFiles, NULL)); -- cgit v1.2.3 From 5c09faee34befd6c2fa117055928c810ccf86f91 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 22 Feb 2012 09:43:25 +0100 Subject: queue: lightdelay config: keep default of 70% until mark is explicitely set --- tools/syslogd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tools/syslogd.c') diff --git a/tools/syslogd.c b/tools/syslogd.c index 4c537570..c0e663d2 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -262,7 +262,7 @@ static uchar *pszConfDAGFile = NULL; /* name of config DAG file, non-NULL mea qqueue_t *pMsgQueue = NULL; /* the main message queue */ static int iMainMsgQueueSize = 10000; /* size of the main message queue above */ static int iMainMsgQHighWtrMark = 8000; /* high water mark for disk-assisted queues */ -static int iMainMsgQLightDlyMark = 7000; /* light delay mark for disk-assisted queues */ +static int iMainMsgQLightDlyMark = -1; /* light delay mark for disk-assisted queues */ static int iMainMsgQLowWtrMark = 2000; /* low water mark for disk-assisted queues */ static int iMainMsgQDiscardMark = 9800; /* begin to discard messages */ static int iMainMsgQDiscardSeverity = 8; /* by default, discard nothing to prevent unintentional loss */ @@ -301,7 +301,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a pszMainMsgQFName = NULL; iMainMsgQueueSize = 10000; iMainMsgQHighWtrMark = 8000; - iMainMsgQLightDlyMark = 7000; + iMainMsgQLightDlyMark = -1; iMainMsgQLowWtrMark = 2000; iMainMsgQDiscardMark = 9800; iMainMsgQDiscardSeverity = 8; @@ -1576,7 +1576,9 @@ rsRetVal createMainQueue(qqueue_t **ppQueue, uchar *pszQueueName) setQPROP(qqueueSetiHighWtrMrk, "$MainMsgQueueHighWaterMark", iMainMsgQHighWtrMark); setQPROP(qqueueSetiLowWtrMrk, "$MainMsgQueueLowWaterMark", iMainMsgQLowWtrMark); setQPROP(qqueueSetiDiscardMrk, "$MainMsgQueueDiscardMark", iMainMsgQDiscardMark); - setQPROP(qqueueSetiLightDlyMrk, "$MainMsgQueueLightDelayMark", iMainMsgQLightDlyMark); + if(iMainMsgQLightDlyMark > 0) { + setQPROP(qqueueSetiLightDlyMrk, "$MainMsgQueueLightDelayMark", iMainMsgQLightDlyMark); + } setQPROP(qqueueSetiDiscardSeverity, "$MainMsgQueueDiscardSeverity", iMainMsgQDiscardSeverity); setQPROP(qqueueSetiMinMsgsPerWrkr, "$MainMsgQueueWorkerThreadMinimumMessages", iMainMsgQWrkMinMsgs); setQPROP(qqueueSetbSaveOnShutdown, "$MainMsgQueueSaveOnShutdown", bMainMsgQSaveOnShutdown); -- cgit v1.2.3 From 9601b181cf5d2166e2c813973e82a4b48002e83f Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 6 Mar 2012 17:26:04 +0100 Subject: added capability to use a local interface IP address as fromhost-ip for imuxsock new config directives: $IMUXSockLocalIPIF --- tools/syslogd.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/syslogd.c') diff --git a/tools/syslogd.c b/tools/syslogd.c index c0e663d2..02a0dad6 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -2712,6 +2712,7 @@ int realMain(int argc, char **argv) CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_aliases[i])); } else { CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name)); + int i; } if((p = (uchar*)strchr((char*)LocalHostName, '.'))) -- cgit v1.2.3 From 2c7604f45b1c416180794f2c4f29ba25504f8d47 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 12 Mar 2012 17:01:44 +0100 Subject: cosmetic: removed stray definition --- tools/syslogd.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tools/syslogd.c') diff --git a/tools/syslogd.c b/tools/syslogd.c index 92c539c7..33330a95 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -2725,7 +2725,6 @@ int realMain(int argc, char **argv) CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_aliases[i])); } else { CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name)); - int i; } if((p = (uchar*)strchr((char*)LocalHostName, '.'))) -- cgit v1.2.3 From 49ec54d36984b9e91da7bd41e56e65dac22ce830 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 21 Mar 2012 11:43:45 +0100 Subject: milestone: added capability to use a local interface IP address as fromhost-ip ... for locally originating messages. New directive $LocalHostIPIF. Note that not all modules yet support this new directive - next step... --- tools/syslogd.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'tools/syslogd.c') diff --git a/tools/syslogd.c b/tools/syslogd.c index 02a0dad6..9cd3c9ca 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -199,7 +199,6 @@ static rsRetVal GlobalClassExit(void); #endif static prop_t *pInternalInputName = NULL; /* there is only one global inputName for all internally-generated messages */ -static prop_t *pLocalHostIP = NULL; /* there is only one global IP for all internally-generated messages */ static uchar *ConfFile = (uchar*) _PATH_LOGCONF; /* read-only after startup */ static char *PidFile = _PATH_LOGPID; /* read-only after startup */ @@ -545,7 +544,8 @@ logmsgInternal(int iErr, int pri, uchar *msg, int flags) MsgSetRawMsgWOSize(pMsg, (char*)msg); MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName())); MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp()); - MsgSetRcvFromIP(pMsg, pLocalHostIP); +dbgprintf("ZZZZ: pLocalHostIPIF used!\n"); + MsgSetRcvFromIP(pMsg, glbl.GetLocalHostIP()); MsgSetMSGoffs(pMsg, 0); /* check if we have an error code associated and, if so, * adjust the tag. -- rgerhards, 2008-06-27 @@ -1109,8 +1109,6 @@ die(int sig) /* destruct our global properties */ if(pInternalInputName != NULL) prop.Destruct(&pInternalInputName); - if(pLocalHostIP != NULL) - prop.Destruct(&pLocalHostIP); /* terminate the remaining classes */ GlobalClassExit(); @@ -2660,10 +2658,6 @@ int realMain(int argc, char **argv) CHKiRet(prop.SetString(pInternalInputName, UCHAR_CONSTANT("rsyslogd"), sizeof("rsyslgod") - 1)); CHKiRet(prop.ConstructFinalize(pInternalInputName)); - CHKiRet(prop.Construct(&pLocalHostIP)); - CHKiRet(prop.SetString(pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1)); - CHKiRet(prop.ConstructFinalize(pLocalHostIP)); - /* get our host and domain names - we need to do this early as we may emit * error log messages, which need the correct hostname. -- rgerhards, 2008-04-04 */ @@ -2712,7 +2706,6 @@ int realMain(int argc, char **argv) CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_aliases[i])); } else { CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name)); - int i; } if((p = (uchar*)strchr((char*)LocalHostName, '.'))) -- cgit v1.2.3 From d0a73d3449511392b115ca078517ff659aafe23d Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 11 Apr 2012 11:18:41 +0200 Subject: bugfix: hostname was not requeried on HUP Thanks to Marius Tomaschewski for reporting this bug. --- tools/syslogd.c | 165 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 93 insertions(+), 72 deletions(-) (limited to 'tools/syslogd.c') diff --git a/tools/syslogd.c b/tools/syslogd.c index 0b7bbc96..183decb1 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -154,6 +154,7 @@ DEFobjCurrIf(net) /* TODO: make go away! */ /* forward definitions */ static rsRetVal GlobalClassExit(void); +static rsRetVal queryLocalHostname(void); #ifndef _PATH_LOGCONF @@ -1897,6 +1898,11 @@ DEFFUNC_llExecFunc(doHUPActions) * is *NOT* the sighup handler. The signal is recorded by the handler, that record * detected inside the mainloop and then this function is called to do the * real work. -- rgerhards, 2008-10-22 + * Note: there is a VERY slim chance of a data race when the hostname is reset. + * We prefer to take this risk rather than sync all accesses, because to the best + * of my analysis it can not really hurt (the actual property is reference-counted) + * but the sync would require some extra CPU for *each* message processed. + * rgerhards, 2012-04-11 */ static inline void doHUP(void) @@ -1912,6 +1918,7 @@ doHUP(void) logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, (uchar*)buf, 0); } + queryLocalHostname(); /* re-read our name */ ruleset.IterateAllActions(doHUPActions, NULL); } @@ -2329,6 +2336,90 @@ GlobalClassExit(void) } +/* query our host and domain names - we need to do this early as we may emit + * rgerhards, 2012-04-11 + */ +static rsRetVal +queryLocalHostname(void) +{ + uchar *LocalHostName; + uchar *LocalDomain; + uchar *LocalFQDNName; + uchar *p; + struct hostent *hent; + DEFiRet; + + net.getLocalHostname(&LocalFQDNName); + CHKmalloc(LocalHostName = (uchar*) strdup((char*)LocalFQDNName)); + glbl.SetLocalFQDNName(LocalFQDNName); /* set the FQDN before we modify it */ + if((p = (uchar*)strchr((char*)LocalHostName, '.'))) { + *p++ = '\0'; + LocalDomain = p; + } else { + LocalDomain = (uchar*)""; + + /* It's not clearly defined whether gethostname() + * should return the simple hostname or the fqdn. A + * good piece of software should be aware of both and + * we want to distribute good software. Joey + * + * Good software also always checks its return values... + * If syslogd starts up before DNS is up & /etc/hosts + * doesn't have LocalHostName listed, gethostbyname will + * return NULL. + */ + /* TODO: gethostbyname() is not thread-safe, but replacing it is + * not urgent as we do not run on multiple threads here. rgerhards, 2007-09-25 + */ + hent = gethostbyname((char*)LocalHostName); + if(hent) { + int i = 0; + + if(hent->h_aliases) { + size_t hnlen; + + hnlen = strlen((char *) LocalHostName); + + for (i = 0; hent->h_aliases[i]; i++) { + if (!strncmp(hent->h_aliases[i], (char *) LocalHostName, hnlen) + && hent->h_aliases[i][hnlen] == '.') { + /* found a matching hostname */ + break; + } + } + } + + free(LocalHostName); + if(hent->h_aliases && hent->h_aliases[i]) { + CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_aliases[i])); + } else { + CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name)); + } + + if((p = (uchar*)strchr((char*)LocalHostName, '.'))) + { + *p++ = '\0'; + LocalDomain = p; + } + } + } + + /* Convert to lower case to recognize the correct domain laterly */ + for(p = LocalDomain ; *p ; p++) + *p = (char)tolower((int)*p); + + /* we now have our hostname and can set it inside the global vars. + * TODO: think if all of this would better be a runtime function + * rgerhards, 2008-04-17 + */ + glbl.SetLocalHostName(LocalHostName); + glbl.SetLocalDomain(LocalDomain); + glbl.GenerateLocalHostNameProperty(); /* must be redone after conf processing, FQDN setting may have changed */ +finalize_it: + RETiRet; +} + + /* some support for command line option parsing. Any non-trivial options must be * buffered until the complete command line has been parsed. This is necessary to * prevent dependencies between the options. That, in turn, means we need to have @@ -2530,9 +2621,7 @@ int realMain(int argc, char **argv) { DEFiRet; - register uchar *p; int ch; - struct hostent *hent; extern int optind; extern char *optarg; int bEOptionWasGiven = 0; @@ -2541,9 +2630,6 @@ int realMain(int argc, char **argv) int bChDirRoot = 1; /* change the current working directory to "/"? */ char *arg; /* for command line option processing */ uchar legacyConfLine[80]; - uchar *LocalHostName; - uchar *LocalDomain; - uchar *LocalFQDNName; char cwdbuf[128]; /* buffer to obtain/display current working directory */ /* first, parse the command line options. We do not carry out any actual work, just @@ -2651,7 +2737,7 @@ int realMain(int argc, char **argv) /* we need to create the inputName property (only once during our lifetime) */ CHKiRet(prop.Construct(&pInternalInputName)); - CHKiRet(prop.SetString(pInternalInputName, UCHAR_CONSTANT("rsyslogd"), sizeof("rsyslgod") - 1)); + CHKiRet(prop.SetString(pInternalInputName, UCHAR_CONSTANT("rsyslogd"), sizeof("rsyslogd") - 1)); CHKiRet(prop.ConstructFinalize(pInternalInputName)); CHKiRet(prop.Construct(&pLocalHostIP)); @@ -2661,72 +2747,7 @@ int realMain(int argc, char **argv) /* get our host and domain names - we need to do this early as we may emit * error log messages, which need the correct hostname. -- rgerhards, 2008-04-04 */ - net.getLocalHostname(&LocalFQDNName); - CHKmalloc(LocalHostName = (uchar*) strdup((char*)LocalFQDNName)); - glbl.SetLocalFQDNName(LocalFQDNName); /* set the FQDN before we modify it */ - if((p = (uchar*)strchr((char*)LocalHostName, '.'))) { - *p++ = '\0'; - LocalDomain = p; - } else { - LocalDomain = (uchar*)""; - - /* It's not clearly defined whether gethostname() - * should return the simple hostname or the fqdn. A - * good piece of software should be aware of both and - * we want to distribute good software. Joey - * - * Good software also always checks its return values... - * If syslogd starts up before DNS is up & /etc/hosts - * doesn't have LocalHostName listed, gethostbyname will - * return NULL. - */ - /* TODO: gethostbyname() is not thread-safe, but replacing it is - * not urgent as we do not run on multiple threads here. rgerhards, 2007-09-25 - */ - hent = gethostbyname((char*)LocalHostName); - if(hent) { - int i = 0; - - if(hent->h_aliases) { - size_t hnlen; - - hnlen = strlen((char *) LocalHostName); - - for (i = 0; hent->h_aliases[i]; i++) { - if (!strncmp(hent->h_aliases[i], (char *) LocalHostName, hnlen) - && hent->h_aliases[i][hnlen] == '.') { - /* found a matching hostname */ - break; - } - } - } - - free(LocalHostName); - if(hent->h_aliases && hent->h_aliases[i]) { - CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_aliases[i])); - } else { - CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name)); - } - - if((p = (uchar*)strchr((char*)LocalHostName, '.'))) - { - *p++ = '\0'; - LocalDomain = p; - } - } - } - - /* Convert to lower case to recognize the correct domain laterly */ - for(p = LocalDomain ; *p ; p++) - *p = (char)tolower((int)*p); - - /* we now have our hostname and can set it inside the global vars. - * TODO: think if all of this would better be a runtime function - * rgerhards, 2008-04-17 - */ - glbl.SetLocalHostName(LocalHostName); - glbl.SetLocalDomain(LocalDomain); - glbl.GenerateLocalHostNameProperty(); /* must be redone after conf processing, FQDN setting may have changed */ + queryLocalHostname(); /* initialize the objects */ if((iRet = modInitIminternal()) != RS_RET_OK) { -- cgit v1.2.3 From a3a0acadb4aa9d09bde3a6951557939b0a0eeda6 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Wed, 11 Apr 2012 14:39:42 +0200 Subject: Allocate LocalDomain as new string LocalDomain points to "" or the domain in LocalHostName, allocate as new string before passing to SetLocalDomain or free will fail later. Signed-off-by: Marius Tomaschewski --- tools/syslogd.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/syslogd.c') diff --git a/tools/syslogd.c b/tools/syslogd.c index 183decb1..5e94beab 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -2404,6 +2404,9 @@ queryLocalHostname(void) } } + /* LocalDomain is "" or part of LocalHostName, allocate a new string */ + CHKmalloc(LocalDomain = (uchar*)strdup(LocalDomain)); + /* Convert to lower case to recognize the correct domain laterly */ for(p = LocalDomain ; *p ; p++) *p = (char)tolower((int)*p); -- cgit v1.2.3 From d749dadcc30e35448894a152fb0ddf77d60b8300 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 12 Apr 2012 10:14:32 +0200 Subject: imuxsock: do not cache hostname --- tools/syslogd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/syslogd.c') diff --git a/tools/syslogd.c b/tools/syslogd.c index 5e94beab..af63b111 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -21,7 +21,7 @@ * For further information, please see http://www.rsyslog.com * * rsyslog - An Enhanced syslogd Replacement. - * Copyright 2003-2009 Rainer Gerhards and Adiscon GmbH. + * Copyright 2003-2012 Rainer Gerhards and Adiscon GmbH. * * This file is part of rsyslog. * -- cgit v1.2.3