From d4d06f43f7503df418c7cc08b6a4a538409d67b2 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 11 Aug 2016 08:46:55 +0900 Subject: [PATCH] When the output of a remote command isn't required, ensure it's consumed anyway This fixes a regression introduced with commit 85f68e9f77bb6aa0a666e88cb2ce3b06cbcda583 Also clean up some code made redundant by same. --- repmgr.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/repmgr.c b/repmgr.c index 954b9663..51709d68 100644 --- a/repmgr.c +++ b/repmgr.c @@ -3453,16 +3453,12 @@ do_standby_switchover(void) log_debug("Executing:\n%s\n", command); - initPQExpBuffer(&command_output); - (void)remote_command( remote_host, runtime_options.remote_user, command, NULL); - termPQExpBuffer(&command_output); - /* verify that new standby is connected and replicating */ connection_success = false; @@ -5734,6 +5730,22 @@ remote_command(const char *host, const char *user, const char *command, PQExpBuf appendPQExpBuffer(outputbuf, "%s", output); } } + else + { + /* + * When executed remotely, repmgr commands which execute pg_ctl (particularly + * `repmgr standby follow`) will see the pg_ctl command appear to fail with a + * non-zero return code when the output from the executed pg_ctl command + * has nowhere to go, even though the command actually succeeds. We'll consume an + * arbitrary amount of output and throw it away to work around this. + */ + int i = 0; + while (fgets(output, MAXLEN, fp) != NULL && i < 10) + { + i++; + } + } + pclose(fp); if (outputbuf != NULL)