From bf3e0d4f224a26e2ac9bc3edfd1e6eedcf56c9f8 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 16 Apr 2008 18:01:26 +0200 Subject: prevented segfault during runtime library init phase --- runtime/errmsg.c | 10 +++++++++- runtime/glbl.h | 6 +++--- runtime/rsyslog.c | 15 +++++++++++++++ runtime/rsyslog.h | 1 + 4 files changed, 28 insertions(+), 4 deletions(-) (limited to 'runtime') diff --git a/runtime/errmsg.c b/runtime/errmsg.c index 01d392b7..b555d06a 100644 --- a/runtime/errmsg.c +++ b/runtime/errmsg.c @@ -83,7 +83,15 @@ LogError(int __attribute__((unused)) iErrCode, char *fmt, ... ) } msg[sizeof(msg)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ errno = 0; - logmsgInternal(LOG_SYSLOG|LOG_ERR, msg, ADDDATE); + + /* we must check if the runtime is initialized, because else we can NOT + * submit internal errors. -- rgerhards, 2008-04-16 + * TODO: a better way is to set an error handler and check if it is NULL + */ + if(rsrtIsInit()) + logmsgInternal(LOG_SYSLOG|LOG_ERR, msg, ADDDATE); + else + fprintf(stderr, "rsyslog runtime error: %s\n", msg); ENDfunc } diff --git a/runtime/glbl.h b/runtime/glbl.h index 5385006a..037c9ec4 100644 --- a/runtime/glbl.h +++ b/runtime/glbl.h @@ -29,8 +29,8 @@ * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution. */ -#ifndef GLOBALS_H_INCLUDED -#define GLOBALS_H_INCLUDED +#ifndef GLBL_H_INCLUDED +#define GLBL_H_INCLUDED #define glblGetIOBufSize() 4096 /* size of the IO buffer, e.g. for strm class */ @@ -38,4 +38,4 @@ extern uchar *glblModPath; /* module load path */ extern uchar *pszWorkDir; #define glblGetWorkDir() (pszWorkDir == NULL ? (uchar*) "" : pszWorkDir) -#endif /* #ifndef GLOBALS_H_INCLUDED */ +#endif /* #ifndef GLBL_H_INCLUDED */ diff --git a/runtime/rsyslog.c b/runtime/rsyslog.c index 0d983bb1..6051cc57 100644 --- a/runtime/rsyslog.c +++ b/runtime/rsyslog.c @@ -162,5 +162,20 @@ rsrtExit(obj_if_t *pObjIF) } +/* returns 0 if the rsyslog runtime is not initialized and another value + * if it is. This function is primarily meant to be used by runtime functions + * itself. However, it is safe to call it before initializing the runtime. + * Plugins should NOT rely on this function. The reason is that another caller + * may have already initialized it but deinits it before this plugin is done. + * So for plugins and like architectures, the right course of action is to + * call rsrtInit() and rsrtExit(), which can be called by multiple callers. + * rgerhards, 2008-04-16 + */ +int rsrtIsInit(void) +{ + return iRefCount; +} + + /* vim:set ai: */ diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 5ec3a369..54373673 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -288,6 +288,7 @@ void dbgprintf(char *, ...) __attribute__((format(printf, 1, 2))); /* some runtime prototypes */ rsRetVal rsrtInit(char **ppErrObj, obj_if_t *pObjIF); rsRetVal rsrtExit(obj_if_t *pObjIF); +int rsrtIsInit(void); #endif /* multi-include protection */ /* vim:set ai: -- cgit