summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-04-17 12:46:57 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2008-04-17 12:46:57 +0200
commit60309004dfc57c3243abb2f01042950201596773 (patch)
tree707b9fbe0e4cc00133611701af0999c1bdacfbfc /runtime
parente5130affc022eff12a3d9584576a385edbb13465 (diff)
downloadrsyslog-60309004dfc57c3243abb2f01042950201596773.tar.gz
rsyslog-60309004dfc57c3243abb2f01042950201596773.tar.xz
rsyslog-60309004dfc57c3243abb2f01042950201596773.zip
completed better modularity of runtime
- added the ability to specify an error log function for the runtime - removed dependency of core runtime on dirty.h Note that it is "better" modularity, not perfect. There is still work to do, but I think we can for the time being proceed with other things.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/cfsysline.c1
-rw-r--r--runtime/errmsg.c17
-rw-r--r--runtime/glbl.c1
-rw-r--r--runtime/modules.c1
-rw-r--r--runtime/msg.c1
-rw-r--r--runtime/obj.c2
-rw-r--r--runtime/queue.c1
-rw-r--r--runtime/rsyslog.c20
-rw-r--r--runtime/rsyslog.h8
-rw-r--r--runtime/srutils.c1
-rw-r--r--runtime/stream.c1
-rw-r--r--runtime/wti.c1
-rw-r--r--runtime/wtp.c1
13 files changed, 34 insertions, 22 deletions
diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c
index cb86c7d4..ffc49057 100644
--- a/runtime/cfsysline.c
+++ b/runtime/cfsysline.c
@@ -33,7 +33,6 @@
#include <pwd.h>
#include <grp.h>
-#include "dirty.h" /* TODO: when the module interface & library design is done, this should be able to go away */
#include "cfsysline.h"
#include "obj.h"
#include "errmsg.h"
diff --git a/runtime/errmsg.c b/runtime/errmsg.c
index b555d06a..1744c902 100644
--- a/runtime/errmsg.c
+++ b/runtime/errmsg.c
@@ -33,7 +33,6 @@
#include <assert.h>
#include "rsyslog.h"
-#include "dirty.h"
#include "obj.h"
#include "errmsg.h"
#include "sysvar.h"
@@ -84,14 +83,7 @@ LogError(int __attribute__((unused)) iErrCode, char *fmt, ... )
msg[sizeof(msg)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
errno = 0;
- /* 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);
+ glblErrLogger((uchar*)msg);
ENDfunc
}
@@ -126,5 +118,12 @@ BEGINAbstractObjClassInit(errmsg, 1, OBJ_IS_CORE_MODULE) /* class, version */
/* set our own handlers */
ENDObjClassInit(errmsg)
+/* Exit the class.
+ * rgerhards, 2008-04-17
+ */
+BEGINObjClassExit(errmsg, OBJ_IS_CORE_MODULE) /* class, version */
+ /* release objects we no longer need */
+ENDObjClassExit(errmsg)
+
/* vi:set ai:
*/
diff --git a/runtime/glbl.c b/runtime/glbl.c
index 432da93a..047fd611 100644
--- a/runtime/glbl.c
+++ b/runtime/glbl.c
@@ -82,6 +82,7 @@ SIMP_PROP(DisableDNS, bDisableDNS, int)
SIMP_PROP(LocalDomain, LocalDomain, uchar*)
SIMP_PROP(StripDomains, StripDomains, char**)
SIMP_PROP(LocalHosts, LocalHosts, char**)
+
SIMP_PROP_SET(LocalHostName, LocalHostName, uchar*)
#undef SIMP_PROP
diff --git a/runtime/modules.c b/runtime/modules.c
index 8ae9f038..c156fef2 100644
--- a/runtime/modules.c
+++ b/runtime/modules.c
@@ -49,7 +49,6 @@
#include <unistd.h>
#include <sys/file.h>
-#include "dirty.h"
#include "cfsysline.h"
#include "modules.h"
#include "errmsg.h"
diff --git a/runtime/msg.c b/runtime/msg.c
index 96bd8cc5..e72ef71b 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -36,7 +36,6 @@
#include <assert.h>
#include <ctype.h>
#include "rsyslog.h"
-#include "dirty.h"
#include "srUtils.h"
#include "stringbuf.h"
#include "template.h"
diff --git a/runtime/obj.c b/runtime/obj.c
index 8f2f99e3..8ab606f9 100644
--- a/runtime/obj.c
+++ b/runtime/obj.c
@@ -1286,10 +1286,10 @@ objClassExit(void)
/* TODO: implement the class exits! */
#if 0
- errmsgClassInit(pModInfo);
cfsyslineInit(pModInfo);
varClassInit(pModInfo);
#endif
+ errmsgClassExit();
moduleClassExit();
RETiRet;
}
diff --git a/runtime/queue.c b/runtime/queue.c
index c6b617a9..56711416 100644
--- a/runtime/queue.c
+++ b/runtime/queue.c
@@ -43,7 +43,6 @@
#include <errno.h>
#include "rsyslog.h"
-#include "dirty.h"
#include "queue.h"
#include "stringbuf.h"
#include "srUtils.h"
diff --git a/runtime/rsyslog.c b/runtime/rsyslog.c
index d0eaa6f8..95ac23ef 100644
--- a/runtime/rsyslog.c
+++ b/runtime/rsyslog.c
@@ -56,6 +56,7 @@
* A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
*/
#include "config.h"
+#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -75,14 +76,33 @@
#include "queue.h"
#include "conf.h"
#include "glbl.h"
+#include "errmsg.h"
+
+/* forward definitions */
+static rsRetVal dfltErrLogger(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 */
/* static data */
static int iRefCount = 0; /* our refcount - it MUST exist only once inside a process (not thread)
thus it is perfectly OK to use a static. MUST be initialized to 0! */
+/* This is the default instance of the error logger. It simply writes the message
+ * to stderr. It is expected that this is replaced by the runtime user very early
+ * during startup (at least if the default is unsuitable). However, we provide a
+ * default so that we can log errors during the intial phase, most importantly
+ * during initialization. -- rgerhards. 2008-04-17
+ */
+static rsRetVal dfltErrLogger(uchar *errMsg)
+{
+ DEFiRet;
+ fprintf(stderr, "rsyslog runtime error: %s\n", errMsg);
+ RETiRet;
+}
+
+
/* globally initialze the runtime system
* NOTE: this is NOT thread safe and must not be called concurrently. If that
* ever poses a problem, we may use proper mutex calls - not considered needed yet.
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index 5a3175e2..868bb564 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -59,12 +59,15 @@
/* define some base data types */
+typedef unsigned char uchar;/* get rid of the unhandy "unsigned char" */
typedef struct thrdInfo thrdInfo_t;
typedef struct filed selector_t; /* TODO: this so far resides in syslogd.c, think about modularization */
typedef struct NetAddr netAddr_t;
typedef struct msg msg_t;
typedef struct interface_s interface_t;
typedef struct objInfo_s objInfo_t;
+typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */
+typedef rsRetVal (*errLogFunc_t)(uchar*); /* this is a trick to store a function ptr to a function returning a function ptr... */
/* some universal 64 bit define... */
typedef long long int64;
@@ -204,7 +207,6 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
RS_RET_NO_RUN = 3, /**< operation successful, but function does not like to be executed */
RS_RET_OK = 0 /**< operation successful */
};
-typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */
/* some helpful macros to work with srRetVals.
* Be sure to call the to-be-returned variable always "iRet" and
@@ -269,9 +271,6 @@ typedef enum rsObjectID rsObjID;
#define RSFREEOBJ(x) {(x)->OID = OIDrsFreed; free(x);}
#endif
-/* get rid of the unhandy "unsigned char"
- */
-typedef unsigned char uchar;
/* for the time being, we do our own portability handling here. It
* looks like autotools either does not yet support checks for it, or
@@ -297,6 +296,7 @@ void dbgprintf(char *, ...) __attribute__((format(printf, 1, 2)));
* add them. -- rgerhards, 2008-04-17
*/
extern uchar *glblModPath; /* module load path */
+extern rsRetVal (*glblErrLogger)(uchar*);
/* some runtime prototypes */
rsRetVal rsrtInit(char **ppErrObj, obj_if_t *pObjIF);
diff --git a/runtime/srutils.c b/runtime/srutils.c
index cf36493a..97cc3252 100644
--- a/runtime/srutils.c
+++ b/runtime/srutils.c
@@ -44,7 +44,6 @@
#define TRUE 1
#define FALSE 0
#include "srUtils.h"
-#include "dirty.h"
#include "obj.h"
diff --git a/runtime/stream.c b/runtime/stream.c
index 7274b807..3afa9fcd 100644
--- a/runtime/stream.c
+++ b/runtime/stream.c
@@ -41,7 +41,6 @@
#include <errno.h>
#include "rsyslog.h"
-#include "dirty.h"
#include "stringbuf.h"
#include "srUtils.h"
#include "obj.h"
diff --git a/runtime/wti.c b/runtime/wti.c
index 88439049..0e04200c 100644
--- a/runtime/wti.c
+++ b/runtime/wti.c
@@ -40,7 +40,6 @@
#include <errno.h>
#include "rsyslog.h"
-#include "dirty.h"
#include "stringbuf.h"
#include "srUtils.h"
#include "wtp.h"
diff --git a/runtime/wtp.c b/runtime/wtp.c
index 98f1bdbe..0658232b 100644
--- a/runtime/wtp.c
+++ b/runtime/wtp.c
@@ -41,7 +41,6 @@
#include <errno.h>
#include "rsyslog.h"
-#include "dirty.h"
#include "stringbuf.h"
#include "srUtils.h"
#include "wtp.h"