mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 08:56:29 +00:00
Refactor remote_command() function
Use dynamic rather than fixed buffer to generate the command string.
This commit is contained in:
25
sysutils.c
25
sysutils.c
@@ -1,6 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* sysutils.c
|
* sysutils.c
|
||||||
*
|
*
|
||||||
|
* Functions which need to be executed on the local system.
|
||||||
|
*
|
||||||
* Copyright (c) 2ndQuadrant, 2010-2019
|
* Copyright (c) 2ndQuadrant, 2010-2019
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@@ -115,7 +117,7 @@ bool
|
|||||||
remote_command(const char *host, const char *user, const char *command, const char *ssh_options, PQExpBufferData *outputbuf)
|
remote_command(const char *host, const char *user, const char *command, const char *ssh_options, PQExpBufferData *outputbuf)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char ssh_command[MAXLEN] = "";
|
PQExpBufferData ssh_command;
|
||||||
PQExpBufferData ssh_host;
|
PQExpBufferData ssh_host;
|
||||||
|
|
||||||
char output[MAXLEN] = "";
|
char output[MAXLEN] = "";
|
||||||
@@ -129,24 +131,29 @@ remote_command(const char *host, const char *user, const char *command, const ch
|
|||||||
|
|
||||||
appendPQExpBufferStr(&ssh_host, host);
|
appendPQExpBufferStr(&ssh_host, host);
|
||||||
|
|
||||||
maxlen_snprintf(ssh_command,
|
initPQExpBuffer(&ssh_command);
|
||||||
"ssh -o Batchmode=yes %s %s %s",
|
|
||||||
ssh_options,
|
appendPQExpBuffer(&ssh_command,
|
||||||
ssh_host.data,
|
"ssh -o Batchmode=yes %s %s %s",
|
||||||
command);
|
ssh_options,
|
||||||
|
ssh_host.data,
|
||||||
|
command);
|
||||||
|
|
||||||
termPQExpBuffer(&ssh_host);
|
termPQExpBuffer(&ssh_host);
|
||||||
|
|
||||||
log_debug("remote_command():\n %s", ssh_command);
|
log_debug("remote_command():\n %s", ssh_command.data);
|
||||||
|
|
||||||
fp = popen(ssh_command, "r");
|
fp = popen(ssh_command.data, "r");
|
||||||
|
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
{
|
{
|
||||||
log_error(_("unable to execute remote command:\n %s"), ssh_command);
|
log_error(_("unable to execute remote command:\n %s"), ssh_command.data);
|
||||||
|
termPQExpBuffer(&ssh_command);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
termPQExpBuffer(&ssh_command);
|
||||||
|
|
||||||
if (outputbuf != NULL)
|
if (outputbuf != NULL)
|
||||||
{
|
{
|
||||||
/* TODO: better error handling */
|
/* TODO: better error handling */
|
||||||
|
|||||||
Reference in New Issue
Block a user