~ubuntu-branches/debian/sid/rsyslog/sid

« back to all changes in this revision

Viewing changes to tools/omfile.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl, Michael Biebl, Daniel Pocock
  • Date: 2014-03-11 19:52:49 UTC
  • mfrom: (1.1.37)
  • Revision ID: package-import@ubuntu.com-20140311195249-phbsh9be8lebawti
Tags: 7.4.8-1
[ Michael Biebl ]
* New upstream release.
* Update Build-Depends:
  - Bump libestr-dev to (>= 0.1.9).
  - Tighten liblognorm-dev to (<< 1.0.0).
  - Replace libjson0-dev with libjson-c-dev, we no longer need the
    transitional package.
* Bump Standards-Version to 3.9.5. No further changes.

[ Daniel Pocock ]
* Make template parameter not mandatory in mongodb output plugin. Patch
  cherry-picked from upstream Git. (Closes: #740869, #721277)
* Ensure JSON templates are NUL terminated. Patch cherry-picked from
  upstream Git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
 
134
134
 
135
135
typedef struct _instanceData {
136
 
        uchar   *f_fname;       /* file or template name (display only) */
 
136
        uchar   *fname; /* file or template name (display only) */
137
137
        uchar   *tplName;       /* name of assigned template */
138
138
        strm_t  *pStrm;         /* our output stream */
139
139
        char    bDynamicName;   /* 0 - static name, 1 - dynamic name (with properties) */
287
287
        if(pData->bDynamicName) {
288
288
                dbgprintf("[dynamic]\n");
289
289
        } else { /* regular file */
290
 
                dbgprintf("%s%s\n", pData->f_fname,
 
290
                dbgprintf("%s%s\n", pData->fname,
291
291
                          (pData->pStrm == NULL) ? " (closed)" : "");
292
292
        }
293
293
 
294
 
        dbgprintf("\ttemplate='%s'\n", pData->f_fname);
 
294
        dbgprintf("\ttemplate='%s'\n", pData->fname);
295
295
        dbgprintf("\tuse async writer=%d\n", pData->bUseAsyncWriter);
296
296
        dbgprintf("\tflush on TX end=%d\n", pData->bFlushOnTXEnd);
297
297
        dbgprintf("\tflush interval=%d\n", pData->iFlushInterval);
411
411
        }
412
412
 
413
413
        /* OK, we finally got a correct template. So let's use it... */
414
 
        pData->f_fname = ustrdup(pOch->pszFileTemplate);
 
414
        pData->fname = ustrdup(pOch->pszFileTemplate);
415
415
        pData->iSizeLimit = pOch->uSizeLimit;
416
416
        /* WARNING: It is dangerous "just" to pass the pointer. As we
417
417
         * never rebuild the output channel description, this is acceptable here.
796
796
                CHKiRet(prepareDynFile(pData, ppString[1], iMsgOpts));
797
797
        } else { /* "regular", non-dynafile */
798
798
                if(pData->pStrm == NULL) {
799
 
                        CHKiRet(prepareFile(pData, pData->f_fname));
 
799
                        CHKiRet(prepareFile(pData, pData->fname));
800
800
                        if(pData->pStrm == NULL) {
801
 
                                errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could no open output file '%s'", pData->f_fname);
 
801
                                errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could no open output file '%s'", pData->fname);
802
802
                        }
803
803
                }
804
804
        }
885
885
BEGINfreeInstance
886
886
CODESTARTfreeInstance
887
887
        free(pData->tplName);
888
 
        free(pData->f_fname);
 
888
        free(pData->fname);
889
889
        if(pData->bDynamicName) {
890
890
                dynaFileFreeCache(pData);
891
891
        } else if(pData->pStrm != NULL)
935
935
BEGINdoAction
936
936
CODESTARTdoAction
937
937
        DBGPRINTF("file to log to: %s\n",
938
 
                  (pData->bDynamicName) ? ppString[1] : pData->f_fname);
 
938
                  (pData->bDynamicName) ? ppString[1] : pData->fname);
939
939
        DBGPRINTF("omfile: start of data: '%.128s'\n", ppString[0]);
940
940
        STATSCOUNTER_INC(pData->ctrRequests, pData->mutCtrRequests);
941
941
        CHKiRet(writeFile(ppString, iMsgOpts, pData));
951
951
static inline void
952
952
setInstParamDefaults(instanceData *pData)
953
953
{
954
 
        pData->f_fname = NULL;
 
954
        pData->fname = NULL;
955
955
        pData->tplName = NULL;
956
956
        pData->fileUID = -1;
957
957
        pData->fileGID = -1;
987
987
        }
