Redefine default result from PQhost()?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Redefine default result from PQhost()?
Date: 2015-11-25 22:59:48
Message-ID: 27665.1448492388@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Currently, libpq's PQhost() function will return NULL if the connection is
using the default Unix-socket connection address. This seems like a
pretty dubious definition to me. psql works around it in several places
with

host = PQhost(pset.db);
if (host == NULL)
host = DEFAULT_PGSOCKET_DIR;

That seems rather duplicative, and it also means that both libpq and psql
have the default socket directory hard-wired into them, which does not
seem like a good thing. It's conceivable that psql could get used with
a libpq built with a different default, in which case these places would
be outright lying about which socket is being used.

I think we should do this:

char *
PQhost(const PGconn *conn)
{
if (!conn)
return NULL;
if (conn->pghost != NULL && conn->pghost[0] != '\0')
return conn->pghost;
else
{
#ifdef HAVE_UNIX_SOCKETS
- return conn->pgunixsocket;
+ if (conn->pgunixsocket != NULL && conn->pgunixsocket[0] != '\0')
+ return conn->pgunixsocket;
+ else
+ return DEFAULT_PGSOCKET_DIR;
#else
return DefaultHost;
#endif
}
}

As a definitional change, this would be for HEAD only.

Comments?

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2015-11-26 01:13:26 Re: WIP: About CMake v2
Previous Message Pavel Stehule 2015-11-25 19:21:49 Re: proposal: multiple psql option -c