1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-05 15:05:48 +02:00
pgbackrest/src/command/command.c

86 lines
3.1 KiB
C
Raw Normal View History

2018-01-17 09:15:51 -05:00
/***********************************************************************************************************************************
Common Command Routines
***********************************************************************************************************************************/
#include <string.h>
#include "common/log.h"
#include "common/memContext.h"
#include "config/config.h"
#include "version.h"
/***********************************************************************************************************************************
Begin the command
***********************************************************************************************************************************/
void
cmdBegin()
2018-01-17 09:15:51 -05:00
{
MEM_CONTEXT_TEMP_BEGIN()
{
// Basic info on command start
String *info = strNewFmt("%s command begin %s:", cfgCommandName(cfgCommand()), PGBACKREST_VERSION);
// Loop though options and add the ones that are interesting
for (ConfigOption optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++)
{
const Variant *option = cfgOption(optionId);
// Skip the option if it is not valid, or default, or not set
if (!cfgOptionValid(optionId) ||
cfgOptionSource(optionId) == cfgSourceDefault ||
(option == NULL && !cfgOptionNegate(optionId)))
{
continue;
}
// If option was negated
if (cfgOptionNegate(optionId))
strCatFmt(info, " --no-%s", cfgOptionName(optionId));
// Else not negated
else
{
ConfigDefineOption optionDefId = cfgOptionDefIdFromId(optionId);
strCatFmt(info, " --%s", cfgOptionName(optionId));
if (cfgDefOptionType(optionDefId) != cfgDefOptTypeBoolean)
{
if (cfgDefOptionSecure(optionDefId))
strCat(info, "=<redacted>");
else
{
const String *optionStr = varStrForce(option);
if (strchr(strPtr(optionStr), ' ') != NULL)
optionStr = strNewFmt("\"%s\"", strPtr(optionStr));
strCatFmt(info, "=%s", strPtr(optionStr));
}
}
}
}
LOG_INFO(strPtr(info));
}
MEM_CONTEXT_TEMP_END();
}
/***********************************************************************************************************************************
End the command
***********************************************************************************************************************************/
void
cmdEnd(int code)
2018-01-17 09:15:51 -05:00
{
MEM_CONTEXT_TEMP_BEGIN()
{
// Basic info on command end
String *info = strNewFmt("%s command end: ", cfgCommandName(cfgCommand()));
if (code == 0)
strCat(info, "completed successfully");
else
strCatFmt(info, "aborted with exception [%03d]", code);
LOG_INFO(strPtr(info));
}
MEM_CONTEXT_TEMP_END();
}