2018-01-17 16:15:51 +02:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Common Command Routines
|
|
|
|
***********************************************************************************************************************************/
|
2018-03-12 16:55:58 +02:00
|
|
|
#include <assert.h>
|
2018-01-17 16:15:51 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "common/memContext.h"
|
|
|
|
#include "config/config.h"
|
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Begin the command
|
|
|
|
***********************************************************************************************************************************/
|
2018-02-01 01:22:25 +02:00
|
|
|
void
|
|
|
|
cmdBegin()
|
2018-01-17 16:15:51 +02:00
|
|
|
{
|
2018-03-12 16:55:58 +02:00
|
|
|
// A command must be set
|
|
|
|
assert(cfgCommand() != cfgCmdNone);
|
2018-01-17 16:15:51 +02:00
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
// This is fairly expensive log message to generate so skip it if it won't be output
|
|
|
|
if (logWill(cfgLogLevelDefault()))
|
|
|
|
{
|
|
|
|
MEM_CONTEXT_TEMP_BEGIN()
|
2018-01-17 16:15:51 +02:00
|
|
|
{
|
2018-03-12 16:55:58 +02:00
|
|
|
// Basic info on command start
|
|
|
|
String *info = strNewFmt("%s command begin %s:", cfgCommandName(cfgCommand()), PGBACKREST_VERSION);
|
2018-01-17 16:15:51 +02:00
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
// Loop though options and add the ones that are interesting
|
|
|
|
for (ConfigOption optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++)
|
2018-01-17 16:15:51 +02:00
|
|
|
{
|
2018-03-12 16:55:58 +02:00
|
|
|
// Skip the option if it is not valid
|
|
|
|
if (!cfgOptionValid(optionId))
|
|
|
|
continue;
|
2018-01-17 16:15:51 +02:00
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
// If option was negated
|
|
|
|
if (cfgOptionNegate(optionId))
|
|
|
|
strCatFmt(info, " --no-%s", cfgOptionName(optionId));
|
|
|
|
// If option was reset
|
|
|
|
else if (cfgOptionReset(optionId))
|
|
|
|
strCatFmt(info, " --reset-%s", cfgOptionName(optionId));
|
|
|
|
// Else set and not default
|
|
|
|
else if (cfgOptionSource(optionId) != cfgSourceDefault && cfgOptionTest(optionId))
|
2018-01-17 16:15:51 +02:00
|
|
|
{
|
2018-03-12 16:55:58 +02:00
|
|
|
ConfigDefineOption optionDefId = cfgOptionDefIdFromId(optionId);
|
|
|
|
|
|
|
|
// Don't show redacted options
|
2018-01-17 16:15:51 +02:00
|
|
|
if (cfgDefOptionSecure(optionDefId))
|
2018-03-12 16:55:58 +02:00
|
|
|
strCatFmt(info, " --%s=<redacted>", cfgOptionName(optionId));
|
|
|
|
// Output boolean option
|
|
|
|
else if (cfgDefOptionType(optionDefId) == cfgDefOptTypeBoolean)
|
|
|
|
strCatFmt(info, " --%s", cfgOptionName(optionId));
|
|
|
|
// Output other options
|
2018-01-17 16:15:51 +02:00
|
|
|
else
|
|
|
|
{
|
2018-03-12 16:55:58 +02:00
|
|
|
StringList *valueList = NULL;
|
|
|
|
|
|
|
|
// Generate the values of hash options
|
|
|
|
if (cfgDefOptionType(optionDefId) == cfgDefOptTypeHash)
|
|
|
|
{
|
|
|
|
valueList = strLstNew();
|
|
|
|
|
|
|
|
const KeyValue *optionKv = cfgOptionKv(optionId);
|
|
|
|
const VariantList *keyList = kvKeyList(optionKv);
|
2018-01-17 16:15:51 +02:00
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
for (unsigned int keyIdx = 0; keyIdx < varLstSize(keyList); keyIdx++)
|
|
|
|
{
|
|
|
|
strLstAdd(
|
|
|
|
valueList,
|
|
|
|
strNewFmt(
|
|
|
|
"%s=%s", strPtr(varStr(varLstGet(keyList, keyIdx))),
|
|
|
|
strPtr(varStrForce(kvGet(optionKv, varLstGet(keyList, keyIdx))))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Generate values for list options
|
|
|
|
else if (cfgDefOptionType(optionDefId) == cfgDefOptTypeList)
|
|
|
|
{
|
|
|
|
valueList = strLstNewVarLst(cfgOptionLst(optionId));
|
|
|
|
}
|
|
|
|
// Else only one value
|
|
|
|
else
|
|
|
|
{
|
|
|
|
valueList = strLstNew();
|
|
|
|
strLstAdd(valueList, varStrForce(cfgOption(optionId)));
|
|
|
|
}
|
2018-01-17 16:15:51 +02:00
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
// Output options and values
|
|
|
|
for (unsigned int valueListIdx = 0; valueListIdx < strLstSize(valueList); valueListIdx++)
|
|
|
|
{
|
|
|
|
const String *value = strLstGet(valueList, valueListIdx);
|
|
|
|
|
|
|
|
strCatFmt(info, " --%s", cfgOptionName(optionId));
|
|
|
|
|
|
|
|
if (strchr(strPtr(value), ' ') != NULL)
|
|
|
|
value = strNewFmt("\"%s\"", strPtr(value));
|
|
|
|
|
|
|
|
strCatFmt(info, "=%s", strPtr(value));
|
|
|
|
}
|
2018-01-17 16:15:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
LOG_ANY(cfgLogLevelDefault(), 0, strPtr(info));
|
|
|
|
}
|
|
|
|
MEM_CONTEXT_TEMP_END();
|
2018-01-17 16:15:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
End the command
|
|
|
|
***********************************************************************************************************************************/
|
2018-02-01 01:22:25 +02:00
|
|
|
void
|
|
|
|
cmdEnd(int code)
|
2018-01-17 16:15:51 +02:00
|
|
|
{
|
2018-03-12 16:55:58 +02:00
|
|
|
// A command must be set
|
|
|
|
assert(cfgCommand() != cfgCmdNone);
|
|
|
|
|
|
|
|
// Skip this log message if it won't be output. It's not too expensive but since we skipped cmdBegin(), may as well.
|
|
|
|
if (logWill(cfgLogLevelDefault()))
|
2018-01-17 16:15:51 +02:00
|
|
|
{
|
2018-03-12 16:55:58 +02:00
|
|
|
MEM_CONTEXT_TEMP_BEGIN()
|
|
|
|
{
|
|
|
|
// Basic info on command end
|
|
|
|
String *info = strNewFmt("%s command end: ", cfgCommandName(cfgCommand()));
|
2018-01-17 16:15:51 +02:00
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
if (code == 0)
|
|
|
|
strCat(info, "completed successfully");
|
|
|
|
else
|
|
|
|
strCatFmt(info, "aborted with exception [%03d]", code);
|
2018-01-17 16:15:51 +02:00
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
LOG_ANY(cfgLogLevelDefault(), 0, strPtr(info));
|
|
|
|
}
|
|
|
|
MEM_CONTEXT_TEMP_END();
|
2018-01-17 16:15:51 +02:00
|
|
|
}
|
|
|
|
}
|