From 9c5e76401f15610ef393df681ac3cff57db023f3 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 27 Mar 2018 10:24:36 +0900 Subject: [PATCH] Fix "repmgr cluster crosscheck" output Addresses GitHub #398. --- HISTORY | 1 + repmgr-action-cluster.c | 11 ++++------- repmgr-client-global.h | 1 + repmgr-client.c | 25 ++++++++++++++++++++----- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/HISTORY b/HISTORY index 626d851a..b4db0431 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,6 @@ 4.0.5 2018-??-?? repmgr: fix display of conninfo parsing error messages (Ian) + repmgr: fix "repmgr cluster crosscheck" output; GitHub #389 (Ian) repmgrd: fix memory leaks in witness code (AndrzejNowicki, Martín) repmgrd: set "connect_timeout=2" when pinging a server (Ian) diff --git a/repmgr-action-cluster.c b/repmgr-action-cluster.c index da9fa47b..44b5a5cd 100644 --- a/repmgr-action-cluster.c +++ b/repmgr-action-cluster.c @@ -964,8 +964,7 @@ build_cluster_matrix(t_node_matrix_rec ***matrix_rec_dest, int *name_length) initPQExpBuffer(&command_output); - (void) remote_command( - host, + (void) remote_command(host, runtime_options.remote_user, command.data, &command_output); @@ -1144,9 +1143,8 @@ build_cluster_crosscheck(t_node_status_cube ***dest_cube, int *name_length) /* fix to work with --node-id */ if (cube[i]->node_id == config_file_options.node_id) { - (void) local_command( - command.data, - &command_output); + (void) local_command_simple(command.data, + &command_output); } else { @@ -1170,8 +1168,7 @@ build_cluster_crosscheck(t_node_status_cube ***dest_cube, int *name_length) log_verbose(LOG_DEBUG, "build_cluster_crosscheck(): executing\n %s", quoted_command.data); - (void) remote_command( - host, + (void) remote_command(host, runtime_options.remote_user, quoted_command.data, &command_output); diff --git a/repmgr-client-global.h b/repmgr-client-global.h index e6b24303..2c693579 100644 --- a/repmgr-client-global.h +++ b/repmgr-client-global.h @@ -207,6 +207,7 @@ extern void check_93_config(void); extern bool create_repmgr_extension(PGconn *conn); extern int test_ssh_connection(char *host, char *remote_user); extern bool local_command(const char *command, PQExpBufferData *outputbuf); +extern bool local_command_simple(const char *command, PQExpBufferData *outputbuf); extern standy_clone_mode get_standby_clone_mode(void); diff --git a/repmgr-client.c b/repmgr-client.c index 8bf7f32e..bd3ab94d 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -90,6 +90,7 @@ t_node_info target_node_info = T_NODE_INFO_INITIALIZER; static ItemList cli_errors = {NULL, NULL}; static ItemList cli_warnings = {NULL, NULL}; +static bool _local_command(const char *command, PQExpBufferData *outputbuf, bool simple); int main(int argc, char **argv) @@ -2096,12 +2097,28 @@ test_ssh_connection(char *host, char *remote_user) } + + /* * Execute a command locally. "outputbuf" should either be an * initialised PQexpbuffer, or NULL */ bool local_command(const char *command, PQExpBufferData *outputbuf) +{ + return _local_command(command, outputbuf, false); +} + + +bool +local_command_simple(const char *command, PQExpBufferData *outputbuf) +{ + return _local_command(command, outputbuf, true); +} + + +static bool +_local_command(const char *command, PQExpBufferData *outputbuf, bool simple) { FILE *fp = NULL; char output[MAXLEN]; @@ -2128,7 +2145,8 @@ local_command(const char *command, PQExpBufferData *outputbuf) while (fgets(output, MAXLEN, fp) != NULL) { appendPQExpBuffer(outputbuf, "%s", output); - if (!feof(fp)) + + if (!feof(fp) && simple == false) { break; } @@ -2352,9 +2370,6 @@ copy_remote_files(char *host, char *remote_user, char *remote_path, } - - - /* * Execute a command via ssh on the remote host. * @@ -2420,7 +2435,7 @@ remote_command(const char *host, const char *user, const char *command, PQExpBuf if (outputbuf != NULL) { if (strlen(outputbuf->data)) - log_verbose(LOG_DEBUG, "remote_command(): output returned was:\n %s", outputbuf->data); + log_verbose(LOG_DEBUG, "remote_command(): output returned was:\n%s", outputbuf->data); else log_verbose(LOG_DEBUG, "remote_command(): no output returned"); }