summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cfsysline.c124
-rw-r--r--cfsysline.h2
-rw-r--r--doc/imfile.html19
-rw-r--r--plugins/imfile/imfile.c20
-rwxr-xr-xsrUtils.c8
-rwxr-xr-xsrUtils.h10
-rw-r--r--syslogd.c1
7 files changed, 143 insertions, 41 deletions
diff --git a/cfsysline.c b/cfsysline.c
index 0cc6c134..7249188e 100644
--- a/cfsysline.c
+++ b/cfsysline.c
@@ -438,7 +438,40 @@ finalize_it:
}
-/* Parse and a word config line option. A word is a consequitive
+/* parse a whitespace-delimited word from the provided string. This is a
+ * helper function for a number of syntaxes. The parsed value is returned
+ * in ppStrB (which must be provided by caller).
+ * rgerhards, 2008-02-14
+ */
+static rsRetVal
+getWord(uchar **pp, rsCStrObj **ppStrB)
+{
+ DEFiRet;
+ uchar *p;
+
+ ASSERT(pp != NULL);
+ ASSERT(*pp != NULL);
+ ASSERT(*ppStrB != NULL);
+
+ if((*ppStrB = rsCStrConstruct()) == NULL)
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+
+ /* parse out the word */
+ p = *pp;
+
+ while(*p && !isspace((int) *p)) {
+ CHKiRet(rsCStrAppendChar(*ppStrB, *p++));
+ }
+ CHKiRet(rsCStrFinish(*ppStrB));
+
+ *pp = p;
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* Parse and a word config line option. A word is a consequtive
* sequence of non-whitespace characters. pVal must be
* a pointer to a string which is to receive the option
* value. The returned string must be freed by the caller.
@@ -455,23 +488,12 @@ static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void
{
DEFiRet;
rsCStrObj *pStrB;
- uchar *p;
uchar *pNewVal;
- assert(pp != NULL);
- assert(*pp != NULL);
-
- if((pStrB = rsCStrConstruct()) == NULL)
- return RS_RET_OUT_OF_MEMORY;
-
- /* parse out the word */
- p = *pp;
-
- while(*p && !isspace((int) *p)) {
- CHKiRet(rsCStrAppendChar(pStrB, *p++));
- }
- CHKiRet(rsCStrFinish(pStrB));
+ ASSERT(pp != NULL);
+ ASSERT(*pp != NULL);
+ CHKiRet(getWord(pp, &pStrB));
CHKiRet(rsCStrConvSzStrAndDestruct(pStrB, &pNewVal, 0));
pStrB = NULL;
@@ -486,7 +508,6 @@ static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void
CHKiRet(pSetHdlr(pVal, pNewVal));
}
- *pp = p;
skipWhiteSpace(pp); /* skip over any whitespace */
finalize_it:
@@ -499,6 +520,66 @@ finalize_it:
}
+/* parse a syslog name from the string. This is the generic code that is
+ * called by the facility/severity functions. Note that we do not check the
+ * validity of numerical values, something that should probably change over
+ * time (TODO). -- rgerhards, 2008-02-14
+ */
+static rsRetVal
+doSyslogName(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal, syslogName_t *pNameTable)
+{
+ DEFiRet;
+ rsCStrObj *pStrB;
+ int iNewVal;
+
+ ASSERT(pp != NULL);
+ ASSERT(*pp != NULL);
+
+ CHKiRet(getWord(pp, &pStrB)); /* get word */
+ iNewVal = decodeSyslogName(rsCStrGetSzStr(pStrB), pNameTable);
+
+ if(pSetHdlr == NULL) {
+ /* we should set value directly to var */
+ *((int*)pVal) = iNewVal; /* set new one */
+ } else {
+ /* we set value via a set function */
+ CHKiRet(pSetHdlr(pVal, iNewVal));
+ }
+
+ skipWhiteSpace(pp); /* skip over any whitespace */
+
+finalize_it:
+ if(pStrB != NULL)
+ rsCStrDestruct(pStrB);
+
+ RETiRet;
+}
+
+
+/* Implements the facility syntax.
+ * rgerhards, 2008-02-14
+ */
+static rsRetVal
+doFacility(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal)
+{
+ DEFiRet;
+ iRet = doSyslogName(pp, pSetHdlr, pVal, syslogFacNames);
+ RETiRet;
+}
+
+
+/* Implements the severity syntax.
+ * rgerhards, 2008-02-14
+ */
+static rsRetVal
+doSeverity(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal)
+{
+ DEFiRet;
+ iRet = doSyslogName(pp, pSetHdlr, pVal, syslogPriNames);
+ RETiRet;
+}
+
+
/* --------------- END functions for handling canned syntaxes --------------- */
/* destructor for cslCmdHdlr
@@ -507,7 +588,7 @@ finalize_it:
*/
static rsRetVal cslchDestruct(void *pThis)
{
- assert(pThis != NULL);
+ ASSERT(pThis != NULL);
free(pThis);
return RS_RET_OK;
@@ -607,6 +688,12 @@ static rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine)
case eCmdHdlrGetChar:
pHdlr = doGetChar;
break;
+ case eCmdHdlrFacility:
+ pHdlr = doFacility;
+ break;
+ case eCmdHdlrSeverity:
+ pHdlr = doSeverity;
+ break;
case eCmdHdlrGetWord:
pHdlr = doGetWord;
break;
@@ -892,6 +979,5 @@ void dbgPrintCfSysLineHandlers(void)
ENDfunc
}
-/*
- * vi:set ai:
+/* vim:set ai:
*/
diff --git a/cfsysline.h b/cfsysline.h
index 2aa54595..2eec18ab 100644
--- a/cfsysline.h
+++ b/cfsysline.h
@@ -37,6 +37,8 @@ typedef enum cslCmdHdlrType {
eCmdHdlrInt,
eCmdHdlrSize,
eCmdHdlrGetChar,
+ eCmdHdlrFacility,
+ eCmdHdlrSeverity,
eCmdHdlrGetWord
} ecslCmdHdrlType;
diff --git a/doc/imfile.html b/doc/imfile.html
index 15ace7c1..3cc8308d 100644
--- a/doc/imfile.html
+++ b/doc/imfile.html
@@ -54,6 +54,16 @@ $WorkDirectory). Be careful to use unique names for different files
being monitored. If there are duplicates, all sorts of "interesting"
things may happen. Rsyslog currently does not check if a name is
specified multiple times.</li>
+<li><span style="font-weight: bold;">$InputFileFacility
+facility</span><br>
+The syslog facility to be assigned to lines read. Can be specified in
+textual form (e.g. "local0", "local1", ...) or as numbers (e.g. 128 for
+"local0"). Textual form is suggested. <span style="font-weight: bold;">Default</span> &nbsp;is "local0".<span style="font-weight: bold;"></span></li>
+<li><span style="font-weight: bold;">$InputFileSeverity</span><br>
+The
+syslog severity to be assigned to lines read. Can be specified in
+textual form (e.g. "info", "warning", ...) or as numbers (e.g. 4 for
+"info"). Textual form is suggested. <span style="font-weight: bold;">Default</span> is "notice".</li>
<li><span style="font-weight: bold;">$InputRunFileMonitor</span><br>
This <span style="font-weight: bold;">activates</span>
the current monitor. It has no parameters. If you forget this
@@ -61,7 +71,8 @@ directive, no file monitoring will take place.</li>
<li><span style="font-weight: bold;">$InputFilePollInterval
seconds</span><br>
This is a global setting. It specifies how often files are to be polled
-for new data. The time specified is in seconds. The <span style="font-weight: bold;">default value</span> is 10 seconds. Please note that future
+for new data. The time specified is in seconds. The <span style="font-weight: bold;">default value</span> is 10
+seconds. Please note that future
releases of imfile may support per-file polling intervals, but
currently this is not the case. If multiple $InputFilePollInterval
statements are present in rsyslog.conf, only the last one is used.<br>
@@ -83,7 +94,9 @@ the source needs to be patched. See define MAX_INPUT_FILES in imfile.c
<p>The following sample monitors two files. If you need just one,
remove the second one. If you need more, add them according to the
sample ;). This code must be placed in /etc/rsyslog.conf (or wherever
-your distro puts rsyslog's config files).<br>
+your distro puts rsyslog's config files). Note that only commands
+actually needed need to be specified. The second file uses less
+commands and uses defaults instead.<br>
</p>
<textarea rows="15" cols="60">$ModLoad imfile.so #
needs to be done just once
@@ -91,6 +104,8 @@ needs to be done just once
$InputFileName /path/to/file1
$InputFileTag tag1:
$InputFileStateFile stat-file1
+$InputFileSeverity error
+$InputFileFacility local7
$InputRunFileMonitor
# File 2
$InputFileName /path/to/file2
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c
index 46d8af51..47df37f3 100644
--- a/plugins/imfile/imfile.c
+++ b/plugins/imfile/imfile.c
@@ -62,8 +62,8 @@ 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 iFacility;
-static int iSeverity;
+static int iFacility = 128; /* local0 */
+static int iSeverity = 5; /* notice, as of rfc 3164 */
static int iFilPtr = 0; /* number of files to be monitored; pointer to next free spot during config */
#define MAX_INPUT_FILES 100
@@ -90,8 +90,8 @@ static rsRetVal enqLine(fileInfo_t *pInfo, rsCStrObj *cstrLine)
MsgSetMSG(pMsg, (char*)rsCStrGetSzStr(cstrLine));
MsgSetHOSTNAME(pMsg, LocalHostName);
MsgSetTAG(pMsg, (char*)pInfo->pszTag);
- pMsg->iFacility = pInfo->iFacility;
- pMsg->iSeverity = pInfo->iSeverity;
+ pMsg->iFacility = LOG_FAC(pInfo->iFacility);
+ pMsg->iSeverity = LOG_PRI(pInfo->iSeverity);
pMsg->bParseHOSTNAME = 0;
getCurrTime(&(pMsg->tTIMESTAMP)); /* use the current time! */
CHKiRet(submitMsg(pMsg));
@@ -394,7 +394,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
/* set defaults... */
iPollInterval = 10;
- iFacility = 16; /* local0, as of RFC 3164 */
+ iFacility = 128; /* local0 */
iSeverity = 5; /* notice, as of rfc 3164 */
RETiRet;
@@ -438,6 +438,8 @@ static rsRetVal addMonitor(void __attribute__((unused)) *pVal, uchar __attribute
ABORT_FINALIZE(RS_RET_OUT_OF_DESRIPTORS);
}
+ CHKiRet(resetConfigVariables((uchar*) "dummy", (void*) pThis)); /* values are both dummies */
+
finalize_it:
if(iRet == RS_RET_OK)
++iFilPtr; /* we got a new file to monitor */
@@ -464,10 +466,9 @@ CODEmodInit_QueryRegCFSLineHdlr
NULL, &pszFileTag, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilestatefile", 0, eCmdHdlrGetWord,
NULL, &pszStateFile, STD_LOADABLE_MODULE_ID));
- /* use numerical values as of RFC 3164 for the time being... */
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfileseverity", 0, eCmdHdlrInt,
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfileseverity", 0, eCmdHdlrSeverity,
NULL, &iSeverity, STD_LOADABLE_MODULE_ID));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilefacility", 0, eCmdHdlrInt,
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilefacility", 0, eCmdHdlrFacility,
NULL, &iFacility, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilepollinterval", 0, eCmdHdlrInt,
NULL, &iPollInterval, STD_LOADABLE_MODULE_ID));
@@ -477,6 +478,5 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
ENDmodInit
-/*
- * vim:set ai:
+/* vim:set ai:
*/
diff --git a/srUtils.c b/srUtils.c
index 312c8b81..652ae5c8 100755
--- a/srUtils.c
+++ b/srUtils.c
@@ -50,7 +50,7 @@
/* here we host some syslog specific names. There currently is no better place
* to do it, but over here is also not ideal... -- rgerhards, 2008-02-14
*/
-struct code syslogPriNames[] = {
+syslogName_t syslogPriNames[] = {
{"alert", LOG_ALERT},
{"crit", LOG_CRIT},
{"debug", LOG_DEBUG},
@@ -67,7 +67,7 @@ struct code syslogPriNames[] = {
{NULL, -1}
};
-struct code syslogFacNames[] = {
+syslogName_t syslogFacNames[] = {
{"auth", LOG_AUTH},
{"authpriv", LOG_AUTHPRIV},
{"cron", LOG_CRON},
@@ -470,9 +470,9 @@ char *rs_strerror_r(int errnum, char *buf, size_t buflen) {
/* Decode a symbolic name to a numeric value
*/
-int decodeSyslogName(uchar *name, struct code *codetab)
+int decodeSyslogName(uchar *name, syslogName_t *codetab)
{
- register struct code *c;
+ register syslogName_t *c;
register uchar *p;
uchar buf[80];
diff --git a/srUtils.h b/srUtils.h
index 3a66dc22..6540b15a 100755
--- a/srUtils.h
+++ b/srUtils.h
@@ -34,13 +34,13 @@
#define TABLE_ALLPRI 0xFF /* Value to indicate all priorities in f_pmask */
#define LOG_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) /* mark "facility" */
-struct code {
+typedef struct syslogName_s {
char *c_name;
int c_val;
-};
+} syslogName_t;
-extern struct code syslogPriNames[];
-extern struct code syslogFacNames[];
+extern syslogName_t syslogPriNames[];
+extern syslogName_t syslogFacNames[];
/**
* A reimplementation of itoa(), as this is not available
@@ -86,7 +86,7 @@ long timeoutVal(struct timespec *pt);
void mutexCancelCleanup(void *arg);
void srSleep(int iSeconds, int iuSeconds);
char *rs_strerror_r(int errnum, char *buf, size_t buflen);
-int decodeSyslogName(uchar *name, struct code *codetab);
+int decodeSyslogName(uchar *name, syslogName_t *codetab);
/* mutex operations */
/* some macros to cancel-safe lock a mutex (it will automatically be released
diff --git a/syslogd.c b/syslogd.c
index e54d0ff5..71378f6e 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -102,7 +102,6 @@
* once the situation has been resolved.
*/
#define DEFUPRI (LOG_USER|LOG_NOTICE)
-#define DEFSPRI (LOG_KERN|LOG_CRIT)
#define TIMERINTVL 30 /* interval for checking flush, mark */
#define CONT_LINE 1 /* Allow continuation lines */