Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: RSyslog: users

add dynimic filename support for outchannel

 

 

RSyslog users RSS feed   Index | Next | Previous | View Threaded


marywangran at 126

Aug 16, 2012, 1:47 AM

Post #1 of 1 (164 views)
Permalink
add dynimic filename support for outchannel

From e82f42dc9eb78fd2132b875c8718151ab9218acf Mon Sep 17 00:00:00 2001
From: zhaoya <marywangran [at] 126>
Date: Tue, 7 Aug 2012 08:07:12 -0700
Subject: [PATCH] add dynimic filename support for outchannel

The URL:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477351
present a FALSE BUG! Up to the newest version,rsyslogd's "outchannel [still]
doesn't get variable from template"!
---
runtime/stream.c | 13 +++++++++-
tools/omfile.c | 63 +++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/runtime/stream.c b/runtime/stream.c
index bb1a0a4..49e7ec4 100644
--- a/runtime/stream.c
+++ b/runtime/stream.c
@@ -96,6 +96,8 @@ static rsRetVal
resolveFileSizeLimit(strm_t *pThis, uchar *pszCurrFName)
{
uchar *pParams;
+ uchar params[512] = {0};
+ int len;
uchar *pCmd;
uchar *p;
off_t actualFileSize;
@@ -121,15 +123,22 @@ resolveFileSizeLimit(strm_t *pThis, uchar *pszCurrFName)
if(*p == ' ') {
*p = '\0'; /* pretend string-end */
pParams = p+1;
- } else
+ len = strlen(pParams);
+ strcpy(params, pParams);
+ } else {
pParams = NULL;
+ len = 0;
+ }
+
+ //Æ´½Ó¶¯Ì¬ÎļþµÄÃû×Ö
+ strcpy(params+len, pszCurrFName);

/* the execProg() below is probably not great, but at least is is
* fairly secure now. Once we change the way file size limits are
* handled, we should also revisit how this command is run (and
* with which parameters). rgerhards, 2007-07-20
*/
- execProg(pCmd, 1, pParams);
+ execProg(pCmd, 1, params);

free(pCmd);

diff --git a/tools/omfile.c b/tools/omfile.c
index 1a36343..a877555 100644
--- a/tools/omfile.c
+++ b/tools/omfile.c
@@ -333,6 +333,32 @@ rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal)
RETiRet;
}

+/* Get a FileName from a outchannel
+ */
+rsRetVal channParseFileName(uchar* p, uchar *szBuf)
+{
+ DEFiRet;
+ size_t i;
+ char szChn[128];
+ struct outchannel *pOch;
+
+ ++p; /* skip '$' */
+ i = 0;
+ /* get outchannel name */
+ while(*p && *p != ';' && *p != ' ' &&
+ i < sizeof(szChn) / sizeof(char)) {
+ szChn[i++] = *p++;
+ }
+ szChn[i] = '\0';
+ pOch = ochFind(szChn, i);
+ if (pOch != NULL &&
+ pOch->pszFileTemplate != NULL) {
+ strcpy(szBuf, pOch->pszFileTemplate);
+ }
+
+finalize_it:
+ RETiRet;
+}

/* Helper to cfline(). Parses a output channel name up until the first
* comma and then looks for the template specifier. Tries
@@ -1004,19 +1030,32 @@ CODESTARTparseSelectorAct
pData->iSizeLimit = 0; /* default value, use outchannels to configure! */

switch(*p) {
- case '$':
- CODE_STD_STRING_REQUESTparseSelectorAct(1)
- /* rgerhards 2005-06-21: this is a special setting for output-channel
- * definitions. In the long term, this setting will probably replace
- * anything else, but for the time being we must co-exist with the
- * traditional mode lines.
- * rgerhards, 2007-07-24: output-channels will go away. We keep them
- * for compatibility reasons, but seems to have been a bad idea.
- */
- CHKiRet(cflineParseOutchannel(pData, p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS));
- pData->bDynamicName = 0;
+ case '$': {
+ uchar szFileName[128] = {0};
+ channParseFileName(p, szFileName);
+ if (szFileName[0] == '$') {
+ CODE_STD_STRING_REQUESTparseSelectorAct(2)
+ CHKiRet(cflineParseOutchannel(pData, p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS));
+ strcpy(pData->f_fname, "");
+ CHKiRet(OMSRsetEntry(*ppOMSR, 1, ustrdup(&szFileName[1]), OMSR_NO_RQD_TPL_OPTS));
+ pData->bDynamicName = 1;
+ pData->iCurrElt = -1; /* no current element */
+ CHKmalloc(pData->dynCache = (dynaFileCacheEntry**)
+ calloc(iDynaFileCacheSize, sizeof(dynaFileCacheEntry*)));
+ } else {
+ CODE_STD_STRING_REQUESTparseSelectorAct(1)
+ /* rgerhards 2005-06-21: this is a special setting for output-channel
+ * definitions. In the long term, this setting will probably replace
+ * anything else, but for the time being we must co-exist with the
+ * traditional mode lines.
+ * rgerhards, 2007-07-24: output-channels will go away. We keep them
+ * for compatibility reasons, but seems to have been a bad idea.
+ */
+ CHKiRet(cflineParseOutchannel(pData, p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS));
+ pData->bDynamicName = 0;
+ }
break;
-
+ }
case '?': /* This is much like a regular file handle, but we need to obtain
* a template name. rgerhards, 2007-07-03
*/
--
1.7.4.1

RSyslog users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.