summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-07-16 11:51:09 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2013-07-16 11:51:09 +0200
commit6caa8cb043885c1ea64f39d87e18e63d3c6c36ea (patch)
treefdc5f4746b43104cffb2467de899a70e86a23398
parentf8f87de0a5111b02b35057005949986ab8616802 (diff)
downloadrsyslog-6caa8cb043885c1ea64f39d87e18e63d3c6c36ea.tar.gz
rsyslog-6caa8cb043885c1ea64f39d87e18e63d3c6c36ea.tar.bz2
rsyslog-6caa8cb043885c1ea64f39d87e18e63d3c6c36ea.zip
add base plumbing for (later) dynamic table reload
among others, we change some internal interfaces. So far, we only add the necessary locks. More work in later commits.
-rw-r--r--grammar/rainerscript.c3
-rw-r--r--runtime/lookup.c26
-rw-r--r--runtime/lookup.h5
3 files changed, 23 insertions, 11 deletions
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index ef44a410..53e56f05 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -1481,8 +1481,7 @@ dbgprintf("DDDD: executing lookup\n");
}
cnfexprEval(func->expr[1], &r[1], usrptr);
str = (char*) var2CString(&r[1], &bMustFree);
- s = (char*)lookupKey(func->funcdata, (uchar*)str);
- ret->d.estr = es_newStrFromCStr(s, strlen(s));
+ ret->d.estr = lookupKey_estr(func->funcdata, (uchar*)str);
if(bMustFree) free(str);
if(r[1].datatype == 'S') es_deleteStr(r[1].d.estr);
break;
diff --git a/runtime/lookup.c b/runtime/lookup.c
index e83f5979..b0780354 100644
--- a/runtime/lookup.c
+++ b/runtime/lookup.c
@@ -67,6 +67,7 @@ lookupNew(lookup_t **ppThis)
DEFiRet;
CHKmalloc(pThis = malloc(sizeof(lookup_t)));
+ pthread_rwlock_init(&pThis->rwlock, NULL);
pThis->name = NULL;
if(loadConf->lu_tabs.root == NULL) {
@@ -85,9 +86,11 @@ finalize_it:
RETiRet;
}
void
-lookupDestruct(lookup_t *lookup)
+lookupDestruct(lookup_t *pThis)
{
- free(lookup);
+ pthread_rwlock_destroy(&pThis->rwlock);
+ free(pThis->name);
+ free(pThis);
}
void
@@ -171,19 +174,26 @@ lookupFindTable(uchar *name)
/* returns either a pointer to the value (read only!) or NULL
* if either the key could not be found or an error occured.
+ * Note that an estr_t object is returned. The caller is
+ * responsible for freeing it.
*/
-uchar *
-lookupKey(lookup_t *pThis, uchar *key)
+es_str_t *
+lookupKey_estr(lookup_t *pThis, uchar *key)
{
lookup_string_tab_etry_t *etry;
- uchar *r;
+ char *r;
+ es_str_t *estr;
+
+ pthread_rwlock_rdlock(&pThis->rwlock);
etry = bsearch(key, pThis->d.strtab, pThis->nmemb, sizeof(lookup_string_tab_etry_t), bs_arrcmp_strtab);
if(etry == NULL) {
- r = (uchar*)""; // TODO: use set default
+ r = ""; // TODO: use set default
} else {
- r = etry->val;
+ r = (char*)etry->val;
}
- return r;
+ estr = es_newStrFromCStr(r, strlen(r));
+ pthread_rwlock_unlock(&pThis->rwlock);
+ return estr;
}
diff --git a/runtime/lookup.h b/runtime/lookup.h
index db2737a2..12bd9336 100644
--- a/runtime/lookup.h
+++ b/runtime/lookup.h
@@ -20,6 +20,7 @@
*/
#ifndef INCLUDED_LOOKUP_H
#define INCLUDED_LOOKUP_H
+#include <libestr.h>
struct lookup_tables_s {
lookup_t *root; /* the root of the template list */
@@ -31,7 +32,9 @@ struct lookup_string_tab_etry_s {
uchar *val;
};
+/* a single lookup table */
struct lookup_s {
+ pthread_rwlock_t rwlock; /* protect us in case of dynamic reloads */
uchar *name;
uchar *filename;
uint32_t nmemb;
@@ -45,7 +48,7 @@ struct lookup_s {
void lookupInitCnf(lookup_tables_t *lu_tabs);
rsRetVal lookupProcessCnf(struct cnfobj *o);
lookup_t *lookupFindTable(uchar *name);
-uchar *lookupKey(lookup_t *pThis, uchar *key);
+es_str_t *lookupKey(lookup_t *pThis, uchar *key);
void lookupDestruct(lookup_t *pThis);
void lookupClassExit(void);
rsRetVal lookupClassInit(void);