summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/imuxsock/imuxsock.c4
-rw-r--r--plugins/omhdfs/Makefile.am3
-rw-r--r--plugins/omhdfs/omhdfs.c47
-rw-r--r--runtime/hashtable.h3
-rw-r--r--runtime/hashtable/hashtable.c17
-rw-r--r--runtime/hashtable/hashtable_private.h1
6 files changed, 53 insertions, 22 deletions
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
index 24bcebb7..ad2d61c8 100644
--- a/plugins/imuxsock/imuxsock.c
+++ b/plugins/imuxsock/imuxsock.c
@@ -278,7 +278,7 @@ addLstnSocketName(void __attribute__((unused)) *pVal, uchar *pNewVal)
}
CHKiRet(prop.ConstructFinalize(listeners[nfd].hostName));
if(ratelimitInterval > 0) {
- if((listeners[nfd].ht = create_hashtable(1000, hash_from_key_fn, key_equals_fn)) == NULL) {
+ if((listeners[nfd].ht = create_hashtable(1000, hash_from_key_fn, key_equals_fn, NULL)) == NULL) {
/* in this case, we simply turn of rate-limiting */
dbgprintf("imuxsock: turning off rate limiting because we could not "
"create hash table\n");
@@ -755,7 +755,7 @@ CODESTARTwillRun
if(pLogSockName != NULL)
listeners[0].sockName = pLogSockName;
if(ratelimitIntervalSysSock > 0) {
- if((listeners[0].ht = create_hashtable(1000, hash_from_key_fn, key_equals_fn)) == NULL) {
+ if((listeners[0].ht = create_hashtable(1000, hash_from_key_fn, key_equals_fn, NULL)) == NULL) {
/* in this case, we simply turn of rate-limiting */
dbgprintf("imuxsock: turning off rate limiting because we could not "
"create hash table\n");
diff --git a/plugins/omhdfs/Makefile.am b/plugins/omhdfs/Makefile.am
index 2e7ef8ea..95e6b102 100644
--- a/plugins/omhdfs/Makefile.am
+++ b/plugins/omhdfs/Makefile.am
@@ -1,7 +1,6 @@
pkglib_LTLIBRARIES = omhdfs.la
omhdfs_la_SOURCES = omhdfs.c
-#omhdfs_la_CPPFLAGS = -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS) -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux
omhdfs_la_CPPFLAGS = -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS) $(JAVA_INCLUDES)
omhdfs_la_LDFLAGS = -module -avoid-version -lhdfs $(JAVA_LIBS)
-omhdfs_la_LIBADD =
+omhdfs_la_LIBADD = $(RSRT_LIBS)
diff --git a/plugins/omhdfs/omhdfs.c b/plugins/omhdfs/omhdfs.c
index eaca90e4..734c28cd 100644
--- a/plugins/omhdfs/omhdfs.c
+++ b/plugins/omhdfs/omhdfs.c
@@ -61,6 +61,7 @@ static struct hashtable *files; /* holds all file objects that we know */
/* globals for default values */
static uchar *fileName = NULL;
static uchar *hdfsHost = NULL;
+static uchar *dfltTplName = NULL; /* default template name to use */
int hdfsPort = 0;
/* end globals for default values */
@@ -176,10 +177,10 @@ fileObjAddUser(file_t *pFile)
++pFile->nUsers;
if(pFile->nUsers == 2)
pthread_mutex_init(&pFile->mut, NULL);
- dbgprintf("omhdfs: file %s now being used by %d actions\n", pFile->name, pFile->nUsers);
+ DBGPRINTF("omhdfs: file %s now being used by %d actions\n", pFile->name, pFile->nUsers);
}
-static inline rsRetVal
+static rsRetVal
fileObjDestruct(file_t **ppFile)
{
file_t *pFile = *ppFile;
@@ -193,6 +194,18 @@ fileObjDestruct(file_t **ppFile)
return RS_RET_OK;
}
+/* this function is to be used as destructor for the
+ * hash table code.
+ */
+static void
+fileObjDestruct4Hashtable(void *ptr)
+{
+ dbgprintf("omfile: fileObjDestruct4Hashtable called\n");
+ file_t *pFile = (file_t*) ptr;
+ fileObjDestruct(&pFile);
+}
+
+
static inline rsRetVal
fileOpen(file_t *pFile)
{
@@ -261,6 +274,8 @@ finalize_it:
static inline rsRetVal
fileClose(file_t *pFile)
{
+ DEFiRet;
+
if(pFile->nUsers > 1)
d_pthread_mutex_lock(&pFile->mut);
if(pFile->fh != NULL) {
@@ -271,7 +286,7 @@ fileClose(file_t *pFile)
if(pFile->nUsers > 1)
d_pthread_mutex_unlock(&pFile->mut);
- return RS_RET_OK;
+ RETiRet;
}
/* ---END FILE OBJECT---------------------------------------------------- */
@@ -285,7 +300,8 @@ ENDcreateInstance
BEGINfreeInstance
CODESTARTfreeInstance
- fileObjDestruct(&pData->pFile);
+ if(pData->pFile != NULL)
+ fileObjDestruct(&pData->pFile);
ENDfreeInstance
@@ -315,8 +331,8 @@ CODESTARTparseSelectorAct
p += sizeof(":omhdfs:") - 1; /* eat indicator sequence (-1 because of '\0'!) */
CHKiRet(createInstance(&pData));
CODE_STD_STRING_REQUESTparseSelectorAct(1)
- CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, 0, (uchar*) "RSYSLOG_FileFormat"));
- //(pszFileDfltTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : pszFileDfltTplName));
+ CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, 0,
+ (dfltTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : dfltTplName));
if(fileName == NULL) {
errmsg.LogError(0, RS_RET_ERR_HDFS_OPEN, "omhdfs: no file name specified, can not continue");
@@ -327,17 +343,18 @@ CODESTARTparseSelectorAct
if(pFile == NULL) {
/* we need a new file object, this one not seen before */
CHKiRet(fileObjConstruct(&pFile));
- CHKmalloc(pFile->name = (uchar*)strdup((char*)fileName));
+ CHKmalloc(pFile->name = fileName);
CHKmalloc(keybuf = ustrdup(fileName));
+ fileName = NULL; /* re-set, data passed to file object */
+ CHKmalloc(pFile->hdfsHost = strdup((hdfsHost == NULL) ? "default" : (char*) hdfsHost));
+ pFile->hdfsPort = hdfsPort;
+ fileOpen(pFile);
r = hashtable_insert(files, keybuf, pFile);
if(r == 0)
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
}
fileObjAddUser(pFile);
- CHKmalloc(pFile->hdfsHost = strdup((hdfsHost == NULL) ? "default" : (char*) hdfsHost));
- pFile->hdfsPort = hdfsPort;
- fileOpen(pFile);
if(pFile->fh == NULL){
errmsg.LogError(0, RS_RET_ERR_HDFS_OPEN, "omhdfs: failed to open %s - retrying later", pFile->name);
iRet = RS_RET_SUSPENDED;
@@ -390,11 +407,13 @@ CODESTARTmodInit
*ipIFVersProvided = CURR_MOD_IF_VERSION;
CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(errmsg, CORE_COMPONENT));
- CHKmalloc(files = create_hashtable(20, hash_from_string, key_equals_string));
+ CHKmalloc(files = create_hashtable(20, hash_from_string, key_equals_string,
+ fileObjDestruct4Hashtable));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"omhdfsfilename", 0, eCmdHdlrGetWord, NULL, &fileName, NULL));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"omhdfshost", 0, eCmdHdlrGetWord, NULL, &hdfsHost, NULL));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"omhdfsport", 0, eCmdHdlrInt, NULL, &hdfsPort, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"omhdfsfilename", 0, eCmdHdlrGetWord, NULL, &fileName, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"omhdfshost", 0, eCmdHdlrGetWord, NULL, &hdfsHost, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"omhdfsport", 0, eCmdHdlrInt, NULL, &hdfsPort, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"omhdfsdefaulttemplate", 0, eCmdHdlrGetWord, NULL, &dfltTplName, NULL));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
CODEmodInit_QueryRegCFSLineHdlr
ENDmodInit
diff --git a/runtime/hashtable.h b/runtime/hashtable.h
index 0f980127..f777ad0b 100644
--- a/runtime/hashtable.h
+++ b/runtime/hashtable.h
@@ -68,13 +68,14 @@ struct hashtable;
* @param minsize minimum initial size of hashtable
* @param hashfunction function for hashing keys
* @param key_eq_fn function for determining key equality
+ * @param dest destructor for value entries (NULL -> use free())
* @return newly created hashtable or NULL on failure
*/
struct hashtable *
create_hashtable(unsigned int minsize,
unsigned int (*hashfunction) (void*),
- int (*key_eq_fn) (void*,void*));
+ int (*key_eq_fn) (void*,void*), void (*dest) (void*));
/*****************************************************************************
* hashtable_insert
diff --git a/runtime/hashtable/hashtable.c b/runtime/hashtable/hashtable.c
index e2a2b3f4..41fc60fe 100644
--- a/runtime/hashtable/hashtable.c
+++ b/runtime/hashtable/hashtable.c
@@ -29,7 +29,7 @@ const float max_load_factor = 0.65;
struct hashtable *
create_hashtable(unsigned int minsize,
unsigned int (*hashf) (void*),
- int (*eqf) (void*,void*))
+ int (*eqf) (void*,void*), void (*dest)(void*))
{
struct hashtable *h;
unsigned int pindex, size = primes[0];
@@ -49,6 +49,7 @@ create_hashtable(unsigned int minsize,
h->entrycount = 0;
h->hashfn = hashf;
h->eqfn = eqf;
+ h->dest = dest;
h->loadlimit = (unsigned int) ceil(size * max_load_factor);
return h;
}
@@ -225,7 +226,16 @@ hashtable_destroy(struct hashtable *h, int free_values)
{
e = table[i];
while (NULL != e)
- { f = e; e = e->next; freekey(f->k); free(f->v); free(f); }
+ {
+ f = e;
+ e = e->next;
+ freekey(f->k);
+ if(h->dest == NULL)
+ free(f->v);
+ else
+ h->dest(f->v);
+ free(f);
+ }
}
}
else
@@ -264,7 +274,8 @@ hash_from_string(void *k)
int
key_equals_string(void *key1, void *key2)
{
- return strcmp(key1, key2);
+ /* we must return true IF the keys are equal! */
+ return !strcmp(key1, key2);
}
diff --git a/runtime/hashtable/hashtable_private.h b/runtime/hashtable/hashtable_private.h
index 3e95f600..10b82da4 100644
--- a/runtime/hashtable/hashtable_private.h
+++ b/runtime/hashtable/hashtable_private.h
@@ -21,6 +21,7 @@ struct hashtable {
unsigned int primeindex;
unsigned int (*hashfn) (void *k);
int (*eqfn) (void *k1, void *k2);
+ void (*dest) (void *v); /* destructor for values, if NULL use free() */
};
/*****************************************************************************/