diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-06-27 12:52:45 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-06-27 12:52:45 +0200 |
commit | 3f6c73a8b7ff2c6d9c931876d823f2b4ef6bbea2 (patch) | |
tree | a147c4dbda59de0675b0c2a5e80a2b6f97569691 /runtime | |
parent | d4518082362afebef9400bcbf46e38228de83bf1 (diff) | |
download | rsyslog-3f6c73a8b7ff2c6d9c931876d823f2b4ef6bbea2.tar.gz rsyslog-3f6c73a8b7ff2c6d9c931876d823f2b4ef6bbea2.tar.bz2 rsyslog-3f6c73a8b7ff2c6d9c931876d823f2b4ef6bbea2.zip |
added (internal) error codes to error messages
Also added redirector to web description of error codes
closes bug http://bugzilla.adiscon.com/show_bug.cgi?id=20
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/cfsysline.c | 20 | ||||
-rw-r--r-- | runtime/conf.c | 37 | ||||
-rw-r--r-- | runtime/errmsg.c | 34 | ||||
-rw-r--r-- | runtime/errmsg.h | 2 | ||||
-rw-r--r-- | runtime/modules.c | 10 | ||||
-rw-r--r-- | runtime/net.c | 57 | ||||
-rw-r--r-- | runtime/nsd_gtls.c | 37 | ||||
-rw-r--r-- | runtime/nsd_ptcp.c | 8 | ||||
-rw-r--r-- | runtime/obj.c | 2 | ||||
-rw-r--r-- | runtime/rsyslog.c | 10 | ||||
-rw-r--r-- | runtime/rsyslog.h | 12 |
11 files changed, 123 insertions, 106 deletions
diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c index ef21fb4b..18643ba5 100644 --- a/runtime/cfsysline.c +++ b/runtime/cfsysline.c @@ -69,7 +69,7 @@ static rsRetVal doGetChar(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void * /* if we are not at a '\0', we have our new char - no validity checks here... */ if(**pp == '\0') { - errmsg.LogError(NO_ERRCODE, "No character available"); + errmsg.LogError(0, RS_RET_NOT_FOUND, "No character available"); iRet = RS_RET_NOT_FOUND; } else { if(pSetHdlr == NULL) { @@ -133,7 +133,7 @@ static rsRetVal parseIntVal(uchar **pp, int64 *pVal) if(!isdigit((int) *p)) { errno = 0; - errmsg.LogError(NO_ERRCODE, "invalid number"); + errmsg.LogError(0, RS_RET_INVALID_INT, "invalid number"); ABORT_FINALIZE(RS_RET_INVALID_INT); } @@ -272,7 +272,7 @@ static rsRetVal doFileCreateMode(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar), "value must be octal (e.g 0644)."); errno = 0; - errmsg.LogError(NO_ERRCODE, "%s", errMsg); + errmsg.LogError(0, RS_RET_INVALID_VALUE, "%s", errMsg); ABORT_FINALIZE(RS_RET_INVALID_VALUE); } @@ -317,7 +317,7 @@ static int doParseOnOffOption(uchar **pp) skipWhiteSpace(pp); /* skip over any whitespace */ if(getSubString(pp, (char*) szOpt, sizeof(szOpt) / sizeof(uchar), ' ') != 0) { - errmsg.LogError(NO_ERRCODE, "Invalid $-configline - could not extract on/off option"); + errmsg.LogError(0, NO_ERRCODE, "Invalid $-configline - could not extract on/off option"); return -1; } @@ -326,7 +326,7 @@ static int doParseOnOffOption(uchar **pp) } else if(!strcmp((char*)szOpt, "off")) { return 0; } else { - errmsg.LogError(NO_ERRCODE, "Option value must be on or off, but is '%s'", (char*)pOptStart); + errmsg.LogError(0, NO_ERRCODE, "Option value must be on or off, but is '%s'", (char*)pOptStart); return -1; } } @@ -347,14 +347,14 @@ static rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p assert(*pp != NULL); if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) { - errmsg.LogError(NO_ERRCODE, "could not extract group name"); + errmsg.LogError(0, RS_RET_NOT_FOUND, "could not extract group name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } getgrnam_r((char*)szName, &gBuf, stringBuf, sizeof(stringBuf), &pgBuf); if(pgBuf == NULL) { - errmsg.LogError(NO_ERRCODE, "ID for group '%s' could not be found or error", (char*)szName); + errmsg.LogError(0, RS_RET_NOT_FOUND, "ID for group '%s' could not be found or error", (char*)szName); iRet = RS_RET_NOT_FOUND; } else { if(pSetHdlr == NULL) { @@ -389,14 +389,14 @@ static rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p assert(*pp != NULL); if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) { - errmsg.LogError(NO_ERRCODE, "could not extract user name"); + errmsg.LogError(0, RS_RET_NOT_FOUND, "could not extract user name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } getpwnam_r((char*)szName, &pwBuf, stringBuf, sizeof(stringBuf), &ppwBuf); if(ppwBuf == NULL) { - errmsg.LogError(NO_ERRCODE, "ID for user '%s' could not be found or error", (char*)szName); + errmsg.LogError(0, RS_RET_NOT_FOUND, "ID for user '%s' could not be found or error", (char*)szName); iRet = RS_RET_NOT_FOUND; } else { if(pSetHdlr == NULL) { @@ -911,7 +911,7 @@ rsRetVal processCfSysLineCommand(uchar *pCmdName, uchar **p) iRet = llFind(&llCmdList, (void *) pCmdName, (void*) &pCmd); if(iRet == RS_RET_NOT_FOUND) { - errmsg.LogError(NO_ERRCODE, "invalid or yet-unknown config file command - have you forgotten to load a module?"); + errmsg.LogError(0, RS_RET_NOT_FOUND, "invalid or yet-unknown config file command - have you forgotten to load a module?"); } if(iRet != RS_RET_OK) diff --git a/runtime/conf.c b/runtime/conf.c index b24083d3..a0a2b080 100644 --- a/runtime/conf.c +++ b/runtime/conf.c @@ -120,7 +120,7 @@ static rsRetVal doIncludeDirectory(uchar *pDirName) ASSERT(pDirName != NULL); if((pDir = opendir((char*) pDirName)) == NULL) { - errmsg.LogError(NO_ERRCODE, "error opening include directory"); + errmsg.LogError(errno, RS_RET_FOPEN_FAILURE, "error opening include directory"); ABORT_FINALIZE(RS_RET_FOPEN_FAILURE); } @@ -195,7 +195,7 @@ doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal) ASSERT(*pp != NULL); if(getSubString(pp, (char*) pattern, sizeof(pattern) / sizeof(char), ' ') != 0) { - errmsg.LogError(NO_ERRCODE, "could not extract group name"); + errmsg.LogError(0, RS_RET_NOT_FOUND, "could not extract group name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } @@ -242,7 +242,7 @@ doModLoad(uchar **pp, __attribute__((unused)) void* pVal) skipWhiteSpace(pp); /* skip over any whitespace */ if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) { - errmsg.LogError(NO_ERRCODE, "could not extract module name"); + errmsg.LogError(0, RS_RET_NOT_FOUND, "could not extract module name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } skipWhiteSpace(pp); /* skip over any whitespace */ @@ -289,7 +289,7 @@ doNameLine(uchar **pp, void* pVal) eDir = (enum eDirective) pVal; /* this time, it actually is NOT a pointer! */ if(getSubString(&p, szName, sizeof(szName) / sizeof(char), ',') != 0) { - errmsg.LogError(NO_ERRCODE, "Invalid config line: could not extract name - line ignored"); + errmsg.LogError(0, RS_RET_NOT_FOUND, "Invalid config line: could not extract name - line ignored"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } if(*p == ',') @@ -338,12 +338,11 @@ cfsysline(uchar *p) { DEFiRet; uchar szCmd[64]; - uchar errMsg[128]; /* for dynamic error messages */ ASSERT(p != NULL); errno = 0; if(getSubString(&p, (char*) szCmd, sizeof(szCmd) / sizeof(uchar), ' ') != 0) { - errmsg.LogError(NO_ERRCODE, "Invalid $-configline - could not extract command - line ignored\n"); + errmsg.LogError(0, RS_RET_NOT_FOUND, "Invalid $-configline - could not extract command - line ignored\n"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } @@ -361,10 +360,8 @@ cfsysline(uchar *p) skipWhiteSpace(&p); if(*p && *p != '#') { /* we have a non-whitespace, so let's complain */ - snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar), + errmsg.LogError(0, NO_ERRCODE, "error: extra characters in config line ignored: '%s'", p); - errno = 0; - errmsg.LogError(NO_ERRCODE, "%s", errMsg); } finalize_it: @@ -448,7 +445,7 @@ processConfFile(uchar *pConfFile) dbgprintf("config line NOT successfully processed\n"); snprintf((char*)szErrLoc, sizeof(szErrLoc) / sizeof(uchar), "%s, line %d", pConfFile, iLnNbr); - errmsg.LogError(NO_ERRCODE, "the last error occured in %s", (char*)szErrLoc); + errmsg.LogError(0, NO_ERRCODE, "the last error occured in %s", (char*)szErrLoc); } } @@ -497,7 +494,7 @@ rsRetVal cflineParseTemplateName(uchar** pp, omodStringRequest_t *pOMSR, int iEn if(*p == ';') ++p; /* eat it */ else if(*p != '\0' && *p != '#') { - errmsg.LogError(NO_ERRCODE, "invalid character in selector line - ';template' expected"); + errmsg.LogError(0, NO_ERRCODE, "invalid character in selector line - ';template' expected"); iRet = RS_RET_ERR; goto finalize_it; } @@ -639,7 +636,7 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register selector_t *f if (pri < 0) { snprintf((char*) xbuf, sizeof(xbuf), "unknown priority name \"%s\"", buf); - errmsg.LogError(NO_ERRCODE, "%s", xbuf); + errmsg.LogError(0, RS_RET_ERR, "%s", xbuf); return RS_RET_ERR; } @@ -686,7 +683,7 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register selector_t *f if (i < 0) { snprintf((char*) xbuf, sizeof(xbuf), "unknown facility name \"%s\"", buf); - errmsg.LogError(NO_ERRCODE, "%s", xbuf); + errmsg.LogError(0, RS_RET_ERR, "%s", xbuf); return RS_RET_ERR; } @@ -792,7 +789,7 @@ dbgprintf("calling expression parser, pp %p ('%s')\n", *pline, *pline); finalize_it: if(iRet == RS_RET_SYNTAX_ERROR) { - errmsg.LogError(NO_ERRCODE, "syntax error in expression"); + errmsg.LogError(0, RS_RET_SYNTAX_ERROR, "syntax error in expression"); } RETiRet; @@ -822,14 +819,14 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) /* create parser object starting with line string without leading colon */ if((iRet = rsParsConstructFromSz(&pPars, (*pline)+1)) != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "Error %d constructing parser object - ignoring selector", iRet); + errmsg.LogError(0, iRet, "Error %d constructing parser object - ignoring selector", iRet); return(iRet); } /* read property */ iRet = parsDelimCStr(pPars, &f->f_filterData.prop.pCSPropName, ',', 1, 1, 1); if(iRet != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "error %d parsing filter property - ignoring selector", iRet); + errmsg.LogError(0, iRet, "error %d parsing filter property - ignoring selector", iRet); rsParsDestruct(pPars); return(iRet); } @@ -837,7 +834,7 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) /* read operation */ iRet = parsDelimCStr(pPars, &pCSCompOp, ',', 1, 1, 1); if(iRet != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "error %d compare operation property - ignoring selector", iRet); + errmsg.LogError(0, iRet, "error %d compare operation property - ignoring selector", iRet); rsParsDestruct(pPars); return(iRet); } @@ -869,7 +866,7 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (unsigned char*) "regex", 5)) { f->f_filterData.prop.operation = FIOP_REGEX; } else { - errmsg.LogError(NO_ERRCODE, "error: invalid compare operation '%s' - ignoring selector", + errmsg.LogError(0, NO_ERRCODE, "error: invalid compare operation '%s' - ignoring selector", (char*) rsCStrGetSzStrNoNULL(pCSCompOp)); } rsCStrDestruct(&pCSCompOp); /* no longer needed */ @@ -877,14 +874,14 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) /* read compare value */ iRet = parsQuotedCStr(pPars, &f->f_filterData.prop.pCSCompValue); if(iRet != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "error %d compare value property - ignoring selector", iRet); + errmsg.LogError(0, iRet, "error %d compare value property - ignoring selector", iRet); rsParsDestruct(pPars); return(iRet); } /* skip to action part */ if((iRet = parsSkipWhitespace(pPars)) != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "error %d skipping to action part - ignoring selector", iRet); + errmsg.LogError(0, iRet, "error %d skipping to action part - ignoring selector", iRet); rsParsDestruct(pPars); return(iRet); } diff --git a/runtime/errmsg.c b/runtime/errmsg.c index 1744c902..dc09fc03 100644 --- a/runtime/errmsg.c +++ b/runtime/errmsg.c @@ -46,11 +46,18 @@ DEFobjStaticHelpers /* ------------------------------ methods ------------------------------ */ -/* TODO: restructure this code some time. Especially look if we need - * to check errno and, if so, how to do that in a clean way. +/* We now receive three parameters: one is the internal error code + * which will also become the error message number, the second is + * errno - if it is non-zero, the corresponding error message is included + * in the text and finally the message text itself. Note that it is not + * 100% clean to use the internal errcode, as it may be reached from + * multiple actual error causes. However, it is much better than having + * no error code at all (and in most cases, a single internal error code + * maps to a specific error event). + * rgerhards, 2008-06-27 */ -static void __attribute__((format(printf, 2, 3))) -LogError(int __attribute__((unused)) iErrCode, char *fmt, ... ) +static void __attribute__((format(printf, 3, 4))) +LogError(int iErrno, int iErrCode, char *fmt, ... ) { va_list ap; char buf[1024]; @@ -74,16 +81,25 @@ LogError(int __attribute__((unused)) iErrCode, char *fmt, ... ) dbgprintf("Called LogError, msg: %s\n", buf); - if (errno == 0) { - snprintf(msg, sizeof(msg), "%s", buf); + if(iErrno != 0) { + rs_strerror_r(iErrno, errStr, sizeof(errStr)); + if(iErrCode == NO_ERRCODE) { + snprintf(msg, sizeof(msg), "%s: %s", buf, errStr); + } else { + snprintf(msg, sizeof(msg), "%s: %s [try http://www.rsyslog.com/e/%d ]", buf, errStr, iErrCode * -1); + } } else { - rs_strerror_r(errno, errStr, sizeof(errStr)); - snprintf(msg, sizeof(msg), "%s: %s", buf, errStr); + if(iErrCode == NO_ERRCODE) { + snprintf(msg, sizeof(msg), "%s", buf); + } else { + snprintf(msg, sizeof(msg), "%s [try http://www.rsyslog.com/e/%d ]", buf, iErrCode * -1); + } } msg[sizeof(msg)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ errno = 0; - glblErrLogger((uchar*)msg); +dbgprintf("LogError logging error '%s', code %d\n", msg, iErrCode); + glblErrLogger(iErrCode, (uchar*)msg); ENDfunc } diff --git a/runtime/errmsg.h b/runtime/errmsg.h index bde6bcff..799954fb 100644 --- a/runtime/errmsg.h +++ b/runtime/errmsg.h @@ -35,7 +35,7 @@ typedef struct errmsg_s { /* interfaces */ BEGINinterface(errmsg) /* name must also be changed in ENDinterface macro! */ - void __attribute__((format(printf, 2, 3))) (*LogError)(int iErrCode, char *pszErrFmt, ... ); + void __attribute__((format(printf, 3, 4))) (*LogError)(int iErrno, int iErrCode, char *pszErrFmt, ... ); ENDinterface(errmsg) #define errmsgCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */ diff --git a/runtime/modules.c b/runtime/modules.c index 502e6525..ceb4768c 100644 --- a/runtime/modules.c +++ b/runtime/modules.c @@ -604,7 +604,7 @@ Load(uchar *pModName) szPath[iPathLen++] = '/'; szPath[iPathLen] = '\0'; } else { - errmsg.LogError(NO_ERRCODE, "could not load module '%s', path too long\n", pModName); + errmsg.LogError(0, RS_RET_MODULE_LOAD_ERR_PATHLEN, "could not load module '%s', path too long\n", pModName); ABORT_FINALIZE(RS_RET_MODULE_LOAD_ERR_PATHLEN); } } @@ -625,23 +625,23 @@ Load(uchar *pModName) } if(iPathLen + strlen((char*) pModName) >= sizeof(szPath)) { - errmsg.LogError(NO_ERRCODE, "could not load module '%s', path too long\n", pModName); + errmsg.LogError(0, RS_RET_MODULE_LOAD_ERR_PATHLEN, "could not load module '%s', path too long\n", pModName); ABORT_FINALIZE(RS_RET_MODULE_LOAD_ERR_PATHLEN); } /* complete load path constructed, so ... GO! */ dbgprintf("loading module '%s'\n", szPath); if(!(pModHdlr = dlopen((char *) szPath, RTLD_NOW))) { - errmsg.LogError(NO_ERRCODE, "could not load module '%s', dlopen: %s\n", szPath, dlerror()); + errmsg.LogError(0, RS_RET_MODULE_LOAD_ERR_DLOPEN, "could not load module '%s', dlopen: %s\n", szPath, dlerror()); ABORT_FINALIZE(RS_RET_MODULE_LOAD_ERR_DLOPEN); } if(!(pModInit = dlsym(pModHdlr, "modInit"))) { - errmsg.LogError(NO_ERRCODE, "could not load module '%s', dlsym: %s\n", szPath, dlerror()); + errmsg.LogError(0, RS_RET_MODULE_LOAD_ERR_NO_INIT, "could not load module '%s', dlsym: %s\n", szPath, dlerror()); dlclose(pModHdlr); ABORT_FINALIZE(RS_RET_MODULE_LOAD_ERR_NO_INIT); } if((iRet = doModInit(pModInit, (uchar*) pModName, pModHdlr)) != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "could not load module '%s', rsyslog error %d\n", szPath, iRet); + errmsg.LogError(0, RS_RET_MODULE_LOAD_ERR_INIT_FAILED, "could not load module '%s', rsyslog error %d\n", szPath, iRet); dlclose(pModHdlr); ABORT_FINALIZE(RS_RET_MODULE_LOAD_ERR_INIT_FAILED); } diff --git a/runtime/net.c b/runtime/net.c index c3252269..f5b8f46a 100644 --- a/runtime/net.c +++ b/runtime/net.c @@ -305,7 +305,7 @@ PermittedPeerWildcardCompile(permittedPeers_t *pPeer) finalize_it: if(iRet != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "error compiling wildcard expression '%s'", + errmsg.LogError(0, iRet, "error compiling wildcard expression '%s'", pPeer->pszID); } RETiRet; @@ -531,14 +531,14 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS /* we handle this seperatly just to provide a better * error message. */ - errmsg.LogError(NO_ERRCODE, "You can not specify 0 bits of the netmask, this would " + errmsg.LogError(0, NO_ERRCODE, "You can not specify 0 bits of the netmask, this would " "match ALL systems. If you really intend to do that, " "remove all $AllowedSender directives."); switch (iAllow->addr.NetAddr->sa_family) { case AF_INET: if((iSignificantBits < 1) || (iSignificantBits > 32)) { - errmsg.LogError(NO_ERRCODE, "Invalid number of bits (%d) in IPv4 address - adjusted to 32", + errmsg.LogError(0, NO_ERRCODE, "Invalid number of bits (%d) in IPv4 address - adjusted to 32", (int)iSignificantBits); iSignificantBits = 32; } @@ -547,7 +547,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS break; case AF_INET6: if((iSignificantBits < 1) || (iSignificantBits > 128)) { - errmsg.LogError(NO_ERRCODE, "Invalid number of bits (%d) in IPv6 address - adjusted to 128", + errmsg.LogError(0, NO_ERRCODE, "Invalid number of bits (%d) in IPv6 address - adjusted to 128", iSignificantBits); iSignificantBits = 128; } @@ -562,7 +562,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS * worst thing that happens is that one host will not be allowed to * log. */ - errmsg.LogError(NO_ERRCODE, "Internal error caused AllowedSender to be ignored, AF = %d", + errmsg.LogError(0, NO_ERRCODE, "Internal error caused AllowedSender to be ignored, AF = %d", iAllow->addr.NetAddr->sa_family); ABORT_FINALIZE(RS_RET_ERR); } @@ -571,7 +571,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS } else { /* we need to process a hostname ACL */ if(glbl.GetDisableDNS()) { - errmsg.LogError(NO_ERRCODE, "Ignoring hostname based ACLs because DNS is disabled."); + errmsg.LogError(0, NO_ERRCODE, "Ignoring hostname based ACLs because DNS is disabled."); ABORT_FINALIZE(RS_RET_OK); } @@ -592,14 +592,14 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS # endif if (getaddrinfo (iAllow->addr.HostWildcard, NULL, &hints, &res) != 0) { - errmsg.LogError(NO_ERRCODE, "DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard); + errmsg.LogError(0, NO_ERRCODE, "DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard); if (ACLAddHostnameOnFail) { - errmsg.LogError(NO_ERRCODE, "Adding hostname \"%s\" to ACL as a wildcard entry.", iAllow->addr.HostWildcard); + errmsg.LogError(0, NO_ERRCODE, "Adding hostname \"%s\" to ACL as a wildcard entry.", iAllow->addr.HostWildcard); iRet = AddAllowedSenderEntry(ppRoot, ppLast, iAllow, iSignificantBits); FINALIZE; } else { - errmsg.LogError(NO_ERRCODE, "Hostname \"%s\" WON\'T be added to ACL.", iAllow->addr.HostWildcard); + errmsg.LogError(0, NO_ERRCODE, "Hostname \"%s\" WON\'T be added to ACL.", iAllow->addr.HostWildcard); ABORT_FINALIZE(RS_RET_NOENTRY); } } @@ -756,7 +756,7 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine) ppLast = &pLastAllowedSenders_GSS; #endif } else { - errmsg.LogError(NO_ERRCODE, "Invalid protocol '%s' in allowed sender " + errmsg.LogError(0, RS_RET_ERR, "Invalid protocol '%s' in allowed sender " "list, line ignored", pName); return RS_RET_ERR; } @@ -767,7 +767,7 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine) */ /* create parser object starting with line string without leading colon */ if((iRet = rsParsConstructFromSz(&pPars, (uchar*) *ppRestOfConfLine) != RS_RET_OK)) { - errmsg.LogError(NO_ERRCODE, "Error %d constructing parser object - ignoring allowed sender list", iRet); + errmsg.LogError(0, iRet, "Error %d constructing parser object - ignoring allowed sender list", iRet); return(iRet); } @@ -776,18 +776,17 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine) break; /* a comment-sign stops processing of line */ /* now parse a single IP address */ if((iRet = parsAddrWithBits(pPars, &uIP, &iBits)) != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "Error %d parsing address in allowed sender" + errmsg.LogError(0, iRet, "Error %d parsing address in allowed sender" "list - ignoring.", iRet); rsParsDestruct(pPars); return(iRet); } - if((iRet = AddAllowedSender(ppRoot, ppLast, uIP, iBits)) - != RS_RET_OK) { - if (iRet == RS_RET_NOENTRY) { - errmsg.LogError(NO_ERRCODE, "Error %d adding allowed sender entry " + if((iRet = AddAllowedSender(ppRoot, ppLast, uIP, iBits)) != RS_RET_OK) { + if(iRet == RS_RET_NOENTRY) { + errmsg.LogError(0, iRet, "Error %d adding allowed sender entry " "- ignoring.", iRet); } else { - errmsg.LogError(NO_ERRCODE, "Error %d adding allowed sender entry " + errmsg.LogError(0, iRet, "Error %d adding allowed sender entry " "- terminating, nothing more will be added.", iRet); rsParsDestruct(pPars); return(iRet); @@ -1026,7 +1025,7 @@ gethname(struct sockaddr_storage *f, uchar *pszHostFQDN, uchar *ip) "Malicious PTR record, message dropped " "IP = \"%s\" HOST = \"%s\"", ip, pszHostFQDN); - errmsg.LogError(NO_ERRCODE, "%s", szErrMsg); + errmsg.LogError(0, RS_RET_MALICIOUS_ENTITY, "%s", szErrMsg); pthread_sigmask(SIG_SETMASK, &omask, NULL); ABORT_FINALIZE(RS_RET_MALICIOUS_ENTITY); } @@ -1041,7 +1040,7 @@ gethname(struct sockaddr_storage *f, uchar *pszHostFQDN, uchar *ip) "Malicious PTR record (message accepted, but used IP " "instead of PTR name: IP = \"%s\" HOST = \"%s\"", ip, pszHostFQDN); - errmsg.LogError(NO_ERRCODE, "%s", szErrMsg); + errmsg.LogError(0, NO_ERRCODE, "%s", szErrMsg); error = 1; /* that will trigger using IP address below. */ } @@ -1272,8 +1271,8 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) hints.ai_socktype = SOCK_DGRAM; error = getaddrinfo((char*) hostname, (char*) pszPort, &hints, &res); if(error) { - errmsg.LogError(NO_ERRCODE, "%s", gai_strerror(error)); - errmsg.LogError(NO_ERRCODE, "UDP message reception disabled due to error logged in last message.\n"); + errmsg.LogError(0, NO_ERRCODE, "%s", gai_strerror(error)); + errmsg.LogError(0, NO_ERRCODE, "UDP message reception disabled due to error logged in last message.\n"); return NULL; } @@ -1282,7 +1281,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) /* EMPTY */; socks = malloc((maxs+1) * sizeof(int)); if (socks == NULL) { - errmsg.LogError(NO_ERRCODE, "couldn't allocate memory for UDP sockets, suspending UDP message reception"); + errmsg.LogError(0, NO_ERRCODE, "couldn't allocate memory for UDP sockets, suspending UDP message reception"); freeaddrinfo(res); return NULL; } @@ -1293,7 +1292,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol); if (*s < 0) { if(!(r->ai_family == PF_INET6 && errno == EAFNOSUPPORT)) - errmsg.LogError(NO_ERRCODE, "create_udp_socket(), socket"); + errmsg.LogError(errno, NO_ERRCODE, "create_udp_socket(), socket"); /* it is debateble if PF_INET with EAFNOSUPPORT should * also be ignored... */ @@ -1305,7 +1304,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) int ion = 1; if (setsockopt(*s, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ion, sizeof (ion)) < 0) { - errmsg.LogError(NO_ERRCODE, "setsockopt"); + errmsg.LogError(errno, NO_ERRCODE, "setsockopt"); close(*s); *s = -1; continue; @@ -1322,7 +1321,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) */ if (setsockopt(*s, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0 ) { - errmsg.LogError(NO_ERRCODE, "setsockopt(REUSEADDR)"); + errmsg.LogError(errno, NO_ERRCODE, "setsockopt(REUSEADDR)"); close(*s); *s = -1; continue; @@ -1335,7 +1334,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) if (should_use_so_bsdcompat()) { if (setsockopt(*s, SOL_SOCKET, SO_BSDCOMPAT, (char *) &on, sizeof(on)) < 0) { - errmsg.LogError(NO_ERRCODE, "setsockopt(BSDCOMPAT)"); + errmsg.LogError(errno, NO_ERRCODE, "setsockopt(BSDCOMPAT)"); close(*s); *s = -1; continue; @@ -1357,7 +1356,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) sockflags = fcntl(*s, F_SETFL, sockflags); } if (sockflags == -1) { - errmsg.LogError(NO_ERRCODE, "fcntl(O_NONBLOCK)"); + errmsg.LogError(errno, NO_ERRCODE, "fcntl(O_NONBLOCK)"); close(*s); *s = -1; continue; @@ -1376,7 +1375,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) && (errno != EADDRINUSE) # endif ) { - errmsg.LogError(NO_ERRCODE, "bind"); + errmsg.LogError(errno, NO_ERRCODE, "bind"); close(*s); *s = -1; continue; @@ -1395,7 +1394,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) "- this may or may not be an error indication.\n", *socks, maxs); if(*socks == 0) { - errmsg.LogError(NO_ERRCODE, "No UDP listen socket could successfully be initialized, " + errmsg.LogError(0, NO_ERRCODE, "No UDP listen socket could successfully be initialized, " "message reception via UDP disabled.\n"); /* we do NOT need to free any sockets, because there were none... */ free(socks); diff --git a/runtime/nsd_gtls.c b/runtime/nsd_gtls.c index 103461e7..a80a1836 100644 --- a/runtime/nsd_gtls.c +++ b/runtime/nsd_gtls.c @@ -111,26 +111,26 @@ readFile(uchar *pszFile, gnutls_datum_t *pBuf) pBuf->data = NULL; if((fd = open((char*)pszFile, 0)) == -1) { - errmsg.LogError(NO_ERRCODE, "can not read file '%s'", pszFile); + errmsg.LogError(0, RS_RET_FILE_NOT_FOUND, "can not read file '%s'", pszFile); ABORT_FINALIZE(RS_RET_FILE_NOT_FOUND); } if(fstat(fd, &stat_st) == -1) { - errmsg.LogError(NO_ERRCODE, "can not stat file '%s'", pszFile); + errmsg.LogError(0, RS_RET_FILE_NO_STAT, "can not stat file '%s'", pszFile); ABORT_FINALIZE(RS_RET_FILE_NO_STAT); } /* 1MB limit */ if(stat_st.st_size > 1024 * 1024) { - errmsg.LogError(NO_ERRCODE, "file '%s' too large, max 1MB", pszFile); + errmsg.LogError(0, RS_RET_FILE_TOO_LARGE, "file '%s' too large, max 1MB", pszFile); ABORT_FINALIZE(RS_RET_FILE_TOO_LARGE); } CHKmalloc(pBuf->data = malloc(stat_st.st_size)); pBuf->size = stat_st.st_size; if(read(fd, pBuf->data, stat_st.st_size) != stat_st.st_size) { - errmsg.LogError(NO_ERRCODE, "error or incomplete read of file '%s'", pszFile); + errmsg.LogError(0, RS_RET_IO_ERROR, "error or incomplete read of file '%s'", pszFile); ABORT_FINALIZE(RS_RET_IO_ERROR); } @@ -530,7 +530,7 @@ finalize_it: if(iRet != RS_RET_OK) { pGnuErr = gtlsStrerror(gnuRet); errno = 0; - errmsg.LogError(NO_ERRCODE, "error adding our certificate. GnuTLS error %d, message: '%s', " + errmsg.LogError(0, iRet, "error adding our certificate. GnuTLS error %d, message: '%s', " "key: '%s', cert: '%s'\n", gnuRet, pGnuErr, keyFile, certFile); free(pGnuErr); } @@ -762,7 +762,7 @@ gtlsChkPeerFingerprint(nsd_gtls_t *pThis, gnutls_x509_crt *pCert) dbgprintf("invalid peer fingerprint, not permitted to talk to it\n"); if(pThis->bReportAuthErr == 1) { errno = 0; - errmsg.LogError(NO_ERRCODE, "error: peer fingerprint '%s' unknown - we are " + errmsg.LogError(0, RS_RET_INVALID_FINGERPRINT, "error: peer fingerprint '%s' unknown - we are " "not permitted to talk to it", rsCStrGetSzStr(pstrFingerprint)); pThis->bReportAuthErr = 0; } @@ -870,7 +870,7 @@ gtlsChkPeerName(nsd_gtls_t *pThis, gnutls_x509_crt *pCert) if(pThis->bReportAuthErr == 1) { CHKiRet(rsCStrFinish(pStr)); errno = 0; - errmsg.LogError(NO_ERRCODE, "error: peer name not authorized - " + errmsg.LogError(0, RS_RET_INVALID_FINGERPRINT, "error: peer name not authorized - " "not permitted to talk to it. Names: %s", rsCStrGetSzStr(pStr)); pThis->bReportAuthErr = 0; @@ -913,7 +913,7 @@ gtlsChkPeerID(nsd_gtls_t *pThis) if(list_size < 1) { if(pThis->bReportAuthErr == 1) { errno = 0; - errmsg.LogError(NO_ERRCODE, "error: peer did not provide a certificate, " + errmsg.LogError(0, RS_RET_TLS_NO_CERT, "error: peer did not provide a certificate, " "not permitted to talk to it"); pThis->bReportAuthErr = 0; } @@ -970,7 +970,7 @@ gtlsChkPeerCertValidity(nsd_gtls_t *pThis) cert_list = gnutls_certificate_get_peers(pThis->sess, &cert_list_size); if(cert_list_size < 1) { errno = 0; - errmsg.LogError(NO_ERRCODE, "peer did not provide a certificate, not permitted to talk to it"); + errmsg.LogError(0, RS_RET_TLS_NO_CERT, "peer did not provide a certificate, not permitted to talk to it"); ABORT_FINALIZE(RS_RET_TLS_NO_CERT); } @@ -991,11 +991,10 @@ gtlsChkPeerCertValidity(nsd_gtls_t *pThis) dbgprintf("GnuTLS returned no specific reason for GNUTLS_CERT_INVALID, certificate " "status is %d\n", stateCert); } - errno = 0; /* get rid of errno based message expansion on LogError */ - errmsg.LogError(NO_ERRCODE, "not permitted to talk to peer, certificate invalid: %s", + errmsg.LogError(0, NO_ERRCODE, "not permitted to talk to peer, certificate invalid: %s", pszErrCause); gtlsGetCertInfo(pThis, &pStr); - errmsg.LogError(NO_ERRCODE, "invalid cert info: %s", rsCStrGetSzStr(pStr)); + errmsg.LogError(0, NO_ERRCODE, "invalid cert info: %s", rsCStrGetSzStr(pStr)); rsCStrDestruct(&pStr); ABORT_FINALIZE(RS_RET_CERT_INVALID); } @@ -1015,9 +1014,9 @@ gtlsChkPeerCertValidity(nsd_gtls_t *pThis) if(ttCert == -1) ABORT_FINALIZE(RS_RET_TLS_CERT_ERR); else if(ttCert > ttNow) { - errmsg.LogError(NO_ERRCODE, "not permitted to talk to peer: certificate %d not yet active", i); + errmsg.LogError(0, RS_RET_CERT_NOT_YET_ACTIVE, "not permitted to talk to peer: certificate %d not yet active", i); gtlsGetCertInfo(pThis, &pStr); - errmsg.LogError(NO_ERRCODE, "invalid cert info: %s", rsCStrGetSzStr(pStr)); + errmsg.LogError(0, RS_RET_CERT_NOT_YET_ACTIVE, "invalid cert info: %s", rsCStrGetSzStr(pStr)); rsCStrDestruct(&pStr); ABORT_FINALIZE(RS_RET_CERT_NOT_YET_ACTIVE); } @@ -1026,9 +1025,9 @@ gtlsChkPeerCertValidity(nsd_gtls_t *pThis) if(ttCert == -1) ABORT_FINALIZE(RS_RET_TLS_CERT_ERR); else if(ttCert < ttNow) { - errmsg.LogError(NO_ERRCODE, "not permitted to talk to peer: certificate %d expired", i); + errmsg.LogError(0, RS_RET_CERT_EXPIRED, "not permitted to talk to peer: certificate %d expired", i); gtlsGetCertInfo(pThis, &pStr); - errmsg.LogError(NO_ERRCODE, "invalid cert info: %s", rsCStrGetSzStr(pStr)); + errmsg.LogError(0, RS_RET_CERT_EXPIRED, "invalid cert info: %s", rsCStrGetSzStr(pStr)); rsCStrDestruct(&pStr); ABORT_FINALIZE(RS_RET_CERT_EXPIRED); } @@ -1174,7 +1173,7 @@ SetMode(nsd_t *pNsd, int mode) ISOBJ_TYPE_assert((pThis), nsd_gtls); if(mode != 0 && mode != 1) { - errmsg.LogError(NO_ERRCODE, "error: driver mode %d not supported by " + errmsg.LogError(0, RS_RET_INVALID_DRVR_MODE, "error: driver mode %d not supported by " "gtls netstream driver", mode); ABORT_FINALIZE(RS_RET_INVALID_DRVR_MODE); } @@ -1210,7 +1209,7 @@ SetAuthMode(nsd_t *pNsd, uchar *mode) } else if(!strcasecmp((char*) mode, "anon")) { pThis->authMode = GTLS_AUTH_CERTANON; } else { - errmsg.LogError(NO_ERRCODE, "error: authentication mode '%s' not supported by " + errmsg.LogError(0, RS_RET_VALUE_NOT_SUPPORTED, "error: authentication mode '%s' not supported by " "gtls netstream driver", mode); ABORT_FINALIZE(RS_RET_VALUE_NOT_SUPPORTED); } @@ -1237,7 +1236,7 @@ SetPermPeers(nsd_t *pNsd, permittedPeers_t *pPermPeers) FINALIZE; if(pThis->authMode != GTLS_AUTH_CERTFINGERPRINT && pThis->authMode != GTLS_AUTH_CERTNAME) { - errmsg.LogError(NO_ERRCODE, "authentication not supported by " + errmsg.LogError(0, RS_RET_VALUE_NOT_IN_THIS_MODE, "authentication not supported by " "gtls netstream driver in the configured authentication mode - ignored"); ABORT_FINALIZE(RS_RET_VALUE_NOT_IN_THIS_MODE); } diff --git a/runtime/nsd_ptcp.c b/runtime/nsd_ptcp.c index 93be8081..c3899f83 100644 --- a/runtime/nsd_ptcp.c +++ b/runtime/nsd_ptcp.c @@ -120,7 +120,7 @@ SetMode(nsd_t __attribute__((unused)) *pNsd, int mode) { DEFiRet; if(mode != 0) { - errmsg.LogError(NO_ERRCODE, "error: driver mode %d not supported by " + errmsg.LogError(0, RS_RET_INVALID_DRVR_MODE, "error: driver mode %d not supported by " "ptcp netstream driver", mode); ABORT_FINALIZE(RS_RET_INVALID_DRVR_MODE); } @@ -143,7 +143,7 @@ SetAuthMode(nsd_t __attribute__((unused)) *pNsd, uchar *mode) { DEFiRet; if(mode != NULL && strcasecmp((char*)mode, "anon")) { - errmsg.LogError(NO_ERRCODE, "error: authentication mode '%s' not supported by " + errmsg.LogError(0, RS_RET_VALUE_NOT_SUPPORTED, "error: authentication mode '%s' not supported by " "ptcp netstream driver", mode); ABORT_FINALIZE(RS_RET_VALUE_NOT_SUPPORTED); } @@ -163,7 +163,7 @@ SetPermPeers(nsd_t __attribute__((unused)) *pNsd, permittedPeers_t __attribute__ DEFiRet; if(pPermPeers != NULL) { - errmsg.LogError(NO_ERRCODE, "authentication not supported by ptcp netstream driver"); + errmsg.LogError(0, RS_RET_VALUE_NOT_IN_THIS_MODE, "authentication not supported by ptcp netstream driver"); ABORT_FINALIZE(RS_RET_VALUE_NOT_IN_THIS_MODE); } @@ -443,7 +443,7 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*), if(net.should_use_so_bsdcompat()) { if (setsockopt(sock, SOL_SOCKET, SO_BSDCOMPAT, (char *) &on, sizeof(on)) < 0) { - errmsg.LogError(NO_ERRCODE, "TCP setsockopt(BSDCOMPAT)"); + errmsg.LogError(errno, NO_ERRCODE, "TCP setsockopt(BSDCOMPAT)"); close(sock); continue; } diff --git a/runtime/obj.c b/runtime/obj.c index 9c7656c5..082aa691 100644 --- a/runtime/obj.c +++ b/runtime/obj.c @@ -1072,7 +1072,7 @@ RegisterObj(uchar *pszObjName, objInfo_t *pInfo) finalize_it: if(iRet != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "registering object '%s' failed with error code %d", pszObjName, iRet); + errmsg.LogError(0, NO_ERRCODE, "registering object '%s' failed with error code %d", pszObjName, iRet); } RETiRet; diff --git a/runtime/rsyslog.c b/runtime/rsyslog.c index c05119d8..54db12c2 100644 --- a/runtime/rsyslog.c +++ b/runtime/rsyslog.c @@ -79,11 +79,11 @@ #include "errmsg.h" /* forward definitions */ -static rsRetVal dfltErrLogger(uchar *errMsg); +static rsRetVal dfltErrLogger(int, uchar *errMsg); /* globally visible static data - see comment in rsyslog.h for details */ uchar *glblModPath; /* module load path */ -rsRetVal (*glblErrLogger)(uchar*) = dfltErrLogger; /* the error logger to use by the errmsg module */ +rsRetVal (*glblErrLogger)(int, uchar*) = dfltErrLogger; /* the error logger to use by the errmsg module */ /* static data */ static int iRefCount = 0; /* our refcount - it MUST exist only once inside a process (not thread) @@ -95,10 +95,10 @@ static int iRefCount = 0; /* our refcount - it MUST exist only once inside a pro * default so that we can log errors during the intial phase, most importantly * during initialization. -- rgerhards. 2008-04-17 */ -static rsRetVal dfltErrLogger(uchar *errMsg) +static rsRetVal dfltErrLogger(int iErr, uchar *errMsg) { DEFiRet; - fprintf(stderr, "rsyslog runtime error: %s\n", errMsg); + fprintf(stderr, "rsyslog runtime error(%d): %s\n", iErr, errMsg); RETiRet; } @@ -107,7 +107,7 @@ static rsRetVal dfltErrLogger(uchar *errMsg) * rgerhards, 2008-04-18 */ rsRetVal -rsrtSetErrLogger(rsRetVal (*errLogger)(uchar*)) +rsrtSetErrLogger(rsRetVal (*errLogger)(int, uchar*)) { DEFiRet; assert(errLogger != NULL); diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 5364a87a..7771bea5 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -111,10 +111,16 @@ typedef enum { */ enum rsRetVal_ /** return value. All methods return this if not specified otherwise */ { + /* the first two define are for errmsg.logError(), so that we can use the rsRetVal + * as an rsyslog error code. -- rgerhards, 20080-06-27 + */ + RS_RET_NO_ERRCODE = -1, /**< RESERVED for NO_ERRCODE errmsg.logError status name */ + RS_RET_INCLUDE_ERRNO = 1073741824, /* 2**30 - do NOT use error codes above this! */ + /* begin regular error codes */ RS_RET_NOT_IMPLEMENTED = -7, /**< implementation is missing (probably internal error or lazyness ;)) */ RS_RET_OUT_OF_MEMORY = -6, /**< memory allocation failed */ RS_RET_PROVIDED_BUFFER_TOO_SMALL = -50,/**< the caller provided a buffer, but the called function sees the size of this buffer is too small - operation not carried out */ - RS_RET_TRUE = -1, /**< to indicate a true state (can be used as TRUE, legacy) */ + RS_RET_TRUE = -3, /**< to indicate a true state (can be used as TRUE, legacy) */ RS_RET_FALSE = -2, /**< to indicate a false state (can be used as FALSE, legacy) */ RS_RET_NO_IRET = -8, /**< This is a trick for the debuging system - it means no iRet is provided */ RS_RET_ERR = -3000, /**< generic failure */ @@ -340,13 +346,13 @@ void dbgprintf(char *, ...) __attribute__((format(printf, 1, 2))); * add them. -- rgerhards, 2008-04-17 */ extern uchar *glblModPath; /* module load path */ -extern rsRetVal (*glblErrLogger)(uchar*); +extern rsRetVal (*glblErrLogger)(int, uchar*); /* some runtime prototypes */ rsRetVal rsrtInit(char **ppErrObj, obj_if_t *pObjIF); rsRetVal rsrtExit(void); int rsrtIsInit(void); -rsRetVal rsrtSetErrLogger(rsRetVal (*errLogger)(uchar*)); +rsRetVal rsrtSetErrLogger(rsRetVal (*errLogger)(int, uchar*)); #endif /* multi-include protection */ /* vim:set ai: |