From bbb2b200ab626907534a9a47b928475607b8a8a3 Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Mon, 28 Aug 2017 12:13:28 +0200 Subject: [PATCH] dbd: use port for PostgreSQL connections If present, this uses the option to connect to PostgreSQL rather than systematically connect to the default port. --- src/os_dbd/db_op.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/os_dbd/db_op.c b/src/os_dbd/db_op.c index 2407be5a1..6073a2a13 100644 --- a/src/os_dbd/db_op.c +++ b/src/os_dbd/db_op.c @@ -261,11 +261,19 @@ int mysql_osdb_query_select(void *db_conn, const char *query) * Returns NULL on error */ void *postgresql_osdb_connect(const char *host, const char *user, const char *pass, const char *db, - __attribute__((unused)) unsigned int port, __attribute__((unused)) const char *sock) + unsigned int port, __attribute__((unused)) const char *sock) { PGconn *conn; + char portAsString[6]; + + if (port > 0) { + snprintf(portAsString, 6, "%u", port); + } else { + snprintf(portAsString, 6, ""); + } + + conn = PQsetdbLogin(host, portAsString, NULL, NULL, db, user, pass); - conn = PQsetdbLogin(host, NULL, NULL, NULL, db, user, pass); if (PQstatus(conn) == CONNECTION_BAD) { merror(DBCONN_ERROR, ARGV0, host, db, PQerrorMessage(conn)); PQfinish(conn);