summaryrefslogtreecommitdiff
path: root/daemon/pgsql.c
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-08-18 22:14:20 +0000
committerStef Walter <stef@memberwebs.com>2004-08-18 22:14:20 +0000
commit03d751131db4b452bfcde6add0346fd1fcdc3fec (patch)
tree46bf506189c5677b3d4596af2aa300df007274c7 /daemon/pgsql.c
parent12af3bad4cf302ffad84b192c388de63a2b1c12e (diff)
Implemented postgres connect timeouts
Diffstat (limited to 'daemon/pgsql.c')
-rw-r--r--daemon/pgsql.c49
1 files changed, 46 insertions, 3 deletions
diff --git a/daemon/pgsql.c b/daemon/pgsql.c
index ce3d3b3..6bdb158 100644
--- a/daemon/pgsql.c
+++ b/daemon/pgsql.c
@@ -242,9 +242,48 @@ static int validate_password(ha_request_t* rq, pgsql_context_t* ctx, const char*
return HA_FALSE;
}
+static const char* make_pgsql_connstring(const ha_request_t* rq, pgsql_context_t* ctx)
+{
+ char num[16];
+
+ ASSERT(ctx->database);
+ ha_bufmcat(rq->buf, "dbname='", ctx->database, "'", NULL);
+
+ if(ctx->host)
+ {
+ ha_bufjoin(rq->buf);
+ ha_bufmcat(rq->buf, " host='", ctx->host, "'", NULL);
+ }
+
+ if(ctx->port)
+ {
+ ha_bufjoin(rq->buf);
+ ha_bufmcat(rq->buf, " port='", ctx->port, "'", NULL);
+ }
+
+ if(ctx->user)
+ {
+ ha_bufjoin(rq->buf);
+ ha_bufmcat(rq->buf, " user='", ctx->user, "'", NULL);
+ }
+
+ if(ctx->password)
+ {
+ ha_bufjoin(rq->buf);
+ ha_bufmcat(rq->buf, " password='", ctx->password, "'", NULL);
+ }
+
+ snprintf(num, 16, "%d", ctx->pgsql_timeout);
+ ha_bufjoin(rq->buf);
+ ha_bufmcat(rq->buf, " connect_timeout=", num, NULL);
+
+ return CHECK_RBUF(rq) ? NULL : ha_bufdata(rq->buf);
+}
+
static PGconn* get_pgsql_connection(const ha_request_t* rq, pgsql_context_t* ctx)
{
PGconn* pg;
+ const char* connstring;
int i;
ASSERT(ctx);
@@ -267,8 +306,13 @@ static PGconn* get_pgsql_connection(const ha_request_t* rq, pgsql_context_t* ctx
return NULL;
}
- pg = PQsetdbLogin(ctx->host, ctx->port, NULL, NULL, ctx->database,
- ctx->user, ctx->password);
+ connstring = make_pgsql_connstring(rq, ctx);
+ if(!connstring)
+ return NULL;
+
+ ha_messagex(rq, LOG_DEBUG, "connecting to postgres with: %s", connstring);
+
+ pg = PQconnectdb(connstring);
if(!pg)
{
ha_messagex(rq, LOG_CRIT, "internal error in postgres library");
@@ -653,7 +697,6 @@ int pgsql_config(ha_context_t* context, const char* name, const char* value)
else if(strcmp(name, "dbtimeout") == 0)
{
- /* TODO: Implement database timeouts */
return ha_confint(name, value, 0, 86400, &(ctx->pgsql_timeout));
}