From 5b9f98ee20a245cd5245717b168d7428c6bdad31 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 7 Sep 2007 08:56:43 +0000 Subject: - added eCmdHdlrGetWord command handler - added $ModDir config directive --- ChangeLog | 7 +++++++ cfsysline.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ cfsysline.h | 3 ++- syslogd.c | 14 +++++++++++--- 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 844755c0..b939add9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ --------------------------------------------------------------------------- Version 1.19.5 (rgerhards), 2007-09-0? +- changed part of the CStr interface so that better error tracking + is provided and the calling sequence is more intuitive (there were + invalid calls based on a too-weired interface) +- (hopefully) fixed some remaining bugs rooted in wrong use of + the CStr class. These could lead to program abort. --------------------------------------------------------------------------- Version 1.19.4 (rgerhards/varmojfekoj), 2007-09-04 - fixed a number of small memory leaks - thanks varmojfekoj for patching @@ -21,6 +26,8 @@ Version 1.19.3 (mmeckelein/varmojfekoj), 2007-08-31 to varmojfekoj - the negative selector for program name filter (Blocks) does not work as expected - Thanks varmojfekoj for patching +- added forwarding information to sysklogd (requires special template) + to config doc --------------------------------------------------------------------------- Version 1.19.2 (mmeckelein/varmojfekoj), 2007-08-28 - a specifically formed message caused a segfault - Many thanks varmojfekoj diff --git a/cfsysline.c b/cfsysline.c index b17683c6..24e652d7 100644 --- a/cfsysline.c +++ b/cfsysline.c @@ -348,6 +348,58 @@ finalize_it: } +/* Parse and a word config line option. A word is a consequitive + * sequence of non-whitespace characters. pVal must be + * a pointer to a string which is to receive the option + * value. The returned string must be freed by the caller. + * rgerhards, 2007-09-07 + */ +static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void *pVal) +{ + DEFiRet; + rsCStrObj *pStrB; + uchar *p; + uchar *pNewVal; + + assert(pp != NULL); + assert(*pp != NULL); + + if((pStrB = rsCStrConstruct()) == NULL) + return RS_RET_OUT_OF_MEMORY; + + /* parse out the word */ + p = *pp; + + while(*p && !isspace((int) *p)) { + CHKiRet(rsCStrAppendChar(pStrB, *p++)); + } + CHKiRet(rsCStrFinish(pStrB)); + + CHKiRet(rsCStrConvSzStrAndDestruct(pStrB, &pNewVal, 0)); +dbgprintf("pNewVal: %s\n", pNewVal); + + /* we got the word, now set it */ + if(pSetHdlr == NULL) { + /* we should set value directly to var */ + *((uchar**)pVal) = pNewVal; + } else { + /* we set value via a set function */ + CHKiRet(pSetHdlr(pVal, pNewVal)); + } + + *pp = p; + skipWhiteSpace(pp); /* skip over any whitespace */ + +finalize_it: + if(iRet != RS_RET_OK) { + if(pStrB != NULL) + rsCStrDestruct(pStrB); + } + + return iRet; +} + + /* --------------- END functions for handling canned syntaxes --------------- */ /* destructor for cslCmdHdlr @@ -426,6 +478,9 @@ static rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine) case eCmdHdlrGetChar: pHdlr = doGetChar; break; + case eCmdHdlrGetWord: + pHdlr = doGetWord; + break; default: iRet = RS_RET_NOT_IMPLEMENTED; goto finalize_it; diff --git a/cfsysline.h b/cfsysline.h index 2bca31e1..607ac40e 100644 --- a/cfsysline.h +++ b/cfsysline.h @@ -34,7 +34,8 @@ typedef enum cslCmdHdlrType { eCmdHdlrBinary, eCmdHdlrFileCreateMode, eCmdHdlrInt, - eCmdHdlrGetChar + eCmdHdlrGetChar, + eCmdHdlrGetWord } ecslCmdHdrlType; /* this is a single entry for a parse routine. It describes exactly diff --git a/syslogd.c b/syslogd.c index d65e6662..b0a54051 100644 --- a/syslogd.c +++ b/syslogd.c @@ -363,7 +363,7 @@ syslogCODE rs_facilitynames[] = static uchar *ConfFile = (uchar*) _PATH_LOGCONF; /* read-only after startup */ static char *PidFile = _PATH_LOGPID; /* read-only after startup */ -static char *ModDir = _PATH_MODDIR; /* read-only after startup */ +static uchar *pModDir = NULL; /* read-only after startup */ char ctty[] = _PATH_CONSOLE; /* this is read-only */ static pid_t myPid; /* our pid for use in self-generated messages, e.g. on startup */ @@ -647,6 +647,10 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a bEscapeCCOnRcv = 1; /* default is to escape control characters */ bReduceRepeatMsgs = (logEveryMsg == 1) ? 0 : 1; bDropMalPTRMsgs = 0; + if(pModDir != NULL) { + free(pModDir); + pModDir = NULL; + } #ifdef USE_PTHREADS iMainMsgQueueSize = 10000; #endif @@ -3585,6 +3589,10 @@ static void die(int sig) */ modUnloadAndDestructAll(); + /* clean up auxiliary data */ + if(pModDir != NULL) + free(pModDir); + dbgprintf("Clean shutdown completed, bye.\n"); exit(0); /* "good" exit, this is the terminator function for rsyslog [die()] */ } @@ -3812,7 +3820,7 @@ static rsRetVal doModLoad(uchar **pp, __attribute__((unused)) void* pVal) dbgprintf("Requested to load module '%s'\n", szName); - strncpy((char *) szPath, ModDir, sizeof(szPath)); + strncpy((char *) szPath, (pModDir == NULL) ? _PATH_MODDIR : (char*) pModDir, sizeof(szPath)); strncat((char *) szPath, (char *) pModName, sizeof(szPath) - strlen((char*) szPath) - 1); if(!(pModHdlr = dlopen((char *) szPath, RTLD_NOW))) { snprintf((char *) errMsg, sizeof(errMsg), "could not load module '%s', dlopen: %s\n", szPath, dlerror()); @@ -4293,7 +4301,6 @@ static void init(void) } #endif - /* re-setting values to defaults (where applicable) */ /* TODO: once we have loadable modules, we must re-visit this code. The reason is * that config variables are not re-set, because the module is not yet loaded. On @@ -5909,6 +5916,7 @@ static rsRetVal loadBuildInModules(void) CHKiRet(regCfSysLineHdlr((uchar *)"debugprintmodulelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintModuleList)); CHKiRet(regCfSysLineHdlr((uchar *)"debugprintcfsyslinehandlerlist", 0, eCmdHdlrBinary, NULL, &bDebugPrintCfSysLineHandlerList)); + CHKiRet(regCfSysLineHdlr((uchar *)"moddir", 0, eCmdHdlrGetWord, NULL, &pModDir)); CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL)); finalize_it: -- cgit