summaryrefslogtreecommitdiffstats
path: root/plugins/imuxsock/imuxsock.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/imuxsock/imuxsock.c')
-rw-r--r--plugins/imuxsock/imuxsock.c133
1 files changed, 70 insertions, 63 deletions
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
index c503852c..c6db8c5a 100644
--- a/plugins/imuxsock/imuxsock.c
+++ b/plugins/imuxsock/imuxsock.c
@@ -62,7 +62,6 @@ MODULE_TYPE_NOKEEP
MODULE_CNFNAME("imuxsock")
/* defines */
-#define MAXFUNIX 50
#ifndef _PATH_LOG
#ifdef BSD
#define _PATH_LOG "/var/run/log"
@@ -148,7 +147,7 @@ typedef struct lstn_s {
sbool bUseSysTimeStamp; /* use timestamp from system (instead of from message) */
sbool bUnlink; /* unlink&re-create socket at start and end of processing */
} lstn_t;
-static lstn_t listeners[MAXFUNIX];
+static lstn_t *listeners;
static prop_t *pLocalHostIP = NULL; /* there is only one global IP for all internally-generated messages */
static prop_t *pInputName = NULL; /* our inputName currently is always "imudp", and this will hold it */
@@ -359,12 +358,7 @@ finalize_it:
}
-/* add an additional listen socket. Socket names are added
- * until the array is filled up. It is never reset, only at
- * module unload.
- * TODO: we should change the array to a list so that we
- * can support any number of listen socket names.
- * rgerhards, 2007-12-20
+/* add an additional listen socket.
* added capability to specify hostname for socket -- rgerhards, 2008-08-01
*/
static rsRetVal
@@ -372,53 +366,50 @@ addListner(instanceConf_t *inst)
{
DEFiRet;
- if(nfd < MAXFUNIX) {
- if(*inst->sockName == ':') {
- listeners[nfd].bParseHost = 1;
- } else {
- listeners[nfd].bParseHost = 0;
- }
- if(inst->pLogHostName == NULL) {
- listeners[nfd].hostName = NULL;
- } else {
- CHKiRet(prop.Construct(&(listeners[nfd].hostName)));
- CHKiRet(prop.SetString(listeners[nfd].hostName, inst->pLogHostName, ustrlen(inst->pLogHostName)));
- CHKiRet(prop.ConstructFinalize(listeners[nfd].hostName));
- }
- if(inst->ratelimitInterval > 0) {
- if((listeners[nfd].ht = create_hashtable(100, hash_from_key_fn, key_equals_fn,
- (void(*)(void*))ratelimitDestruct)) == NULL) {
- /* in this case, we simply turn off rate-limiting */
- DBGPRINTF("imuxsock: turning off rate limiting because we could not "
- "create hash table\n");
- inst->ratelimitInterval = 0;
- }
+ if(*inst->sockName == ':') {
+ listeners[nfd].bParseHost = 1;
+ } else {
+ listeners[nfd].bParseHost = 0;
+ }
+ if(inst->pLogHostName == NULL) {
+ listeners[nfd].hostName = NULL;
+ } else {
+ CHKiRet(prop.Construct(&(listeners[nfd].hostName)));
+ CHKiRet(prop.SetString(listeners[nfd].hostName, inst->pLogHostName, ustrlen(inst->pLogHostName)));
+ CHKiRet(prop.ConstructFinalize(listeners[nfd].hostName));
+ }
+ if(inst->ratelimitInterval > 0) {
+ if((listeners[nfd].ht = create_hashtable(100, hash_from_key_fn, key_equals_fn,
+ (void(*)(void*))ratelimitDestruct)) == NULL) {
+ /* in this case, we simply turn off rate-limiting */
+ DBGPRINTF("imuxsock: turning off rate limiting because we could not "
+ "create hash table\n");
+ inst->ratelimitInterval = 0;
}
- listeners[nfd].ratelimitInterval = inst->ratelimitInterval;
- listeners[nfd].ratelimitBurst = inst->ratelimitBurst;
- listeners[nfd].ratelimitSev = inst->ratelimitSeverity;
- listeners[nfd].flowCtl = inst->bUseFlowCtl ? eFLOWCTL_LIGHT_DELAY : eFLOWCTL_NO_DELAY;
- listeners[nfd].flags = inst->bIgnoreTimestamp ? IGNDATE : NOFLAG;
- listeners[nfd].bCreatePath = inst->bCreatePath;
- listeners[nfd].sockName = ustrdup(inst->sockName);
- listeners[nfd].bUseCreds = (inst->bDiscardOwnMsgs || inst->bWritePid || inst->ratelimitInterval || inst->bAnnotate) ? 1 : 0;
- listeners[nfd].bAnnotate = inst->bAnnotate;
- listeners[nfd].bParseTrusted = inst->bParseTrusted;
- listeners[nfd].bDiscardOwnMsgs = inst->bDiscardOwnMsgs;
- listeners[nfd].bUnlink = inst->bUnlink;
- listeners[nfd].bWritePid = inst->bWritePid;
- listeners[nfd].bUseSysTimeStamp = inst->bUseSysTimeStamp;
- CHKiRet(ratelimitNew(&listeners[nfd].dflt_ratelimiter, "imuxsock", NULL));
- ratelimitSetLinuxLike(listeners[nfd].dflt_ratelimiter,
- listeners[nfd].ratelimitInterval,
- listeners[nfd].ratelimitBurst);
- ratelimitSetSeverity(listeners[nfd].dflt_ratelimiter,
- listeners[nfd].ratelimitSev);
- nfd++;
} else {
- errmsg.LogError(0, NO_ERRCODE, "Out of unix socket name descriptors, ignoring %s\n",
- inst->sockName);
+ listeners[nfd].ht = NULL;
}
+ listeners[nfd].ratelimitInterval = inst->ratelimitInterval;
+ listeners[nfd].ratelimitBurst = inst->ratelimitBurst;
+ listeners[nfd].ratelimitSev = inst->ratelimitSeverity;
+ listeners[nfd].flowCtl = inst->bUseFlowCtl ? eFLOWCTL_LIGHT_DELAY : eFLOWCTL_NO_DELAY;
+ listeners[nfd].flags = inst->bIgnoreTimestamp ? IGNDATE : NOFLAG;
+ listeners[nfd].bCreatePath = inst->bCreatePath;
+ listeners[nfd].sockName = ustrdup(inst->sockName);
+ listeners[nfd].bUseCreds = (inst->bDiscardOwnMsgs || inst->bWritePid || inst->ratelimitInterval || inst->bAnnotate) ? 1 : 0;
+ listeners[nfd].bAnnotate = inst->bAnnotate;
+ listeners[nfd].bParseTrusted = inst->bParseTrusted;
+ listeners[nfd].bDiscardOwnMsgs = inst->bDiscardOwnMsgs;
+ listeners[nfd].bUnlink = inst->bUnlink;
+ listeners[nfd].bWritePid = inst->bWritePid;
+ listeners[nfd].bUseSysTimeStamp = inst->bUseSysTimeStamp;
+ CHKiRet(ratelimitNew(&listeners[nfd].dflt_ratelimiter, "imuxsock", NULL));
+ ratelimitSetLinuxLike(listeners[nfd].dflt_ratelimiter,
+ listeners[nfd].ratelimitInterval,
+ listeners[nfd].ratelimitBurst);
+ ratelimitSetSeverity(listeners[nfd].dflt_ratelimiter,
+ listeners[nfd].ratelimitSev);
+ nfd++;
finalize_it:
RETiRet;
@@ -1282,10 +1273,29 @@ ENDcheckCnf
BEGINactivateCnfPrePrivDrop
instanceConf_t *inst;
+ int nLstn;
+ int i;
CODESTARTactivateCnfPrePrivDrop
runModConf = pModConf;
+ if(runModConf->bOmitLocalLogging && nfd == 1)
+ ABORT_FINALIZE(RS_RET_OK);
+ /* we first calculate the number of listeners so that we can
+ * appropriately size the listener array.
+ */
+ nLstn = 0;
for(inst = runModConf->root ; inst != NULL ; inst = inst->next) {
- addListner(inst);
+ ++nLstn;
+ }
+ if(nLstn > 0) {
+ DBGPRINTF("imuxsock: allocating memory for %d addtl listeners\n", nLstn);
+ CHKmalloc(listeners = realloc(listeners, (1+nLstn)*sizeof(lstn_t)));
+ for(i = 1 ; i < nLstn ; ++i) {
+ listeners[i].sockName = NULL;
+ listeners[i].fd = -1;
+ }
+ for(inst = runModConf->root ; inst != NULL ; inst = inst->next) {
+ addListner(inst);
+ }
}
CHKiRet(activateListeners());
finalize_it:
@@ -1325,6 +1335,8 @@ BEGINrunInput
#endif
CODESTARTrunInput
+ if(runModConf->bOmitLocalLogging && nfd == 1)
+ ABORT_FINALIZE(RS_RET_OK);
/* this is an endless loop - it is terminated when the thread is
* signalled to do so. This, however, is handled by the framework,
* right into the sleep below.
@@ -1415,6 +1427,7 @@ ENDafterRun
BEGINmodExit
CODESTARTmodExit
+ free(listeners);
if(pInputName != NULL)
prop.Destruct(&pInputName);
@@ -1477,7 +1490,6 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
BEGINmodInit()
- int i;
CODESTARTmodInit
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
CODEmodInit_QueryRegCFSLineHdlr
@@ -1508,6 +1520,7 @@ CODEmodInit_QueryRegCFSLineHdlr
pLocalHostIP = glbl.GetLocalHostIP();
/* init system log socket settings */
+ CHKmalloc(listeners = malloc(sizeof(lstn_t)));
listeners[0].flags = IGNDATE;
listeners[0].sockName = UCHAR_CONSTANT(_PATH_LOG);
listeners[0].hostName = NULL;
@@ -1529,12 +1542,6 @@ CODEmodInit_QueryRegCFSLineHdlr
listeners[0].ratelimitInterval = 0;
}
- /* initialize socket names */
- for(i = 1 ; i < MAXFUNIX ; ++i) {
- listeners[i].sockName = NULL;
- listeners[i].fd = -1;
- }
-
/* register config file handlers */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputunixlistensocketignoremsgtimestamp", 0, eCmdHdlrBinary,
NULL, &cs.bIgnoreTimestamp, STD_LOADABLE_MODULE_ID));
@@ -1594,13 +1601,13 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(statsobj.SetName(modStats, UCHAR_CONSTANT("imuxsock")));
STATSCOUNTER_INIT(ctrSubmit, mutCtrSubmit);
CHKiRet(statsobj.AddCounter(modStats, UCHAR_CONSTANT("submitted"),
- ctrType_IntCtr, &ctrSubmit));
+ ctrType_IntCtr, CTR_FLAG_RESETTABLE, &ctrSubmit));
STATSCOUNTER_INIT(ctrLostRatelimit, mutCtrLostRatelimit);
CHKiRet(statsobj.AddCounter(modStats, UCHAR_CONSTANT("ratelimit.discarded"),
- ctrType_IntCtr, &ctrLostRatelimit));
+ ctrType_IntCtr, CTR_FLAG_RESETTABLE, &ctrLostRatelimit));
STATSCOUNTER_INIT(ctrNumRatelimiters, mutCtrNumRatelimiters);
CHKiRet(statsobj.AddCounter(modStats, UCHAR_CONSTANT("ratelimit.numratelimiters"),
- ctrType_IntCtr, &ctrNumRatelimiters));
+ ctrType_IntCtr, CTR_FLAG_RESETTABLE, &ctrNumRatelimiters));
CHKiRet(statsobj.ConstructFinalize(modStats));
ENDmodInit