summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-03-11 10:24:58 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2011-03-11 10:24:58 +0100
commit6c3ef4dacfa0a0fb0099299e30335c788704fe2a (patch)
treecb43da8a6fd9508f872059d6dada70ed02348b10 /runtime
parentcd61ecd459d7ba915ac5b31743e7ded8db62e30e (diff)
parentfd26a42bdc04eaf497cafd9ef806a54f3de1a7e9 (diff)
downloadrsyslog-6c3ef4dacfa0a0fb0099299e30335c788704fe2a.tar.gz
rsyslog-6c3ef4dacfa0a0fb0099299e30335c788704fe2a.tar.xz
rsyslog-6c3ef4dacfa0a0fb0099299e30335c788704fe2a.zip
Merge branch 'v5-beta'
Conflicts: ChangeLog configure.ac doc/manual.html plugins/omlibdbi/omlibdbi.c tests/Makefile.am tests/diag.sh
Diffstat (limited to 'runtime')
-rw-r--r--runtime/module-template.h12
-rw-r--r--runtime/modules.c56
-rw-r--r--runtime/modules.h14
-rw-r--r--runtime/net.c1
-rw-r--r--runtime/netstrms.c1
-rw-r--r--runtime/nsd_gtls.c1
-rw-r--r--runtime/nsd_ptcp.c1
-rw-r--r--runtime/regexp.c1
-rw-r--r--runtime/strmsrv.c1
-rw-r--r--runtime/zlibw.c1
10 files changed, 85 insertions, 4 deletions
diff --git a/runtime/module-template.h b/runtime/module-template.h
index f0084ea1..2b0ed593 100644
--- a/runtime/module-template.h
+++ b/runtime/module-template.h
@@ -77,6 +77,16 @@ static rsRetVal modGetType(eModType_t *modType) \
DEF_LMOD_STATIC_DATA \
MODULE_TYPE(eMOD_LIB)
+/* Macro to define whether the module should be kept dynamically linked.
+ */
+#define MODULE_KEEP_TYPE(x)\
+static rsRetVal modGetKeepType(eModKeepType_t *modKeepType) \
+ { \
+ *modKeepType = x; \
+ return RS_RET_OK;\
+ }
+#define MODULE_TYPE_NOKEEP MODULE_KEEP_TYPE(eMOD_NOKEEP)
+#define MODULE_TYPE_KEEP MODULE_KEEP_TYPE(eMOD_KEEP)
/* macro to define a unique module id. This must be able to fit in a void*. The
* module id must be unique inside a running rsyslogd application. It is used to
@@ -386,6 +396,8 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())\
*pEtryPoint = modGetID;\
} else if(!strcmp((char*) name, "getType")) {\
*pEtryPoint = modGetType;\
+ } else if(!strcmp((char*) name, "getKeepType")) {\
+ *pEtryPoint = modGetKeepType;\
}
/* the following definition is the standard block for queryEtryPt for output
diff --git a/runtime/modules.c b/runtime/modules.c
index 73a0012c..8ede134b 100644
--- a/runtime/modules.c
+++ b/runtime/modules.c
@@ -77,6 +77,9 @@ static pthread_mutex_t mutLoadUnload;
static modInfo_t *pLoadedModules = NULL; /* list of currently-loaded modules */
static modInfo_t *pLoadedModulesLast = NULL; /* tail-pointer */
+/* already dlopen()-ed libs */
+static struct dlhandle_s *pHandles = NULL;
+
/* config settings */
uchar *pModDir = NULL; /* read-only after startup */
@@ -232,7 +235,9 @@ static void moduleDestruct(modInfo_t *pThis)
# ifdef VALGRIND
# warning "dlclose disabled for valgrind"
# else
- dlclose(pThis->pModHdlr);
+ if (pThis->eKeepType == eMOD_NOKEEP) {
+ dlclose(pThis->pModHdlr);
+ }
# endif
}
@@ -412,6 +417,8 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
strgen_t *pStrgen; /* used for strgen modules */
rsRetVal (*GetName)(uchar**);
rsRetVal (*modGetType)(eModType_t *pType);
+ rsRetVal (*modGetKeepType)(eModKeepType_t *pKeepType);
+ struct dlhandle_s *pHandle = NULL;
DEFiRet;
assert(modInit != NULL);
@@ -432,6 +439,8 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
*/
CHKiRet((*pNew->modQueryEtryPt)((uchar*)"getType", &modGetType));
CHKiRet((*modGetType)(&pNew->eType));
+ CHKiRet((*pNew->modQueryEtryPt)((uchar*)"getKeepType", &modGetKeepType));
+ CHKiRet((*modGetKeepType)(&pNew->eKeepType));
dbgprintf("module of type %d being loaded.\n", pNew->eType);
/* OK, we know we can successfully work with the module. So we now fill the
@@ -530,11 +539,36 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
pNew->pszName = (uchar*) strdup((char*)name); /* we do not care if strdup() fails, we can accept that */
pNew->pModHdlr = pModHdlr;
/* TODO: take this from module */
- if(pModHdlr == NULL)
+ if(pModHdlr == NULL) {
pNew->eLinkType = eMOD_LINK_STATIC;
- else
+ } else {
pNew->eLinkType = eMOD_LINK_DYNAMIC_LOADED;
+ /* if we need to keep the linked module, save it */
+ if (pNew->eKeepType == eMOD_KEEP) {
+ /* see if we have this one already */
+ for (pHandle = pHandles; pHandle; pHandle = pHandle->next) {
+ if (!strcmp((char *)name, (char *)pHandle->pszName))
+ break;
+ }
+
+ /* not found, create it */
+ if (!pHandle) {
+ if((pHandle = malloc(sizeof (*pHandle))) == NULL) {
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ }
+ if((pHandle->pszName = (uchar*) strdup((char*)name)) == NULL) {
+ free(pHandle);
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ }
+ pHandle->pModHdlr = pModHdlr;
+ pHandle->next = pHandles;
+
+ pHandles = pHandle;
+ }
+ }
+ }
+
/* we initialized the structure, now let's add it to the linked list of modules */
addModToList(pNew);
@@ -743,6 +777,7 @@ Load(uchar *pModName)
modInfo_t *pModInfo;
uchar *pModDirCurr, *pModDirNext;
int iLoadCnt;
+ struct dlhandle_s *pHandle = NULL;
assert(pModName != NULL);
dbgprintf("Requested to load module '%s'\n", pModName);
@@ -832,7 +867,20 @@ Load(uchar *pModName)
/* complete load path constructed, so ... GO! */
dbgprintf("loading module '%s'\n", szPath);
- pModHdlr = dlopen((char *) szPath, RTLD_NOW);
+
+ /* see if we have this one already */
+ for (pHandle = pHandles; pHandle; pHandle = pHandle->next) {
+ if (!strcmp((char *)pModName, (char *)pHandle->pszName)) {
+ pModHdlr = pHandle->pModHdlr;
+ break;
+ }
+ }
+
+ /* not found, try to dynamically link it */
+ if (!pModHdlr) {
+ pModHdlr = dlopen((char *) szPath, RTLD_NOW);
+ }
+
iLoadCnt++;
} while(pModHdlr == NULL && *pModName != '/' && pModDirNext);
diff --git a/runtime/modules.h b/runtime/modules.h
index a78cd6f1..c1c38a26 100644
--- a/runtime/modules.h
+++ b/runtime/modules.h
@@ -77,12 +77,26 @@ typedef enum eModLinkType_ {
eMOD_LINK_ALL /* special: all linkage types, e.g. for unload */
} eModLinkType_t;
+/* remember which shared libs we dlopen()-ed */
+struct dlhandle_s {
+ uchar *pszName;
+ void *pModHdlr;
+ struct dlhandle_s *next;
+};
+
+/* should this module be kept linked? */
+typedef enum eModKeepType_ {
+ eMOD_NOKEEP,
+ eMOD_KEEP
+} eModKeepType_t;
+
struct modInfo_s {
struct modInfo_s *pPrev; /* support for creating a double linked module list */
struct modInfo_s *pNext; /* support for creating a linked module list */
int iIFVers; /* Interface version of module */
eModType_t eType; /* type of this module */
eModLinkType_t eLinkType;
+ eModKeepType_t eKeepType; /* keep the module dynamically linked on unload */
uchar* pszName; /* printable module name, e.g. for dbgprintf */
unsigned uRefCnt; /* reference count for this module; 0 -> may be unloaded */
/* functions supported by all types of modules */
diff --git a/runtime/net.c b/runtime/net.c
index 7653ea1d..789790f6 100644
--- a/runtime/net.c
+++ b/runtime/net.c
@@ -69,6 +69,7 @@
#endif
MODULE_TYPE_LIB
+MODULE_TYPE_NOKEEP
/* static data */
DEFobjStaticHelpers
diff --git a/runtime/netstrms.c b/runtime/netstrms.c
index 56e492fe..0122064d 100644
--- a/runtime/netstrms.c
+++ b/runtime/netstrms.c
@@ -39,6 +39,7 @@
#include "netstrms.h"
MODULE_TYPE_LIB
+MODULE_TYPE_NOKEEP
/* static data */
DEFobjStaticHelpers
diff --git a/runtime/nsd_gtls.c b/runtime/nsd_gtls.c
index b4e747bf..d0fd0e0f 100644
--- a/runtime/nsd_gtls.c
+++ b/runtime/nsd_gtls.c
@@ -55,6 +55,7 @@
GCRY_THREAD_OPTION_PTHREAD_IMPL;
MODULE_TYPE_LIB
+MODULE_TYPE_KEEP
/* static data */
DEFobjStaticHelpers
diff --git a/runtime/nsd_ptcp.c b/runtime/nsd_ptcp.c
index ca00749c..c8915231 100644
--- a/runtime/nsd_ptcp.c
+++ b/runtime/nsd_ptcp.c
@@ -52,6 +52,7 @@
#include "nsd_ptcp.h"
MODULE_TYPE_LIB
+MODULE_TYPE_NOKEEP
/* static data */
DEFobjStaticHelpers
diff --git a/runtime/regexp.c b/runtime/regexp.c
index 86b3e6c4..21079f80 100644
--- a/runtime/regexp.c
+++ b/runtime/regexp.c
@@ -35,6 +35,7 @@
#include "regexp.h"
MODULE_TYPE_LIB
+MODULE_TYPE_NOKEEP
/* static data */
DEFobjStaticHelpers
diff --git a/runtime/strmsrv.c b/runtime/strmsrv.c
index a122ca8a..e66ad717 100644
--- a/runtime/strmsrv.c
+++ b/runtime/strmsrv.c
@@ -75,6 +75,7 @@
#include "unicode-helper.h"
MODULE_TYPE_LIB
+MODULE_TYPE_NOKEEP
/* defines */
#define STRMSESS_MAX_DEFAULT 200 /* default for nbr of strm sessions if no number is given */
diff --git a/runtime/zlibw.c b/runtime/zlibw.c
index 2b386213..455c20d9 100644
--- a/runtime/zlibw.c
+++ b/runtime/zlibw.c
@@ -34,6 +34,7 @@
#include "zlibw.h"
MODULE_TYPE_LIB
+MODULE_TYPE_NOKEEP
/* static data */
DEFobjStaticHelpers