From 28f453637245d618a4b2ee22671ede8b84ff8bc3 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 19 Aug 2019 17:55:18 +0900 Subject: [PATCH] repmgrd: fix pidfile handling at shutdown --- dbutils.c | 16 ++++++++++++++-- repmgr.c | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dbutils.c b/dbutils.c index f41dfd14..ad2f4529 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1908,8 +1908,20 @@ repmgrd_set_pid(PGconn *conn, pid_t repmgrd_pid, const char *pidfile) initPQExpBuffer(&query); appendPQExpBuffer(&query, - "SELECT repmgr.set_repmgrd_pid(%i, '%s')", - (int) repmgrd_pid, pidfile); + "SELECT repmgr.set_repmgrd_pid(%i, ", + (int) repmgrd_pid); + + if (pidfile != NULL) + { + appendPQExpBuffer(&query, + " '%s')", + pidfile); + } + else + { + appendPQExpBufferStr(&query, + " '')"); + } res = PQexec(conn, query.data); termPQExpBuffer(&query); diff --git a/repmgr.c b/repmgr.c index 2b6fc28b..09b9aade 100644 --- a/repmgr.c +++ b/repmgr.c @@ -702,7 +702,7 @@ set_repmgrd_pid(PG_FUNCTION_ARGS) shared_state->repmgrd_pid = repmgrd_pid; memset(shared_state->repmgrd_pidfile, 0, MAXPGPATH); - if(repmgrd_pidfile != NULL) + if (repmgrd_pidfile != NULL) { strncpy(shared_state->repmgrd_pidfile, repmgrd_pidfile, MAXPGPATH); }