diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/omfile.c | 20 | ||||
-rw-r--r-- | tools/omfwd.c | 14 | ||||
-rw-r--r-- | tools/omshell.c | 2 | ||||
-rw-r--r-- | tools/syslogd.c | 51 |
4 files changed, 49 insertions, 38 deletions
diff --git a/tools/omfile.c b/tools/omfile.c index 285e798d..06875fe4 100644 --- a/tools/omfile.c +++ b/tools/omfile.c @@ -161,14 +161,14 @@ rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal) snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar), "DynaFileCacheSize must be greater 0 (%d given), changed to 1.", iNewVal); errno = 0; - errmsg.LogError(NO_ERRCODE, "%s", errMsg); + errmsg.LogError(0, RS_RET_VAL_OUT_OF_RANGE, "%s", errMsg); iRet = RS_RET_VAL_OUT_OF_RANGE; iNewVal = 1; } else if(iNewVal > 10000) { snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar), "DynaFileCacheSize maximum is 10,000 (%d given), changed to 10,000.", iNewVal); errno = 0; - errmsg.LogError(NO_ERRCODE, "%s", errMsg); + errmsg.LogError(0, RS_RET_VAL_OUT_OF_RANGE, "%s", errMsg); iRet = RS_RET_VAL_OUT_OF_RANGE; iNewVal = 10000; } @@ -221,7 +221,7 @@ static rsRetVal cflineParseOutchannel(instanceData *pData, uchar* p, omodStringR snprintf(errMsg, sizeof(errMsg)/sizeof(char), "outchannel '%s' not found - ignoring action line", szBuf); - errmsg.LogError(NO_ERRCODE, "%s", errMsg); + errmsg.LogError(0, RS_RET_NOT_FOUND, "%s", errMsg); ABORT_FINALIZE(RS_RET_NOT_FOUND); } @@ -232,7 +232,7 @@ static rsRetVal cflineParseOutchannel(instanceData *pData, uchar* p, omodStringR snprintf(errMsg, sizeof(errMsg)/sizeof(char), "outchannel '%s' has no file name template - ignoring action line", szBuf); - errmsg.LogError(NO_ERRCODE, "%s", errMsg); + errmsg.LogError(0, RS_RET_ERR, "%s", errMsg); ABORT_FINALIZE(RS_RET_ERR); } @@ -497,7 +497,7 @@ static int prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsg if(iMsgOpts & INTERNAL_MSG) dbgprintf("Could not open dynaFile, discarding message\n"); else - errmsg.LogError(NO_ERRCODE, "Could not open dynamic file '%s' - discarding message", (char*)newFileName); + errmsg.LogError(0, NO_ERRCODE, "Could not open dynamic file '%s' - discarding message", (char*)newFileName); dynaFileDelCacheEntry(pCache, iFirstFree, 1); pData->iCurrElt = -1; return -1; @@ -554,14 +554,14 @@ again: "no longer writing to file %s; grown beyond configured file size of %lld bytes, actual size %lld - configured command did not resolve situation", pData->f_fname, (long long) pData->f_sizeLimit, (long long) actualFileSize); errno = 0; - errmsg.LogError(NO_ERRCODE, "%s", errMsg); + errmsg.LogError(0, RS_RET_DISABLE_ACTION, "%s", errMsg); ABORT_FINALIZE(RS_RET_DISABLE_ACTION); } else { snprintf(errMsg, sizeof(errMsg), "file %s had grown beyond configured file size of %lld bytes, actual size was %lld - configured command resolved situation", pData->f_fname, (long long) pData->f_sizeLimit, (long long) actualFileSize); errno = 0; - errmsg.LogError(NO_ERRCODE, "%s", errMsg); + errmsg.LogError(0, NO_ERRCODE, "%s", errMsg); } } } @@ -595,7 +595,7 @@ again: pData->fd = open((char*) pData->f_fname, O_WRONLY|O_APPEND|O_NOCTTY); if (pData->fd < 0) { iRet = RS_RET_DISABLE_ACTION; - errmsg.LogError(NO_ERRCODE, "%s", pData->f_fname); + errmsg.LogError(0, NO_ERRCODE, "%s", pData->f_fname); } else { untty(); goto again; @@ -603,7 +603,7 @@ again: } else { iRet = RS_RET_DISABLE_ACTION; errno = e; - errmsg.LogError(NO_ERRCODE, "%s", pData->f_fname); + errmsg.LogError(0, NO_ERRCODE, "%s", pData->f_fname); } } else if (pData->bSyncFile) { fsync(pData->fd); @@ -767,7 +767,7 @@ CODESTARTparseSelectorAct if ( pData->fd < 0 ){ pData->fd = -1; dbgprintf("Error opening log file: %s\n", pData->f_fname); - errmsg.LogError(NO_ERRCODE, "%s", pData->f_fname); + errmsg.LogError(0, NO_ERRCODE, "%s", pData->f_fname); break; } if (isatty(pData->fd)) { diff --git a/tools/omfwd.c b/tools/omfwd.c index 1783ef7d..fd326553 100644 --- a/tools/omfwd.c +++ b/tools/omfwd.c @@ -484,7 +484,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) if(*p == '@') { /* indicator for TCP! */ localRet = loadTCPSupport(); if(localRet != RS_RET_OK) { - errmsg.LogError(NO_ERRCODE, "could not activate network stream modules for TCP " + errmsg.LogError(0, localRet, "could not activate network stream modules for TCP " "(internal error %d) - are modules missing?", localRet); ABORT_FINALIZE(localRet); } @@ -521,12 +521,12 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) ++p; /* eat */ pData->compressionLevel = iLevel; } else { - errmsg.LogError(NO_ERRCODE, "Invalid compression level '%c' specified in " + errmsg.LogError(0, NO_ERRCODE, "Invalid compression level '%c' specified in " "forwardig action - NOT turning on compression.", *p); } # else - errmsg.LogError(NO_ERRCODE, "Compression requested, but rsyslogd is not compiled " + errmsg.LogError(0, NO_ERRCODE, "Compression requested, but rsyslogd is not compiled " "with compression support - request ignored."); # endif /* #ifdef USE_NETZIP */ } else if(*p == 'o') { /* octet-couting based TCP framing? */ @@ -534,7 +534,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* no further options settable */ tcp_framing = TCP_FRAMING_OCTET_COUNTING; } else { /* invalid option! Just skip it... */ - errmsg.LogError(NO_ERRCODE, "Invalid option %c in forwarding action - ignoring.", *p); + errmsg.LogError(0, NO_ERRCODE, "Invalid option %c in forwarding action - ignoring.", *p); ++p; /* eat invalid option */ } /* the option processing is done. We now do a generic skip @@ -550,7 +550,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* we probably have end of string - leave it for the rest * of the code to handle it (but warn the user) */ - errmsg.LogError(NO_ERRCODE, "Option block not terminated in forwarding action."); + errmsg.LogError(0, NO_ERRCODE, "Option block not terminated in forwarding action."); } /* extract the host first (we do a trick - we replace the ';' or ':' with a '\0') * now skip to port and then template name. rgerhards 2005-07-06 @@ -568,7 +568,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* SKIP AND COUNT */; pData->port = malloc(i + 1); if(pData->port == NULL) { - errmsg.LogError(NO_ERRCODE, "Could not get memory to store syslog forwarding port, " + errmsg.LogError(0, NO_ERRCODE, "Could not get memory to store syslog forwarding port, " "using default port, results may not be what you intend\n"); /* we leave f_forw.port set to NULL, this is then handled by getFwdPt(). */ } else { @@ -584,7 +584,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) if(bErr == 0) { /* only 1 error msg! */ bErr = 1; errno = 0; - errmsg.LogError(NO_ERRCODE, "invalid selector line (port), probably not doing " + errmsg.LogError(0, NO_ERRCODE, "invalid selector line (port), probably not doing " "what was intended"); } } diff --git a/tools/omshell.c b/tools/omshell.c index 2176c101..7b815869 100644 --- a/tools/omshell.c +++ b/tools/omshell.c @@ -92,7 +92,7 @@ CODESTARTdoAction */ dbgprintf("\n"); if(execProg((uchar*) pData->progName, 1, ppString[0]) == 0) - errmsg.LogError(NO_ERRCODE, "Executing program '%s' failed", (char*)pData->progName); + errmsg.LogError(0, NO_ERRCODE, "Executing program '%s' failed", (char*)pData->progName); ENDdoAction diff --git a/tools/syslogd.c b/tools/syslogd.c index ab4d6784..b21988ab 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -773,7 +773,7 @@ parseAndSubmitMessage(uchar *hname, uchar *hnameIP, uchar *msg, int len, int bPa * rgerhards, 2006-12-07 */ if(ret != Z_OK) { - errmsg.LogError(NO_ERRCODE, "Uncompression of a message failed with return code %d " + errmsg.LogError(0, NO_ERRCODE, "Uncompression of a message failed with return code %d " "- enable debug logging if you need further information. " "Message ignored.", ret); FINALIZE; /* unconditional exit, nothing left to do... */ @@ -786,7 +786,7 @@ parseAndSubmitMessage(uchar *hname, uchar *hnameIP, uchar *msg, int len, int bPa * tell the user we can not accept it. */ if(len > 0 && *msg == 'z') { - errmsg.LogError(NO_ERRCODE, "Received a compressed message, but rsyslogd does not have compression " + errmsg.LogError(0, NO_ERRCODE, "Received a compressed message, but rsyslogd does not have compression " "support enabled. The message will be ignored."); FINALIZE; } @@ -863,10 +863,10 @@ finalize_it: * message handler. -- rgerhards, 2008-04-17 */ rsRetVal -submitErrMsg(uchar *msg) +submitErrMsg(int iErr, uchar *msg) { DEFiRet; - iRet = logmsgInternal(LOG_SYSLOG|LOG_ERR, msg, ADDDATE); + iRet = logmsgInternal(iErr, LOG_SYSLOG|LOG_ERR, msg, ADDDATE); RETiRet; } @@ -880,10 +880,11 @@ submitErrMsg(uchar *msg) * think on the best way to do this. */ rsRetVal -logmsgInternal(int pri, uchar *msg, int flags) +logmsgInternal(int iErr, int pri, uchar *msg, int flags) { - DEFiRet; + uchar pszTag[33]; msg_t *pMsg; + DEFiRet; CHKiRet(msgConstruct(&pMsg)); MsgSetUxTradMsg(pMsg, (char*)msg); @@ -891,7 +892,17 @@ logmsgInternal(int pri, uchar *msg, int flags) MsgSetHOSTNAME(pMsg, (char*)glbl.GetLocalHostName()); MsgSetRcvFrom(pMsg, (char*)glbl.GetLocalHostName()); MsgSetRcvFromIP(pMsg, (uchar*)"127.0.0.1"); - MsgSetTAG(pMsg, "rsyslogd:"); + /* check if we have an error code associated and, if so, + * adjust the tag. -- r5gerhards, 2008-06-27 + */ + if(iErr == NO_ERRCODE) { + MsgSetTAG(pMsg, "rsyslogd:"); + } else { +dbgprintf("iErr %d\n", iErr); + snprintf((char*)pszTag, sizeof(pszTag), "rsyslogd%d:", iErr); + pszTag[32] = '\0'; /* just to make sure... */ + MsgSetTAG(pMsg, (char*)pszTag); + } pMsg->iFacility = LOG_FAC(pri); pMsg->iSeverity = LOG_PRI(pri); pMsg->bParseHOSTNAME = 0; @@ -1745,7 +1756,7 @@ void legacyOptsHook(void) while(pThis != NULL) { if(pThis->line != NULL) { errno = 0; - errmsg.LogError(NO_ERRCODE, "Warning: backward compatibility layer added to following " + errmsg.LogError(0, NO_ERRCODE, "Warning: backward compatibility layer added to following " "directive to rsyslog.conf: %s", pThis->line); conf.cfsysline(pThis->line); } @@ -1900,7 +1911,7 @@ die(int sig) "\" x-pid=\"%d\" x-info=\"http://www.rsyslog.com\"]" " exiting on signal %d.", (int) myPid, sig); errno = 0; - logmsgInternal(LOG_SYSLOG|LOG_INFO, (uchar*)buf, ADDDATE); + logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, (uchar*)buf, ADDDATE); } /* drain queue (if configured so) and stop main queue worker thread pool */ @@ -2262,19 +2273,19 @@ init(void) /* some checks */ if(iMainMsgQueueNumWorkers < 1) { - errmsg.LogError(NO_ERRCODE, "$MainMsgQueueNumWorkers must be at least 1! Set to 1.\n"); + errmsg.LogError(0, NO_ERRCODE, "$MainMsgQueueNumWorkers must be at least 1! Set to 1.\n"); iMainMsgQueueNumWorkers = 1; } if(MainMsgQueType == QUEUETYPE_DISK) { errno = 0; /* for logerror! */ if(glbl.GetWorkDir() == NULL) { - errmsg.LogError(NO_ERRCODE, "No $WorkDirectory specified - can not run main message queue in 'disk' mode. " + errmsg.LogError(0, NO_ERRCODE, "No $WorkDirectory specified - can not run main message queue in 'disk' mode. " "Using 'FixedArray' instead.\n"); MainMsgQueType = QUEUETYPE_FIXED_ARRAY; } if(pszMainMsgQFName == NULL) { - errmsg.LogError(NO_ERRCODE, "No $MainMsgQueueFileName specified - can not run main message queue in " + errmsg.LogError(0, NO_ERRCODE, "No $MainMsgQueueFileName specified - can not run main message queue in " "'disk' mode. Using 'FixedArray' instead.\n"); MainMsgQueType = QUEUETYPE_FIXED_ARRAY; } @@ -2297,11 +2308,11 @@ init(void) /* ... set some properties ... */ # define setQPROP(func, directive, data) \ CHKiRet_Hdlr(func(pMsgQueue, data)) { \ - errmsg.LogError(NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ + errmsg.LogError(0, NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ } # define setQPROPstr(func, directive, data) \ CHKiRet_Hdlr(func(pMsgQueue, data, (data == NULL)? 0 : strlen((char*) data))) { \ - errmsg.LogError(NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ + errmsg.LogError(0, NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ } setQPROP(queueSetMaxFileSize, "$MainMsgQueueFileSize", iMainMsgQueMaxFileSize); @@ -2353,7 +2364,7 @@ init(void) " [origin software=\"rsyslogd\" " "swVersion=\"" VERSION \ "\" x-pid=\"%d\" x-info=\"http://www.rsyslog.com\"] restart", (int) myPid); - logmsgInternal(LOG_SYSLOG|LOG_INFO, (uchar*)bufStartUpMsg, ADDDATE); + logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, (uchar*)bufStartUpMsg, ADDDATE); memset(&sigAct, 0, sizeof (sigAct)); sigemptyset(&sigAct.sa_mask); @@ -2385,7 +2396,7 @@ selectorAddList(selector_t *f) if(f != NULL) { CHKiRet(llGetNumElts(&f->llActList, &iActionCnt)); if(iActionCnt == 0) { - errmsg.LogError(NO_ERRCODE, "warning: selector line without actions will be discarded"); + errmsg.LogError(0, NO_ERRCODE, "warning: selector line without actions will be discarded"); selectorDestruct(f); } else { /* successfully created an entry */ @@ -2432,7 +2443,7 @@ static rsRetVal setMainMsgQueType(void __attribute__((unused)) *pVal, uchar *psz MainMsgQueType = QUEUETYPE_DIRECT; dbgprintf("main message queue type set to DIRECT (no queueing at all)\n"); } else { - errmsg.LogError(NO_ERRCODE, "unknown mainmessagequeuetype parameter: %s", (char *) pszType); + errmsg.LogError(0, RS_RET_INVALID_PARAMS, "unknown mainmessagequeuetype parameter: %s", (char *) pszType); iRet = RS_RET_INVALID_PARAMS; } free(pszType); /* no longer needed */ @@ -3178,7 +3189,7 @@ int realMain(int argc, char **argv) break; case 'h': if(iCompatibilityMode < 3) { - errmsg.LogError(NO_ERRCODE, "WARNING: -h option is no longer supported - ignored"); + errmsg.LogError(0, NO_ERRCODE, "WARNING: -h option is no longer supported - ignored"); } else { usage(); /* for v3 and above, it simply is an error */ } @@ -3273,7 +3284,7 @@ int realMain(int argc, char **argv) /* process compatibility mode settings */ if(iCompatibilityMode < 3) { - errmsg.LogError(NO_ERRCODE, "WARNING: rsyslogd is running in compatibility mode. Automatically " + errmsg.LogError(0, NO_ERRCODE, "WARNING: rsyslogd is running in compatibility mode. Automatically " "generated config directives may interfer with your rsyslog.conf settings. " "We suggest upgrading your config and adding -c3 as the first " "rsyslogd option."); @@ -3288,7 +3299,7 @@ int realMain(int argc, char **argv) } if(bEOptionWasGiven && iCompatibilityMode < 3) { - errmsg.LogError(NO_ERRCODE, "WARNING: \"message repeated n times\" feature MUST be turned on in " + errmsg.LogError(0, NO_ERRCODE, "WARNING: \"message repeated n times\" feature MUST be turned on in " "rsyslog.conf - CURRENTLY EVERY MESSAGE WILL BE LOGGED. Visit " "http://www.rsyslog.com/rptdmsgreduction to learn " "more and cast your vote if you want us to keep this feature."); |