summaryrefslogtreecommitdiff
path: root/tools/omfile.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-10-21 17:03:33 +0200
committerMichael Biebl <biebl@debian.org>2011-10-21 17:03:33 +0200
commita7a3afdd81c8809fbc4927b360e1cb59e2e16b2e (patch)
tree87efee7c0a74d351e4d88e52a5b84fbd4b3b191d /tools/omfile.c
parentae82a633a4d42dfdc942d8f0f4f5e6470f13797e (diff)
downloadrsyslog-a7a3afdd81c8809fbc4927b360e1cb59e2e16b2e.tar.gz
Imported Upstream version 5.8.6upstream/5.8.6
Diffstat (limited to 'tools/omfile.c')
-rw-r--r--tools/omfile.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/tools/omfile.c b/tools/omfile.c
index 150848e..c49a6cd 100644
--- a/tools/omfile.c
+++ b/tools/omfile.c
@@ -388,6 +388,7 @@ prepareFile(instanceData *pData, uchar *newFileName)
int fd;
DEFiRet;
+ pData->pStrm = NULL;
if(access((char*)newFileName, F_OK) == 0) {
if(pData->bForceChown) {
/* Try to fix wrong ownership set by someone else. Note that this code
@@ -473,6 +474,11 @@ prepareFile(instanceData *pData, uchar *newFileName)
CHKiRet(strm.ConstructFinalize(pData->pStrm));
finalize_it:
+ if(iRet != RS_RET_OK) {
+ if(pData->pStrm != NULL) {
+ strm.Destruct(&pData->pStrm);
+ }
+ }
RETiRet;
}
@@ -549,7 +555,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;
@@ -577,16 +583,17 @@ 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.
*/
if(iMsgOpts & INTERNAL_MSG) {
- DBGPRINTF("Could not open dynaFile, discarding message\n");
+ DBGPRINTF("Could not open dynaFile '%s', state %d, discarding message\n",
+ newFileName, localRet);
} else {
- errmsg.LogError(0, NO_ERRCODE, "Could not open dynamic file '%s' - discarding message", newFileName);
+ errmsg.LogError(0, localRet, "Could not open dynamic file '%s' [state %d] - discarding message", newFileName, localRet);
}
ABORT_FINALIZE(localRet);
}
@@ -657,8 +664,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;
}
@@ -691,7 +696,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:
@@ -824,7 +830,7 @@ CODESTARTparseSelectorAct
if(pData->pStrm == NULL) {
DBGPRINTF("Error opening log file: %s\n", pData->f_fname);
- errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could no open output file '%s'", pData->f_fname);
+ errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could not open output file '%s'", pData->f_fname);
}
}
CODE_STD_FINALIZERparseSelectorAct