From 28116918ff3a00b133d74d524df452e29398082d Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 2 Dec 2019 07:35:36 -0500 Subject: [PATCH] Error in remote command when stop file exists. This duplicates the Perl functionality. --- src/Makefile.in | 2 +- src/command/remote/remote.c | 8 ++++++ test/src/module/command/remoteTest.c | 41 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Makefile.in b/src/Makefile.in index af20370e0..ec9d39f5e 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -276,7 +276,7 @@ command/info/info.o: command/info/info.c build.auto.h command/archive/common.h c command/local/local.o: command/local/local.c build.auto.h command/archive/get/protocol.h command/archive/push/protocol.h command/backup/protocol.h command/restore/protocol.h common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/handleRead.h common/io/handleWrite.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/protocol.h protocol/client.h protocol/command.h protocol/helper.h protocol/server.h $(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c command/local/local.c -o command/local/local.o -command/remote/remote.o: command/remote/remote.c build.auto.h common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/handleRead.h common/io/handleWrite.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/protocol.h db/protocol.h protocol/client.h protocol/command.h protocol/helper.h protocol/server.h storage/remote/protocol.h +command/remote/remote.o: command/remote/remote.c build.auto.h command/control/common.h common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/handleRead.h common/io/handleWrite.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/protocol.h db/protocol.h protocol/client.h protocol/command.h protocol/helper.h protocol/server.h storage/remote/protocol.h $(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c command/remote/remote.c -o command/remote/remote.o command/restore/file.o: command/restore/file.c build.auto.h command/restore/file.h common/assert.h common/compress/gzip/common.h common/compress/gzip/decompress.h common/crypto/cipherBlock.h common/crypto/common.h common/crypto/hash.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/filter/size.h common/io/io.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h storage/helper.h storage/info.h storage/read.h storage/storage.h storage/write.h diff --git a/src/command/remote/remote.c b/src/command/remote/remote.c index 58fbbca01..b5fff7e4e 100644 --- a/src/command/remote/remote.c +++ b/src/command/remote/remote.c @@ -5,6 +5,7 @@ Remote Command #include +#include "command/control/common.h" #include "common/debug.h" #include "common/io/handleRead.h" #include "common/io/handleWrite.h" @@ -53,9 +54,16 @@ cmdRemote(int handleRead, int handleWrite) // Acquire a lock if this command requires a lock if (cfgLockRemoteRequired(commandId)) + { + // Make sure the local host is not stopped + lockStopTest(); + + // Acquire the lock lockAcquire(cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), cfgLockRemoteType(commandId), 0, true); + } } + // Notify the client of success protocolServerResponse(server, NULL); success = true; } diff --git a/test/src/module/command/remoteTest.c b/test/src/module/command/remoteTest.c index b65a54a53..764979bb2 100644 --- a/test/src/module/command/remoteTest.c +++ b/test/src/module/command/remoteTest.c @@ -18,6 +18,10 @@ testRun(void) { FUNCTION_HARNESS_VOID(); + // Create default storage object for testing + Storage *storageData = storagePosixNew( + strNew(testDataPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL); + // ***************************************************************************************************************************** if (testBegin("cmdRemote()")) { @@ -162,6 +166,43 @@ testRun(void) HARNESS_FORK_PARENT_END(); } HARNESS_FORK_END(); + + // ------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("stop file exists"); + + HARNESS_FORK_BEGIN() + { + HARNESS_FORK_CHILD_BEGIN(0, true) + { + StringList *argList = strLstNew(); + strLstAddZ(argList, "--stanza=test"); + strLstAddZ(argList, "--command=archive-push-async"); + strLstAddZ(argList, "--process=0"); + strLstAddZ(argList, "--type=backup"); + harnessCfgLoad(cfgCmdRemote, argList); + + cmdRemote(HARNESS_FORK_CHILD_READ(), HARNESS_FORK_CHILD_WRITE()); + } + HARNESS_FORK_CHILD_END(); + + HARNESS_FORK_PARENT_BEGIN() + { + IoRead *read = ioHandleReadNew(strNew("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); + ioReadOpen(read); + IoWrite *write = ioHandleWriteNew(strNew("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0)); + ioWriteOpen(write); + + storagePutP(storageNewWriteP(storageData, strNew("lock/all" STOP_FILE_EXT)), NULL); + + TEST_ERROR( + protocolClientNew(strNew("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), StopError, + "raised from test: stop file exists for all stanzas"); + + storageRemoveP(storageData, strNew("lock/all" STOP_FILE_EXT)); + } + HARNESS_FORK_PARENT_END(); + } + HARNESS_FORK_END(); } FUNCTION_HARNESS_RESULT_VOID();