summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-04-16 18:01:26 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2008-04-16 18:01:26 +0200
commitbf3e0d4f224a26e2ac9bc3edfd1e6eedcf56c9f8 (patch)
treec74263495311d4ffbeb55f0fb27d102144f55024
parent5987107df46157eb847bc8271157ab8a7c73f6f4 (diff)
downloadrsyslog-bf3e0d4f224a26e2ac9bc3edfd1e6eedcf56c9f8.tar.gz
rsyslog-bf3e0d4f224a26e2ac9bc3edfd1e6eedcf56c9f8.tar.xz
rsyslog-bf3e0d4f224a26e2ac9bc3edfd1e6eedcf56c9f8.zip
prevented segfault during runtime library init phase
-rw-r--r--runtime/errmsg.c10
-rw-r--r--runtime/glbl.h6
-rw-r--r--runtime/rsyslog.c15
-rw-r--r--runtime/rsyslog.h1
-rw-r--r--tools/syslogd.c6
5 files changed, 31 insertions, 7 deletions
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:
diff --git a/tools/syslogd.c b/tools/syslogd.c
index a356c338..6f252b3a 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -292,7 +292,7 @@ uchar *pszWorkDir = NULL;/* name of rsyslog's spool directory (without trailing
uchar *glblModPath = NULL; /* module load path - only used during initial init, only settable via -M command line option */
/* end global config file state variables */
-uchar *LocalHostName;/* our hostname - read-only after startup */
+uchar *LocalHostName = NULL;/* our hostname - read-only after startup */
char *LocalDomain; /* our local domain name - read-only after startup */
int MarkInterval = 20 * 60; /* interval between marks in seconds - read-only after startup */
int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both), set via cmdline */
@@ -882,8 +882,8 @@ logmsgInternal(int pri, char *msg, int flags)
CHKiRet(msgConstruct(&pMsg));
MsgSetUxTradMsg(pMsg, msg);
MsgSetRawMsg(pMsg, msg);
- MsgSetHOSTNAME(pMsg, (char*)LocalHostName);
- MsgSetRcvFrom(pMsg, (char*)LocalHostName);
+ MsgSetHOSTNAME(pMsg, (LocalHostName == NULL) ? "[localhost]" : (char*)LocalHostName);
+ MsgSetRcvFrom(pMsg, (LocalHostName == NULL) ? "[localhost]" : (char*)LocalHostName);
MsgSetTAG(pMsg, "rsyslogd:");
pMsg->iFacility = LOG_FAC(pri);
pMsg->iSeverity = LOG_PRI(pri);