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

Migrate remote command to C.

Prior to this the Perl remote was used to satisfy C requests. This worked fine but since the remote needed to be migrated to C anyway there was no reason to wait.

Add the ProtocolServer object and tweak ProtocolClient to work with it. It was also necessary to add a mechanism to get option values from the remote so that encryption settings could be read and used in the storage object.

Update the remote storage objects to comply with the protocol changes and add the storage protocol handler.

Ideally this commit would have been broken up into smaller chunks but there are cross-dependencies in the protocol layer and it didn't seem worth the extra effort.
This commit is contained in:
David Steele
2019-02-19 20:57:38 +02:00
parent d211c2b8b5
commit da628be8a8
21 changed files with 1121 additions and 72 deletions

View File

@ -0,0 +1,73 @@
/***********************************************************************************************************************************
Test Remote Command
***********************************************************************************************************************************/
#include "common/io/handleRead.h"
#include "common/io/handleWrite.h"
#include "protocol/client.h"
#include "protocol/server.h"
#include "common/harnessConfig.h"
#include "common/harnessFork.h"
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
void
testRun(void)
{
FUNCTION_HARNESS_VOID();
// *****************************************************************************************************************************
if (testBegin("cmdRemote()"))
{
// Create pipes for testing. Read/write is from the perspective of the client.
int pipeRead[2];
int pipeWrite[2];
THROW_ON_SYS_ERROR(pipe(pipeRead) == -1, KernelError, "unable to read test pipe");
THROW_ON_SYS_ERROR(pipe(pipeWrite) == -1, KernelError, "unable to write test pipe");
HARNESS_FORK_BEGIN()
{
HARNESS_FORK_CHILD()
{
close(pipeRead[0]);
close(pipeWrite[1]);
StringList *argList = strLstNew();
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--stanza=test1");
strLstAddZ(argList, "--command=info");
strLstAddZ(argList, "--process=1");
strLstAddZ(argList, "--type=backup");
strLstAddZ(argList, "remote");
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
cmdRemote(pipeWrite[0], pipeRead[1]);
close(pipeRead[1]);
close(pipeWrite[0]);
}
HARNESS_FORK_PARENT()
{
close(pipeRead[1]);
close(pipeWrite[0]);
IoRead *read = ioHandleReadIo(ioHandleReadNew(strNew("server read"), pipeRead[0], 2000));
ioReadOpen(read);
IoWrite *write = ioHandleWriteIo(ioHandleWriteNew(strNew("server write"), pipeWrite[1]));
ioWriteOpen(write);
ProtocolClient *client = protocolClientNew(strNew("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write);
protocolClientNoOp(client);
protocolClientFree(client);
close(pipeRead[0]);
close(pipeWrite[1]);
}
}
HARNESS_FORK_END();
}
FUNCTION_HARNESS_RESULT_VOID();
}