The URL:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477351
present a FALSE BUG! Up to the newest version,rsyslogd's "outchannel 
doesn't get variable from template"! 
My testing version is 6.3.12beta.The following patch give a solution:

diff -urN rsyslog-6.3.12.orig/runtime/stream.c rsyslog-6.3.12/runtime/stream.c
--- rsyslog-6.3.12.orig/runtime/stream.c        2012-04-12 20:11:08.000000000 
+0800
+++ rsyslog-6.3.12/runtime/stream.c     2012-08-14 13:44:19.000000000 +0800
@@ -96,6 +96,8 @@
 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 @@
        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 -urN rsyslog-6.3.12.orig/tools/omfile.c rsyslog-6.3.12/tools/omfile.c
--- rsyslog-6.3.12.orig/tools/omfile.c  2012-07-02 21:04:02.000000000 +0800
+++ rsyslog-6.3.12/tools/omfile.c       2012-08-14 13:44:10.000000000 +0800
@@ -276,6 +276,32 @@
        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
@@ -884,19 +910,32 @@
        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(cs.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
                   */

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards

Reply via email to