diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-09-26 12:48:57 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-09-26 12:48:57 +0200 |
commit | f2528ec101eb660560c7ec327d440cbb17f04f14 (patch) | |
tree | 05083efcd96dedc9387579caa17c81b8b78592c6 /tools/omfile.c | |
parent | ceb336f0398e37ab51b4b54a14fa394d53ccdf3f (diff) | |
parent | 0c7604dc27119122a3022c7bf094ffb5f8d59e6d (diff) | |
download | rsyslog-f2528ec101eb660560c7ec327d440cbb17f04f14.tar.gz rsyslog-f2528ec101eb660560c7ec327d440cbb17f04f14.tar.xz rsyslog-f2528ec101eb660560c7ec327d440cbb17f04f14.zip |
Merge branch 'v5-devel'
Conflicts:
ChangeLog
configure.ac
doc/manual.html
runtime/conf.c
tools/omfile.c
tools/omusrmsg.c
Diffstat (limited to 'tools/omfile.c')
-rw-r--r-- | tools/omfile.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/tools/omfile.c b/tools/omfile.c index 3cc3a7f9..e68bddd4 100644 --- a/tools/omfile.c +++ b/tools/omfile.c @@ -427,6 +427,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) { @@ -497,8 +498,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; } @@ -576,7 +579,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; @@ -604,8 +607,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. @@ -613,7 +616,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); } @@ -683,10 +686,6 @@ writeFile(uchar **ppString, unsigned iMsgOpts, instanceData *pData) CHKiRet(doWrite(pData, ppString[0], strlen(CHAR_CONVERT(ppString[0])))); finalize_it: - if(iRet != RS_RET_OK) { - - iRet = RS_RET_SUSPENDED; - } RETiRet; } @@ -719,7 +718,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: |