1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Protocol shim improvements.

Add executable to parameter list to avoid first option being lost. The backup, restore, and verify tests worked OK with their first option being defaulted because it ended up being job-retry which worked fine as the default.

Add hrnProtocolLocalShimUninstall() allow the shim to be uninstalled.

Log shim at debug level to make it obvious in the logs when a shim is in use.
This commit is contained in:
David Steele 2021-05-25 11:00:24 -04:00
parent 55f52955a5
commit d55b9471a8
3 changed files with 29 additions and 14 deletions

View File

@ -209,6 +209,7 @@
<commit subject="Add local process shim."/>
<commit subject="Add log shim."/>
<commit subject="Fix shims with more than one function."/>
<commit subject="Protocol shim improvements."/>
<p>Add local processs shim.</p>
</release-item>

View File

@ -21,11 +21,12 @@ Include shimmed C modules
{[SHIM_MODULE]}
/***********************************************************************************************************************************
Shim initialization state
Shim install state
***********************************************************************************************************************************/
static struct
{
bool localHandler;
// Local process shim
bool localShim;
const ProtocolServerHandler *localHandlerList;
unsigned int localHandlerListSize;
} hrnProtocolStatic;
@ -37,15 +38,15 @@ static void
protocolLocalExec(
ProtocolHelperClient *helper, ProtocolStorageType protocolStorageType, unsigned int hostIdx, unsigned int processId)
{
// Call the shim when initialized
if (hrnProtocolStatic.localHandler)
// Call the shim when installed
if (hrnProtocolStatic.localShim)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM_P(VOID, helper);
FUNCTION_HARNESS_PARAM(ENUM, protocolStorageType);
FUNCTION_HARNESS_PARAM(UINT, hostIdx);
FUNCTION_HARNESS_PARAM(UINT, processId);
FUNCTION_HARNESS_END();
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM_P(VOID, helper);
FUNCTION_LOG_PARAM(STRING_ID, protocolStorageType);
FUNCTION_LOG_PARAM(UINT, hostIdx);
FUNCTION_LOG_PARAM(UINT, processId);
FUNCTION_LOG_END();
// Create pipes to communicate with the subprocess. The names of the pipes are from the perspective of the parent process
// since the child process will use them only briefly before exec'ing.
@ -59,7 +60,8 @@ protocolLocalExec(
if (forkSafe() == 0)
{
// Load configuration
const StringList *const paramList = protocolLocalParam(protocolStorageType, hostIdx, processId);
StringList *const paramList = protocolLocalParam(protocolStorageType, hostIdx, processId);
strLstInsert(paramList, 0, cfgExe());
harnessCfgLoadRaw(strLstSize(paramList), strLstPtr(paramList));
// Change log process id to aid in debugging
@ -92,7 +94,7 @@ protocolLocalExec(
helper->client = protocolClientNew(
strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol", processId), PROTOCOL_SERVICE_LOCAL_STR, read, write);
FUNCTION_HARNESS_RETURN_VOID();
FUNCTION_LOG_RETURN_VOID();
}
// Else call the base function
else
@ -108,9 +110,20 @@ hrnProtocolLocalShimInstall(const ProtocolServerHandler *const handlerList, cons
FUNCTION_HARNESS_PARAM(UINT, handlerListSize);
FUNCTION_HARNESS_END();
hrnProtocolStatic.localHandler = true;
hrnProtocolStatic.localShim = true;
hrnProtocolStatic.localHandlerList = handlerList;
hrnProtocolStatic.localHandlerListSize = handlerListSize;
FUNCTION_HARNESS_RETURN_VOID();
}
/**********************************************************************************************************************************/
void
hrnProtocolLocalShimUninstall(void)
{
FUNCTION_HARNESS_VOID();
hrnProtocolStatic.localShim = false;
FUNCTION_HARNESS_RETURN_VOID();
}

View File

@ -6,7 +6,8 @@ Harness for Protocol Testing
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Initialize the shim that allows protocalLocalGet() to start a local in a forked process rather than being exec'd. The main
// Install/uninstall the shim that allows protocalLocalGet() to start a local in a forked process rather than being exec'd. The main
// benefit is that code running in the forked process will be included in coverage so no separate tests for the local protocol
// functions should be required. A side benefit is that the pgbackrest binary does not need to be built since there is no exec.
void hrnProtocolLocalShimInstall(const ProtocolServerHandler *const handlerList, const unsigned int handlerListSize);
void hrnProtocolLocalShimUninstall(void);