diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-09-26 11:58:20 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-09-26 11:58:20 +0200 |
commit | 0c7604dc27119122a3022c7bf094ffb5f8d59e6d (patch) | |
tree | 370ad5d009cb301e5ea4757f8ac34a7179d28448 /tools/omfile.c | |
parent | b1e21fcb4b072b1780ce093e890450fe3a059de8 (diff) | |
parent | b26387e6b28630b8e5e3582039141ebf1c7455e3 (diff) | |
download | rsyslog-0c7604dc27119122a3022c7bf094ffb5f8d59e6d.tar.gz rsyslog-0c7604dc27119122a3022c7bf094ffb5f8d59e6d.tar.xz rsyslog-0c7604dc27119122a3022c7bf094ffb5f8d59e6d.zip |
Merge branch 'v5-stable' into v5-devel
Conflicts:
ChangeLog
configure.ac
doc/manual.html
runtime/rsyslog.h
tools/omfile.c
tools/ompipe.c
Diffstat (limited to 'tools/omfile.c')
-rw-r--r-- | tools/omfile.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/tools/omfile.c b/tools/omfile.c index fa2fd156..dcb09faf 100644 --- a/tools/omfile.c +++ b/tools/omfile.c @@ -235,7 +235,8 @@ rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal) } -rsRetVal goneAway(void __attribute__((unused)) *pVal, int iNewVal) +rsRetVal goneAway(void __attribute__((unused)) *pVal, + int __attribute__((unused)) iNewVal) { errmsg.LogError(0, RS_RET_ERR, "directive $omfileForceChown is no longer supported"); return RS_RET_ERR; @@ -391,6 +392,7 @@ prepareFile(instanceData *pData, uchar *newFileName) int fd; DEFiRet; + pData->pStrm = NULL; if(access((char*)newFileName, F_OK) != 0) { /* file does not exist, create it (and eventually parent directories */ if(pData->bCreateDirs) { @@ -461,8 +463,10 @@ prepareFile(instanceData *pData, uchar *newFileName) CHKiRet(strm.ConstructFinalize(pData->pStrm)); finalize_it: - if(pData->pStrm == NULL) { - DBGPRINTF("Error opening log file: %s\n", pData->f_fname); + if(iRet != RS_RET_OK) { + if(pData->pStrm != NULL) { + strm.Destruct(&pData->pStrm); + } } RETiRet; } @@ -540,7 +544,7 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts) pData->iCurrElt = -1; /* similarly, we need to set the current pStrm to NULL, because otherwise, if prepareFile() fails, * we may end up using an old stream. This bug depends on how exactly prepareFile fails, - * but it* could be triggered in the common case of a failed open() system call. + * but it could be triggered in the common case of a failed open() system call. * rgerhards, 2010-03-22 */ pData->pStrm = NULL; @@ -568,8 +572,8 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts) /* Ok, we finally can open the file */ localRet = prepareFile(pData, newFileName); /* ignore exact error, we check fd below */ - /* file is either open now or an error state set */ // RG: better check localRet? - if(pData->pStrm == NULL) { + /* check if we had an error */ + if(localRet != RS_RET_OK) { /* do not report anything if the message is an internally-generated * message. Otherwise, we could run into a never-ending loop. The bad * news is that we also lose errors on startup messages, but so it is. @@ -577,7 +581,7 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts) if(iMsgOpts & INTERNAL_MSG) { DBGPRINTF("Could not open dynaFile, discarding message\n"); } else { - errmsg.LogError(0, NO_ERRCODE, "Could not open dynamic file '%s' - discarding message", newFileName); + errmsg.LogError(0, NO_ERRCODE, "Could not open dynamic file '%s' [state %d] - discarding message", newFileName, localRet); } ABORT_FINALIZE(localRet); } @@ -651,8 +655,6 @@ finalize_it: /* in v5, we shall return different states for message-caused failure (but only there!) */ if(pData->strmType == STREAMTYPE_NAMED_PIPE) iRet = RS_RET_DISABLE_ACTION; /* this is the traditional semantic -- rgerhards, 2010-01-15 */ - else - iRet = RS_RET_SUSPENDED; } RETiRet; } @@ -685,7 +687,8 @@ ENDbeginTransaction BEGINendTransaction CODESTARTendTransaction - if(pData->bFlushOnTXEnd) { + /* Note: pStrm may be NULL if there was an error opening the stream */ + if(pData->bFlushOnTXEnd && pData->pStrm != NULL) { CHKiRet(strm.Flush(pData->pStrm)); } finalize_it: |