From 6f149ead8f8ebaea3ac234802dd01d06dc39b6de Mon Sep 17 00:00:00 2001 From: Christian Kruse Date: Thu, 16 Jan 2014 14:48:46 +0100 Subject: [PATCH] do not exit in guc_setted and guc_setted_typed --- dbutils.c | 30 ++++++++++++++---------------- dbutils.h | 4 ++-- repmgr.c | 27 +++++++++++++++++++-------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/dbutils.c b/dbutils.c index ba48798f..7a69266d 100644 --- a/dbutils.c +++ b/dbutils.c @@ -213,12 +213,13 @@ pg_version(PGconn *conn, char* major_version) } -bool +int guc_setted(PGconn *conn, const char *parameter, const char *op, const char *value) { PGresult *res; char sqlquery[QUERY_STR_LEN]; + int retval = 1; sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings " " WHERE name = '%s' AND setting %s '%s'", @@ -229,30 +230,29 @@ guc_setted(PGconn *conn, const char *parameter, const char *op, { log_err(_("GUC setting check PQexec failed: %s"), PQerrorMessage(conn)); - PQclear(res); - PQfinish(conn); - exit(ERR_DB_QUERY); + retval = -1; } - if (PQntuples(res) == 0) + else if (PQntuples(res) == 0) { - PQclear(res); - return false; + retval = 0; } + PQclear(res); - return true; + return retval; } /** * Just like guc_setted except with an extra parameter containing the name of * the pg datatype so that the comparison can be done properly. */ -bool +int guc_setted_typed(PGconn *conn, const char *parameter, const char *op, const char *value, const char *datatype) { PGresult *res; char sqlquery[QUERY_STR_LEN]; + int retval = 1; sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings " " WHERE name = '%s' AND setting::%s %s '%s'::%s", @@ -263,18 +263,16 @@ guc_setted_typed(PGconn *conn, const char *parameter, const char *op, { log_err(_("GUC setting check PQexec failed: %s"), PQerrorMessage(conn)); - PQclear(res); - PQfinish(conn); - exit(ERR_DB_QUERY); + retval = -1; } - if (PQntuples(res) == 0) + else if (PQntuples(res) == 0) { - PQclear(res); - return false; + retval = 0; } + PQclear(res); - return true; + return retval; } diff --git a/dbutils.h b/dbutils.h index 6bc771f7..d571335a 100644 --- a/dbutils.h +++ b/dbutils.h @@ -30,9 +30,9 @@ int is_standby(PGconn *conn); int is_witness(PGconn *conn, char *schema, char *cluster, int node_id); bool is_pgup(PGconn *conn, int timeout); char *pg_version(PGconn *conn, char* major_version); -bool guc_setted(PGconn *conn, const char *parameter, const char *op, +int guc_setted(PGconn *conn, const char *parameter, const char *op, const char *value); -bool guc_setted_typed(PGconn *conn, const char *parameter, const char *op, +int guc_setted_typed(PGconn *conn, const char *parameter, const char *op, const char *value, const char *datatype); const char *get_cluster_size(PGconn *conn); diff --git a/repmgr.c b/repmgr.c index 4b540258..68cb6d32 100644 --- a/repmgr.c +++ b/repmgr.c @@ -853,28 +853,39 @@ do_standby_clone(void) } /* And check if it is well configured */ - if (!guc_setted(conn, "wal_level", "=", "hot_standby")) + i = guc_setted(conn, "wal_level", "=", "hot_standby"); + if (i == 0 || i == -1) { PQfinish(conn); - log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"), progname); + if (i == 0) + log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"), progname); exit(ERR_BAD_CONFIG); } - if (!guc_setted_typed(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments, "integer")) + + i = guc_setted_typed(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments, "integer"); + if (i == 0 || i == -1) { PQfinish(conn); - log_err(_("%s needs parameter 'wal_keep_segments' to be set to %s or greater (see the '-w' option or edit the postgresql.conf of the PostgreSQL master.)\n"), progname, runtime_options.wal_keep_segments); + if (i == 0) + log_err(_("%s needs parameter 'wal_keep_segments' to be set to %s or greater (see the '-w' option or edit the postgresql.conf of the PostgreSQL master.)\n"), progname, runtime_options.wal_keep_segments); exit(ERR_BAD_CONFIG); } - if (!guc_setted(conn, "archive_mode", "=", "on")) + + i = guc_setted(conn, "archive_mode", "=", "on"); + if (i == 0 || i == -1) { PQfinish(conn); - log_err(_("%s needs parameter 'archive_mode' to be set to 'on'\n"), progname); + if (i == 0) + log_err(_("%s needs parameter 'archive_mode' to be set to 'on'\n"), progname); exit(ERR_BAD_CONFIG); } - if (!guc_setted(conn, "hot_standby", "=", "on")) + + i = guc_setted(conn, "hot_standby", "=", "on"); + if (i == 0 || i == -1) { PQfinish(conn); - log_err(_("%s needs parameter 'hot_standby' to be set to 'on'\n"), progname); + if (i == 0) + log_err(_("%s needs parameter 'hot_standby' to be set to 'on'\n"), progname); exit(ERR_BAD_CONFIG); }