summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2010-11-30 15:09:49 +0100
committerMichael Biebl <biebl@debian.org>2010-11-30 15:09:49 +0100
commit0a5a3fba01d42ef3b380c4ae27699bb42c3af493 (patch)
treecba36f6ed3cf72059d16e4e702be01325c1f73c7 /plugins
parent7e2b1add5ffd1d726801b5f3806c7e26f493c3e9 (diff)
downloadrsyslog-0a5a3fba01d42ef3b380c4ae27699bb42c3af493.tar.gz
Imported Upstream version 5.7.2upstream/5.7.2
Diffstat (limited to 'plugins')
-rw-r--r--plugins/imfile/imfile.c26
-rw-r--r--plugins/imklog/bsd.c6
-rw-r--r--plugins/imptcp/imptcp.c20
-rw-r--r--plugins/imuxsock/imuxsock.c22
4 files changed, 61 insertions, 13 deletions
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c
index 8a10e26..8681ac8 100644
--- a/plugins/imfile/imfile.c
+++ b/plugins/imfile/imfile.c
@@ -47,6 +47,7 @@
#include "datetime.h"
#include "unicode-helper.h"
#include "prop.h"
+#include "stringbuf.h"
MODULE_TYPE_INPUT /* must be present for input modules, do not remove */
@@ -67,15 +68,21 @@ typedef struct fileInfo_s {
uchar *pszStateFile; /* file in which state between runs is to be stored */
int iFacility;
int iSeverity;
+ int nRecords; /**< How many records did we process before persisting the stream? */
+ int iPersistStateInterval; /**< how often should state be persisted? (0=on close only) */
strm_t *pStrm; /* its stream (NULL if not assigned) */
} fileInfo_t;
+/* forward definitions */
+static rsRetVal persistStrmState(fileInfo_t *pInfo);
+
/* config variables */
static uchar *pszFileName = NULL;
static uchar *pszFileTag = NULL;
static uchar *pszStateFile = NULL;
static int iPollInterval = 10; /* number of seconds to sleep when there was no file activity */
+static int iPersistStateInterval = 0; /* how often if state file to be persisted? (default 0->never) */
static int iFacility = 128; /* local0 */
static int iSeverity = 5; /* notice, as of rfc 3164 */
@@ -153,10 +160,9 @@ openFile(fileInfo_t *pThis)
CHKiRet(strm.SeekCurrOffs(pThis->pStrm));
- /* OK, we could successfully read the file, so we now can request that it be deleted.
- * If we need it again, it will be written on the next shutdown.
+ /* note: we do not delete the state file, so that the last position remains
+ * known even in the case that rsyslogd aborts for some reason (like powerfail)
*/
- psSF->bDeleteOnClose = 1;
finalize_it:
if(psSF != NULL)
@@ -210,6 +216,10 @@ static rsRetVal pollFile(fileInfo_t *pThis, int *pbHadFileData)
*pbHadFileData = 1; /* this is just a flag, so set it and forget it */
CHKiRet(enqLine(pThis, pCStr)); /* process line */
rsCStrDestruct(&pCStr); /* discard string (must be done by us!) */
+ if(pThis->iPersistStateInterval > 0 && pThis->nRecords++ >= pThis->iPersistStateInterval) {
+ persistStrmState(pThis);
+ pThis->nRecords = 0;
+ }
}
finalize_it:
@@ -337,12 +347,15 @@ persistStrmState(fileInfo_t *pInfo)
{
DEFiRet;
strm_t *psSF = NULL; /* state file (stream) */
+ size_t lenDir;
ASSERT(pInfo != NULL);
/* TODO: create a function persistObj in obj.c? */
CHKiRet(strm.Construct(&psSF));
- CHKiRet(strm.SetDir(psSF, glbl.GetWorkDir(), strlen((char*)glbl.GetWorkDir())));
+ lenDir = ustrlen(glbl.GetWorkDir());
+ if(lenDir > 0)
+ CHKiRet(strm.SetDir(psSF, glbl.GetWorkDir(), lenDir));
CHKiRet(strm.SettOperationsMode(psSF, STREAMMODE_WRITE_TRUNC));
CHKiRet(strm.SetsType(psSF, STREAMTYPE_FILE_SINGLE));
CHKiRet(strm.SetFName(psSF, pInfo->pszStateFile, strlen((char*) pInfo->pszStateFile)));
@@ -474,6 +487,9 @@ static rsRetVal addMonitor(void __attribute__((unused)) *pVal, uchar *pNewVal)
pThis->iSeverity = iSeverity;
pThis->iFacility = iFacility;
+ pThis->iPersistStateInterval = iPersistStateInterval;
+ pThis->nRecords = 0;
+ iPersistStateInterval = 0;
} else {
errmsg.LogError(0, RS_RET_OUT_OF_DESRIPTORS, "Too many file monitors configured - ignoring this one");
ABORT_FINALIZE(RS_RET_OUT_OF_DESRIPTORS);
@@ -519,6 +535,8 @@ CODEmodInit_QueryRegCFSLineHdlr
NULL, &iFacility, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilepollinterval", 0, eCmdHdlrInt,
NULL, &iPollInterval, STD_LOADABLE_MODULE_ID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilepersiststateinterval", 0, eCmdHdlrInt,
+ NULL, &iPersistStateInterval, STD_LOADABLE_MODULE_ID));
/* that command ads a new file! */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputrunfilemonitor", 0, eCmdHdlrGetWord,
addMonitor, NULL, STD_LOADABLE_MODULE_ID));
diff --git a/plugins/imklog/bsd.c b/plugins/imklog/bsd.c
index b789935..0a4c7cd 100644
--- a/plugins/imklog/bsd.c
+++ b/plugins/imklog/bsd.c
@@ -86,7 +86,7 @@ static int fklog = -1; /* /dev/klog */
static uchar *GetPath(void)
{
- return pszPath ? pszPath : _PATH_KLOG;
+ return pszPath ? pszPath : (uchar*) _PATH_KLOG;
}
/* open the kernel log - will be called inside the willRun() imklog
@@ -97,7 +97,7 @@ klogWillRun(void)
{
DEFiRet;
- fklog = open(GetPath(), O_RDONLY, 0);
+ fklog = open((char*)GetPath(), O_RDONLY, 0);
if (fklog < 0) {
dbgprintf("can't open %s (%d)\n", GetPath(), errno);
iRet = RS_RET_ERR; // TODO: better error code
@@ -153,7 +153,7 @@ readklog(void)
break;
}
- for (p = pRcv; (q = strchr(p, '\n')) != NULL; p = q + 1) {
+ for (p = (char*)pRcv; (q = strchr(p, '\n')) != NULL; p = q + 1) {
*q = '\0';
Syslog(LOG_INFO, (uchar*) p);
}
diff --git a/plugins/imptcp/imptcp.c b/plugins/imptcp/imptcp.c
index 9b24dbc..6449ad6 100644
--- a/plugins/imptcp/imptcp.c
+++ b/plugins/imptcp/imptcp.c
@@ -30,6 +30,13 @@
* A copy of the GPL can be found in the file "COPYING" in this distribution.
*/
#include "config.h"
+#if !defined(HAVE_EPOLL_CREATE)
+# error imptcp requires OS support for epoll - can not build
+ /* imptcp gains speed by using modern Linux capabilities. As such,
+ * it can only be build on platforms supporting the epoll API.
+ */
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -1039,7 +1046,18 @@ CODESTARTwillRun
ABORT_FINALIZE(RS_RET_NO_RUN);
}
- if((epollfd = epoll_create1(EPOLL_CLOEXEC)) < 0) {
+# if defined(EPOLL_CLOEXEC) && defined(HAVE_EPOLL_CREATE1)
+ DBGPRINTF("imptcp uses epoll_create1()\n");
+ epollfd = epoll_create1(EPOLL_CLOEXEC);
+# else
+ DBGPRINTF("imptcp uses epoll_create()\n");
+ /* reading the docs, the number of epoll events passed to
+ * epoll_create() seems not to be used at all in kernels. So
+ * we just provide "a" number, happens to be 10.
+ */
+ epollfd = epoll_create(10);
+# endif
+ if(epollfd < 0) {
errmsg.LogError(0, RS_RET_EPOLL_CR_FAILED, "error: epoll_create() failed");
ABORT_FINALIZE(RS_RET_NO_RUN);
}
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
index 41bff4f..0eee112 100644
--- a/plugins/imuxsock/imuxsock.c
+++ b/plugins/imuxsock/imuxsock.c
@@ -66,6 +66,10 @@ MODULE_TYPE_INPUT
#endif
#endif
+/* emulate struct ucred for platforms that do not have it */
+#ifndef HAVE_SCM_CREDENTIALS
+struct ucred { int pid; };
+#endif
/* handle some defines missing on more than one platform */
#ifndef SUN_LEN
@@ -279,7 +283,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)) == NULL) {
+ if((listeners[nfd].ht = create_hashtable(100, 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");
@@ -406,6 +410,7 @@ openLogSocket(lstn_t *pLstn)
CHKiRet(createLogSocket(pLstn));
}
+# if HAVE_SCM_CREDENTIALS
if(pLstn->bUseCreds) {
one = 1;
if(setsockopt(pLstn->fd, SOL_SOCKET, SO_PASSCRED, &one, (socklen_t) sizeof(one)) != 0) {
@@ -417,6 +422,9 @@ openLogSocket(lstn_t *pLstn)
pLstn->bUseCreds = 0;
}
}
+# else /* HAVE_SCM_CREDENTIALS */
+ pLstn->bUseCreds = 0;
+# endif /* HAVE_SCM_CREDENTIALS */
finalize_it:
if(iRet != RS_RET_OK) {
@@ -513,7 +521,7 @@ SubmitMsg(uchar *pRcv, int lenRcv, lstn_t *pLstn, struct ucred *cred)
rs_ratelimit_state_t *ratelimiter = NULL;
DEFiRet;
-// TODO: handle format errors??
+ /* TODO: handle format errors?? */
/* we need to parse the pri first, because we need the severity for
* rate-limiting as well.
*/
@@ -530,8 +538,10 @@ SubmitMsg(uchar *pRcv, int lenRcv, lstn_t *pLstn, struct ucred *cred)
facil = LOG_FAC(pri);
sever = LOG_PRI(pri);
- if(sever >= pLstn->ratelimitSev)
+ if(sever >= pLstn->ratelimitSev) {
+ /* note: if cred == NULL, then ratelimiter == NULL as well! */
findRatelimiter(pLstn, cred, &ratelimiter); /* ignore error, better so than others... */
+ }
datetime.getCurrTime(&st, &tt);
if(ratelimiter != NULL && !withinRatelimit(ratelimiter, tt, cred->pid)) {
@@ -637,6 +647,7 @@ static rsRetVal readSocket(lstn_t *pLstn)
dbgprintf("Message from UNIX socket: #%d\n", pLstn->fd);
if(iRcvd > 0) {
cred = NULL;
+# if HAVE_SCM_CREDENTIALS
if(pLstn->bUseCreds) {
dbgprintf("XXX: pre CM loop, length of control message %d\n", (int) msgh.msg_controllen);
for (cm = CMSG_FIRSTHDR(&msgh); cm; cm = CMSG_NXTHDR(&msgh, cm)) {
@@ -644,11 +655,12 @@ static rsRetVal readSocket(lstn_t *pLstn)
if (cm->cmsg_level == SOL_SOCKET && cm->cmsg_type == SCM_CREDENTIALS) {
cred = (struct ucred*) CMSG_DATA(cm);
dbgprintf("XXX: got credentials pid %d\n", (int) cred->pid);
- //break;
+ break;
}
}
dbgprintf("XXX: post CM loop\n");
}
+# endif /* HAVE_SCM_CREDENTIALS */
CHKiRet(SubmitMsg(pRcv, iRcvd, pLstn, cred));
} else if(iRcvd < 0 && errno != EINTR) {
char errStr[1024];
@@ -749,7 +761,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)) == NULL) {
+ if((listeners[0].ht = create_hashtable(100, 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");