Additional "standby clone" code

We'll break up the unwieldy "do_standby_clone()" function into discrete
unit for easier maintenance.
This commit is contained in:
Ian Barwick
2017-04-28 22:00:26 +09:00
parent 99e7bb0ea3
commit dc347f1484
14 changed files with 668 additions and 14 deletions

View File

@@ -1047,3 +1047,47 @@ test_ssh_connection(char *host, char *remote_user)
return r;
}
/*
* Execute a command locally. If outputbuf == NULL, discard the
* output.
*/
bool
local_command(const char *command, PQExpBufferData *outputbuf)
{
FILE *fp;
char output[MAXLEN];
int retval;
if (outputbuf == NULL)
{
retval = system(command);
return (retval == 0) ? true : false;
}
else
{
fp = popen(command, "r");
if (fp == NULL)
{
log_error(_("unable to execute local command:\n%s"), command);
return false;
}
/* TODO: better error handling */
while (fgets(output, MAXLEN, fp) != NULL)
{
appendPQExpBuffer(outputbuf, "%s", output);
}
pclose(fp);
if (outputbuf->data != NULL)
log_verbose(LOG_DEBUG, "local_command(): output returned was:\n%s", outputbuf->data);
else
log_verbose(LOG_DEBUG, "local_command(): no output returned");
return true;
}
}