From c8e52e486f0c63bae1b7e8e99e1d4bcfd32c90ac Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 2 Sep 2020 15:30:02 +0900 Subject: [PATCH] Have make_pg_path() output to a PQexpBuffer Calling functions are all using one anyway, so there's no point keeping static buffers around. --- repmgr-action-node.c | 6 +++--- repmgr-action-standby.c | 24 ++++++++++++++--------- repmgr-client-global.h | 2 +- repmgr-client.c | 42 ++++++++++++++++++++++------------------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/repmgr-action-node.c b/repmgr-action-node.c index 0696ded1..08eb1f20 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -2733,9 +2733,9 @@ do_node_rejoin(void) } else { - appendPQExpBuffer(&command, - "%s -D ", - make_pg_path("pg_rewind")); + make_pg_path(&command, "pg_rewind"); + appendPQExpBufferStr(&command, + " -D "); } appendShellString(&command, diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 27edb920..a9101c64 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -6564,9 +6564,11 @@ initialise_direct_clone(t_node_info *local_node_record, t_node_info *upstream_no static int run_basebackup(t_node_info *node_record) { - char script[MAXLEN] = ""; - int r = SUCCESS; PQExpBufferData params; + PQExpBufferData script; + + int r = SUCCESS; + TablespaceListCell *cell = NULL; t_basebackup_options backup_options = T_BASEBACKUP_OPTIONS_INITIALIZER; @@ -6717,21 +6719,25 @@ run_basebackup(t_node_info *node_record) } } - maxlen_snprintf(script, - "%s -l \"repmgr base backup\" %s %s", - make_pg_path("pg_basebackup"), - params.data, - config_file_options.pg_basebackup_options); + initPQExpBuffer(&script); + make_pg_path(&script, "pg_basebackup"); + + appendPQExpBuffer(&script, + " -l \"repmgr base backup\" %s %s", + params.data, + config_file_options.pg_basebackup_options); termPQExpBuffer(¶ms); - log_info(_("executing:\n %s"), script); + log_info(_("executing:\n %s"), script.data); /* * As of 9.4, pg_basebackup only ever returns 0 or 1 */ - r = system(script); + r = system(script.data); + + termPQExpBuffer(&script); if (r != 0) return ERR_BAD_BASEBACKUP; diff --git a/repmgr-client-global.h b/repmgr-client-global.h index 88408127..d113d7cb 100644 --- a/repmgr-client-global.h +++ b/repmgr-client-global.h @@ -262,7 +262,7 @@ extern int copy_remote_files(char *host, char *remote_user, char *remote_path, extern void print_error_list(ItemList *error_list, int log_level); -extern char *make_pg_path(const char *file); +extern void make_pg_path(PQExpBufferData *buf, const char *file); extern void get_superuser_connection(PGconn **conn, PGconn **superuser_conn, PGconn **privileged_conn); diff --git a/repmgr-client.c b/repmgr-client.c index cd8e8714..b4f89655 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -81,9 +81,7 @@ t_runtime_options runtime_options = T_RUNTIME_OPTIONS_INITIALIZER; t_conninfo_param_list source_conninfo = T_CONNINFO_PARAM_LIST_INITIALIZER; bool config_file_required = true; -char pg_bindir[MAXLEN] = ""; - -char path_buf[MAXLEN] = ""; +char pg_bindir[MAXPGPATH] = ""; /* * if --node-id/--node-name provided, place that node's record here @@ -3057,7 +3055,6 @@ get_superuser_connection(PGconn **conn, PGconn **superuser_conn, PGconn **privil } - standy_clone_mode get_standby_clone_mode(void) { @@ -3072,12 +3069,11 @@ get_standby_clone_mode(void) } -char * -make_pg_path(const char *file) +void +make_pg_path(PQExpBufferData *buf, const char *file) { - maxlen_snprintf(path_buf, "%s%s", pg_bindir, file); - - return path_buf; + appendPQExpBuffer(buf, "%s%s", + pg_bindir, file); } @@ -3293,9 +3289,10 @@ get_server_action(t_server_action action, char *script, char *data_dir) { initPQExpBuffer(&command); + make_pg_path(&command, "pg_ctl"); + appendPQExpBuffer(&command, - "%s %s -w -D ", - make_pg_path("pg_ctl"), + " %s -w -D ", config_file_options.pg_ctl_options); appendShellString(&command, @@ -3323,9 +3320,10 @@ get_server_action(t_server_action action, char *script, char *data_dir) else { initPQExpBuffer(&command); + make_pg_path(&command, "pg_ctl"); + appendPQExpBuffer(&command, - "%s %s -D ", - make_pg_path("pg_ctl"), + " %s -D ", config_file_options.pg_ctl_options); appendShellString(&command, @@ -3358,9 +3356,11 @@ get_server_action(t_server_action action, char *script, char *data_dir) else { initPQExpBuffer(&command); + + make_pg_path(&command, "pg_ctl"); + appendPQExpBuffer(&command, - "%s %s -w -D ", - make_pg_path("pg_ctl"), + " %s -w -D ", config_file_options.pg_ctl_options); appendShellString(&command, @@ -3386,9 +3386,11 @@ get_server_action(t_server_action action, char *script, char *data_dir) else { initPQExpBuffer(&command); + + make_pg_path(&command, "pg_ctl"); + appendPQExpBuffer(&command, - "%s %s -w -D ", - make_pg_path("pg_ctl"), + " %s -w -D ", config_file_options.pg_ctl_options); appendShellString(&command, @@ -3415,9 +3417,11 @@ get_server_action(t_server_action action, char *script, char *data_dir) else { initPQExpBuffer(&command); + + make_pg_path(&command, "pg_ctl"); + appendPQExpBuffer(&command, - "%s %s -w -D ", - make_pg_path("pg_ctl"), + " %s -w -D ", config_file_options.pg_ctl_options); appendShellString(&command,