1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-09-16 09:06:18 +02:00

Fix error after log file open failure when processing should continue.

The C code was warning on failure and continuing but the Perl logging code was never updated with the same feature.

Rather than add the feature to Perl, just disable file logging if the log file cannot be opened.  Log files are always opened by C first, so this will eliminate the error in Perl.

Reported by vthriller.
This commit is contained in:
David Steele
2018-10-25 14:58:25 +01:00
parent d301720c58
commit 03b9db9aa2
10 changed files with 59 additions and 13 deletions

View File

@@ -14,6 +14,16 @@
<release-list>
<release date="XXXX-XX-XX" version="2.07dev" title="UNDER DEVELOPMENT">
<release-core-list>
<release-bug-list>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="vthriller"/>
</release-item-contributor-list>
<p>Fix error after log file open failure when processing should continue.</p>
</release-item>
</release-bug-list>
<release-development-list>
<release-item>
<release-item-contributor-list>
@@ -5727,6 +5737,11 @@
<contributor-id type="github">vitabaks</contributor-id>
</contributor>
<contributor id="vthriller">
<contributor-name-display>vthriller</contributor-name-display>
<contributor-id type="github">vthriller</contributor-id>
</contributor>
<contributor id="william.cox">
<contributor-name-display>William Cox</contributor-name-display>
<contributor-id type="github">mydimension</contributor-id>

View File

@@ -239,9 +239,9 @@ cmdArchiveGet(void)
cfgLoadLogSetting();
// Open the log file
logFileSet(
strPtr(strNewFmt("%s/%s-%s-async.log", strPtr(cfgOptionStr(cfgOptLogPath)),
strPtr(cfgOptionStr(cfgOptStanza)), cfgCommandName(cfgCommand()))));
cfgLoadLogFile(
strNewFmt("%s/%s-%s-async.log", strPtr(cfgOptionStr(cfgOptLogPath)),
strPtr(cfgOptionStr(cfgOptStanza)), cfgCommandName(cfgCommand())));
// Log command info since we are starting a new log
cmdBegin(true);

View File

@@ -68,9 +68,9 @@ cmdArchivePush(void)
cfgLoadLogSetting();
// Open the log file
logFileSet(
strPtr(strNewFmt("%s/%s-%s-async.log", strPtr(cfgOptionStr(cfgOptLogPath)),
strPtr(cfgOptionStr(cfgOptStanza)), cfgCommandName(cfgCommand()))));
cfgLoadLogFile(
strNewFmt("%s/%s-%s-async.log", strPtr(cfgOptionStr(cfgOptLogPath)),
strPtr(cfgOptionStr(cfgOptStanza)), cfgCommandName(cfgCommand())));
// Log command info since we are starting a new log
cmdBegin(true);

View File

@@ -126,8 +126,10 @@ logInit(LogLevel logLevelStdOutParam, LogLevel logLevelStdErrParam, LogLevel log
/***********************************************************************************************************************************
Set the log file
Returns true if file logging is off or the log file was successfully opened, false if the log file could not be opened.
***********************************************************************************************************************************/
void
bool
logFileSet(const char *logFile)
{
FUNCTION_TEST_BEGIN();
@@ -144,6 +146,8 @@ logFileSet(const char *logFile)
}
// Only open the file if there is a chance to log something
bool result = true;
if (logLevelFile != logLevelOff)
{
// Open the file and handle errors
@@ -153,13 +157,14 @@ logFileSet(const char *logFile)
{
int errNo = errno;
LOG_WARN("unable to open log file '%s': %s\nNOTE: process will continue without log file.", logFile, strerror(errNo));
result = false;
};
// Output the banner on first log message
logFileBanner = false;
}
FUNCTION_TEST_RESULT_VOID();
FUNCTION_TEST_RESULT(BOOL, result);
}
/***********************************************************************************************************************************

View File

@@ -19,7 +19,7 @@ Max size allowed for a single log message including header
Functions
***********************************************************************************************************************************/
void logInit(LogLevel logLevelStdOut, LogLevel logLevelStdErr, LogLevel logLevelFile, bool logTimestamp);
void logFileSet(const char *logFile);
bool logFileSet(const char *logFile);
bool logWill(LogLevel logLevel);

View File

@@ -198,6 +198,17 @@ cfgLoadUpdateOption(void)
FUNCTION_DEBUG_RESULT_VOID();
}
/***********************************************************************************************************************************
Attempt to set the log file and turn file logging off if the file cannot be opened. This is so the Perl code won't attempt to open
the file again and error out.
***********************************************************************************************************************************/
void
cfgLoadLogFile(const String *logFile)
{
if (!logFileSet(strPtr(logFile)))
cfgOptionSet(cfgOptLogLevelFile, cfgSourceParam, varNewStrZ("off"));
}
/***********************************************************************************************************************************
Load the configuration
***********************************************************************************************************************************/
@@ -248,7 +259,7 @@ cfgLoad(unsigned int argListSize, const char *argList[])
strCatFmt(logFile, "%s.log", cfgCommandName(cfgCommand()));
// Set the log file name
logFileSet(strPtr(logFile));
cfgLoadLogFile(logFile);
}
// Begin the command

View File

@@ -6,11 +6,14 @@ Configuration Load
#include <sys/types.h>
#include "common/type/string.h"
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
void cfgLoad(unsigned int argListSize, const char *argList[]);
void cfgLoadLogSetting(void);
void cfgLoadLogFile(const String *logFile);
void cfgLoadUpdateOption(void);
#endif

View File

@@ -406,7 +406,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: load
total: 3
total: 4
coverage:
config/load: full

View File

@@ -239,7 +239,7 @@ testRun(void)
TEST_RESULT_STR(logBuffer, "P00 TRACE: test::test_func: message\n", " check log");
// Reopen the log file
logFileSet(fileFile);
TEST_RESULT_BOOL(logFileSet(fileFile), true, "open valid file");
logBuffer[0] = 0;
TEST_RESULT_VOID(
@@ -250,7 +250,7 @@ testRun(void)
TEST_RESULT_STR(logBuffer, "P00 INFO: info message 2\n", " check log");
// Reopen invalid log file
logFileSet("/" BOGUS_STR);
TEST_RESULT_BOOL(logFileSet("/" BOGUS_STR), false, "attempt to open bogus file");
// Check stdout
testLogResult(

View File

@@ -229,6 +229,18 @@ testRun(void)
" to the maximum.");
}
// *****************************************************************************************************************************
if (testBegin("cfgLoadLogFile()"))
{
cfgInit();
cfgOptionValidSet(cfgOptLogLevelFile, true);
cfgOptionSet(cfgOptLogLevelFile, cfgSourceParam, varNewStrZ("detail"));
// On the error case is tested here, success is tested in cfgLoad()
TEST_RESULT_VOID(cfgLoadLogFile(strNew("/BOGUS")), "attempt to open bogus log file");
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptLogLevelFile)), "off", "log-level-file should now be off");
}
// *****************************************************************************************************************************
if (testBegin("cfgLoad()"))
{