988
988
 
989
989
        /* support statistics gathering */
990
 
        snprintf((char*)ctrName, sizeof(ctrName), "dynafile cache %s", pData->f_fname);
 
990
        snprintf((char*)ctrName, sizeof(ctrName), "dynafile cache %s", pData->fname);
991
991
        ctrName[sizeof(ctrName)-1] = '\0'; /* be on the save side */
992
992
        CHKiRet(statsobj.Construct(&(pData->stats)));
993
993
        CHKiRet(statsobj.SetName(pData->stats, ctrName));
1156
1156
                } else if(!strcmp(actpblk.descr[i].name, "createdirs")) {
1157
1157
                        pData->bCreateDirs = (int) pvals[i].val.d.n;
1158
1158
                } else if(!strcmp(actpblk.descr[i].name, "file")) {
1159
 
                        pData->f_fname = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
 
1159
                        pData->fname = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
1160
1160
                        CODE_STD_STRING_REQUESTnewActInst(1)
1161
1161
                        pData->bDynamicName = 0;
1162
1162
                } else if(!strcmp(actpblk.descr[i].name, "dynafile")) {
1163
 
                        pData->f_fname = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
 
1163
                        pData->fname = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
1164
1164
                        CODE_STD_STRING_REQUESTnewActInst(2)
1165
1165
                        pData->bDynamicName = 1;
1166
1166
                } else if(!strcmp(actpblk.descr[i].name, "template")) {
1175
1175
                }
1176
1176
        }
1177
1177
 
1178
 
        if(pData->f_fname == NULL) {
 
1178
        if(pData->fname == NULL) {
1179
1179
                errmsg.LogError(0, RS_RET_MISSING_CNFPARAMS, "omfile: either the \"file\" or "
1180
1180
                                "\"dynfile\" parameter must be given");
1181
1181
                ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
1196
1196
                /* "filename" is actually a template name, we need this as string 1. So let's add it
1197
1197
                 * to the pOMSR. -- rgerhards, 2007-07-27
1198
1198
                 */
1199
 
                CHKiRet(OMSRsetEntry(*ppOMSR, 1, ustrdup(pData->f_fname), OMSR_NO_RQD_TPL_OPTS));
 
1199
                CHKiRet(OMSRsetEntry(*ppOMSR, 1, ustrdup(pData->fname), OMSR_NO_RQD_TPL_OPTS));
1200
1200
                // TODO: create unified code for this (legacy+v6 system)
1201
1201
                /* we now allocate the cache table */
1202
1202
                CHKmalloc(pData->dynCache = (dynaFileCacheEntry**)
1255
1255
                CODE_STD_STRING_REQUESTparseSelectorAct(2)
1256
1256
                ++p; /* eat '?' */
1257
1257
                CHKiRet(cflineParseFileName(p, fname, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, getDfltTpl()));
1258
 
                pData->f_fname = ustrdup(fname);
 
1258
                pData->fname = ustrdup(fname);
1259
1259
                pData->bDynamicName = 1;
1260
1260
                pData->iCurrElt = -1;             /* no current element */
1261
1261
                /* "filename" is actually a template name, we need this as string 1. So let's add it
1262
1262
                 * to the pOMSR. -- rgerhards, 2007-07-27
1263
1263
                 */
1264
 
                CHKiRet(OMSRsetEntry(*ppOMSR, 1, ustrdup(pData->f_fname), OMSR_NO_RQD_TPL_OPTS));
 
1264
                CHKiRet(OMSRsetEntry(*ppOMSR, 1, ustrdup(pData->fname), OMSR_NO_RQD_TPL_OPTS));
1265
1265
                /* we now allocate the cache table */
1266
1266
                CHKmalloc(pData->dynCache = (dynaFileCacheEntry**)
1267
1267
                                calloc(cs.iDynaFileCacheSize, sizeof(dynaFileCacheEntry*)));
1271
1271
        case '.':
1272
1272
                CODE_STD_STRING_REQUESTparseSelectorAct(1)
1273
1273
                CHKiRet(cflineParseFileName(p, fname, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, getDfltTpl()));
1274
 
                pData->f_fname = ustrdup(fname);
 
1274
                pData->fname = ustrdup(fname);
1275
1275
                pData->bDynamicName = 0;
1276
1276
                break;
1277
1277
        default: