summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-11-29 09:44:58 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2013-11-29 09:44:58 +0100
commit89060ecec2db9799af3d5eb17a174b9a0f2bd4b2 (patch)
treeb2e5c5f7c18b4f5bb7f0a6a0c5c564df9e6e627b
parent1ea869ec5460806841ab4feacf24e25c288a5760 (diff)
downloadrsyslog-89060ecec2db9799af3d5eb17a174b9a0f2bd4b2.tar.gz
rsyslog-89060ecec2db9799af3d5eb17a174b9a0f2bd4b2.tar.bz2
rsyslog-89060ecec2db9799af3d5eb17a174b9a0f2bd4b2.zip
introduce new function to emit warning and other non-error messages
also refactor the error message subsystem a bit
-rw-r--r--runtime/errmsg.c96
-rw-r--r--runtime/errmsg.h5
-rw-r--r--runtime/rsyslog.c17
-rw-r--r--runtime/rsyslog.h4
-rw-r--r--tools/syslogd.c10
5 files changed, 84 insertions, 48 deletions
diff --git a/runtime/errmsg.c b/runtime/errmsg.c
index 55d013ea..5a3fca9b 100644
--- a/runtime/errmsg.c
+++ b/runtime/errmsg.c
@@ -56,51 +56,90 @@ DEFobjStaticHelpers
* maps to a specific error event).
* rgerhards, 2008-06-27
*/
-static void __attribute__((format(printf, 3, 4)))
-LogError(int iErrno, int iErrCode, const char *fmt, ... )
+static void
+doLogMsg(const int iErrno, const int iErrCode, const int severity, const char *msg)
{
- va_list ap;
- char buf[1024];
- char msg[1024];
+ char buf[2048];
char errStr[1024];
- size_t lenBuf;
-
- BEGINfunc
- assert(fmt != NULL);
- /* Format parameters */
- va_start(ap, fmt);
- lenBuf = vsnprintf(buf, sizeof(buf), fmt, ap);
- if(lenBuf >= sizeof(buf)) {
- /* if our buffer was too small, we simply truncate. */
- lenBuf--;
- }
- va_end(ap);
- /* Log the error now */
- buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
-
- dbgprintf("Called LogError, msg: %s\n", buf);
+ dbgprintf("Called LogMsg, msg: %s\n", msg);
if(iErrno != 0) {
rs_strerror_r(iErrno, errStr, sizeof(errStr));
if(iErrCode == NO_ERRCODE || iErrCode == RS_RET_ERR) {
- snprintf(msg, sizeof(msg), "%s: %s", buf, errStr);
+ snprintf(buf, sizeof(buf), "%s: %s", msg, errStr);
} else {
- snprintf(msg, sizeof(msg), "%s: %s [try http://www.rsyslog.com/e/%d ]", buf, errStr, iErrCode * -1);
+ snprintf(buf, sizeof(buf), "%s: %s [try http://www.rsyslog.com/e/%d ]", msg, errStr, iErrCode * -1);
}
} else {
if(iErrCode == NO_ERRCODE || iErrCode == RS_RET_ERR) {
- snprintf(msg, sizeof(msg), "%s", buf);
+ snprintf(buf, sizeof(buf), "%s", msg);
} else {
- snprintf(msg, sizeof(msg), "%s [try http://www.rsyslog.com/e/%d ]", buf, iErrCode * -1);
+ snprintf(buf, sizeof(buf), "%s [try http://www.rsyslog.com/e/%d ]", msg, iErrCode * -1);
}
}
- msg[sizeof(msg)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
+ buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
errno = 0;
- glblErrLogger(iErrCode, (uchar*)msg);
+ glblErrLogger(severity, iErrCode, (uchar*)buf);
+}
+
+/* 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, 3, 4)))
+LogError(const int iErrno, const int iErrCode, const char *fmt, ... )
+{
+ va_list ap;
+ char buf[2048];
+ size_t lenBuf;
+
+ va_start(ap, fmt);
+ lenBuf = vsnprintf(buf, sizeof(buf), fmt, ap);
+ if(lenBuf >= sizeof(buf)) {
+ /* if our buffer was too small, we simply truncate. */
+ lenBuf--;
+ }
+ va_end(ap);
+ buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
+
+ doLogMsg(iErrno, iErrCode, LOG_ERR, buf);
+}
- ENDfunc
+/* 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, 4, 5)))
+LogMsg(const int iErrno, const int iErrCode, const int severity, const char *fmt, ... )
+{
+ va_list ap;
+ char buf[2048];
+ size_t lenBuf;
+
+ va_start(ap, fmt);
+ lenBuf = vsnprintf(buf, sizeof(buf), fmt, ap);
+ if(lenBuf >= sizeof(buf)) {
+ /* if our buffer was too small, we simply truncate. */
+ lenBuf--;
+ }
+ va_end(ap);
+ buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
+
+ doLogMsg(iErrno, iErrCode, severity, buf);
}
@@ -119,6 +158,7 @@ CODESTARTobjQueryInterface(errmsg)
* of course, also affects the "if" above).
*/
pIf->LogError = LogError;
+ pIf->LogMsg = LogMsg;
finalize_it:
ENDobjQueryInterface(errmsg)
diff --git a/runtime/errmsg.h b/runtime/errmsg.h
index 3f511ae5..730e8f82 100644
--- a/runtime/errmsg.h
+++ b/runtime/errmsg.h
@@ -23,7 +23,6 @@
#include "errmsg.h"
-/* TODO: define error codes */
#define NO_ERRCODE -1
/* the errmsg object */
@@ -35,8 +34,10 @@ typedef struct errmsg_s {
/* interfaces */
BEGINinterface(errmsg) /* name must also be changed in ENDinterface macro! */
void __attribute__((format(printf, 3, 4))) (*LogError)(const int iErrno, const int iErrCode, const char *pszErrFmt, ... );
+ /* v2, 2013-11-29 */
+ void __attribute__((format(printf, 4, 5))) (*LogMsg)(const int iErrno, const int iErrCode, const int severity, const char *pszErrFmt, ... );
ENDinterface(errmsg)
-#define errmsgCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+#define errmsgCURR_IF_VERSION 2 /* increment whenever you change the interface structure! */
/* prototypes */
diff --git a/runtime/rsyslog.c b/runtime/rsyslog.c
index 6523ae6d..310d7a1d 100644
--- a/runtime/rsyslog.c
+++ b/runtime/rsyslog.c
@@ -86,11 +86,11 @@ int default_thr_sched_policy;
#endif
/* forward definitions */
-static rsRetVal dfltErrLogger(const int, const uchar *errMsg);
+static void dfltErrLogger(const int, const int, const uchar *errMsg);
/* globally visible static data - see comment in rsyslog.h for details */
uchar *glblModPath; /* module load path */
-rsRetVal (*glblErrLogger)(const int, const uchar*) = dfltErrLogger; /* the error logger to use by the errmsg module */
+void (*glblErrLogger)(const int, const int, const 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)
@@ -102,24 +102,21 @@ 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(const int iErr, const uchar *errMsg)
+static void
+dfltErrLogger(const int severity, const int iErr, const uchar *errMsg)
{
- DEFiRet;
- fprintf(stderr, "rsyslog runtime error(%d): %s\n", iErr, errMsg);
- RETiRet;
+ fprintf(stderr, "rsyslog runtime error(%d,%d): %s\n", severity, iErr, errMsg);
}
/* set the error log function
* rgerhards, 2008-04-18
*/
-rsRetVal
-rsrtSetErrLogger(rsRetVal (*errLogger)(int, const uchar*))
+void
+rsrtSetErrLogger(void (*errLogger)(const int, const int, const uchar*))
{
- DEFiRet;
assert(errLogger != NULL);
glblErrLogger = errLogger;
- RETiRet;
}
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index 10e91215..3c1e55d2 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -505,13 +505,13 @@ void dbgprintf(char *, ...) __attribute__((format(printf, 1, 2)));
* add them. -- rgerhards, 2008-04-17
*/
extern uchar *glblModPath; /* module load path */
-extern rsRetVal (*glblErrLogger)(int, const uchar*);
+extern void (*glblErrLogger)(const int, const int, const uchar*);
/* some runtime prototypes */
rsRetVal rsrtInit(char **ppErrObj, obj_if_t *pObjIF);
rsRetVal rsrtExit(void);
int rsrtIsInit(void);
-rsRetVal rsrtSetErrLogger(rsRetVal (*errLogger)(int, const uchar*));
+void rsrtSetErrLogger(void (*errLogger)(const int, const int, const uchar*));
/* this define below is (later) intended to be used to implement empty
* structs. TODO: check if compilers supports this and, if not, define
diff --git a/tools/syslogd.c b/tools/syslogd.c
index cbc1d74b..65e01858 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -417,12 +417,10 @@ finalize_it:
* function is also passed to the runtime library as the generic error
* message handler. -- rgerhards, 2008-04-17
*/
-rsRetVal
-submitErrMsg(const int iErr, const uchar *msg)
+void
+submitErrMsg(const int severity, const int iErr, const uchar *msg)
{
- DEFiRet;
- iRet = logmsgInternal(iErr, LOG_SYSLOG|LOG_ERR, msg, 0);
- RETiRet;
+ logmsgInternal(iErr, LOG_SYSLOG|(severity & 0x07), msg, 0);
}
@@ -1364,7 +1362,7 @@ InitGlobalClasses(void)
/* Intialize the runtime system */
pErrObj = "rsyslog runtime"; /* set in case the runtime errors before setting an object */
CHKiRet(rsrtInit(&pErrObj, &obj));
- CHKiRet(rsrtSetErrLogger(submitErrMsg)); /* set out error handler */
+ rsrtSetErrLogger(submitErrMsg);
/* Now tell the system which classes we need ourselfs */
pErrObj = "glbl";