summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorBojan Smojver <bojan@rexursive.com>2011-02-23 11:25:43 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2011-02-23 11:25:43 +0100
commitd1eb6e0edc51a78f3209448e800b25eda50340f2 (patch)
tree6d81c1de98eb0c77affaa2f112b5a0628f54ebc3 /runtime
parentee065f1cb55be56da6ed12b35cd0e686abcb3a10 (diff)
downloadrsyslog-d1eb6e0edc51a78f3209448e800b25eda50340f2.tar.gz
rsyslog-d1eb6e0edc51a78f3209448e800b25eda50340f2.tar.xz
rsyslog-d1eb6e0edc51a78f3209448e800b25eda50340f2.zip
added work-around for bug in gtls, which causes fd leak when using TLS
The capability has been added for module to specify that they do not like being unloaded. related bug tracker: http://bugzilla.adiscon.com/show_bug.cgi?id=222 Signed-off-by: Rainer Gerhards <rgerhards@adiscon.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/module-template.h12
-rw-r--r--runtime/modules.c48
-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, 77 insertions, 4 deletions
diff --git a/runtime/module-template.h b/runtime/module-template.h
index d05ec23c..c2585e67 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
@@ -342,6 +352,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 d7362753..86e7c695 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
}
@@ -413,6 +418,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);
@@ -433,6 +440,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
@@ -529,11 +538,28 @@ 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) {
+ if((pHandle = calloc(1, sizeof (*pHandle))) == NULL) {
+ iRet = RS_RET_OUT_OF_MEMORY;
+ goto finalize_it;
+ }
+
+ strncpy((char *)pHandle->szName,
+ (char *)name, PATH_MAX - 1);
+ pHandle->szName[PATH_MAX - 1] = '\0';
+ 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);
@@ -740,6 +766,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);
@@ -829,7 +856,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->szName)) {
+ 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 df1afbc3..7eff8581 100644
--- a/runtime/modules.h
+++ b/runtime/modules.h
@@ -75,12 +75,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 szName[PATH_MAX];
+ 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 e9ff2568..ea2dd9f3 100644
--- a/runtime/netstrms.c
+++ b/runtime/netstrms.c
@@ -40,6 +40,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 0ee70e56..152dc8de 100644
--- a/runtime/nsd_gtls.c
+++ b/runtime/nsd_gtls.c
@@ -56,6 +56,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