aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-connect.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-11-27 14:13:53 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2015-11-27 14:13:53 -0500
commit40cb21f70b4ef2721c38be6628298fb21fa7d2d2 (patch)
tree23f6cd0c7e96c9cde87942ca74e1e8dfed307e66 /src/interfaces/libpq/fe-connect.c
parent92e38182d7c8947a4ebbc1123b44f1245e232e85 (diff)
downloadpostgresql-40cb21f70b4ef2721c38be6628298fb21fa7d2d2.tar.gz
postgresql-40cb21f70b4ef2721c38be6628298fb21fa7d2d2.zip
Improve PQhost() to return useful data for default Unix-socket connections.
Previously, if no host information had been specified at connection time, PQhost() would return NULL (unless you are on Windows, in which case you got "localhost"). This is an unhelpful definition for a couple of reasons: it can cause corner-case crashes in applications (cf commit c5ef8ce53d), and there's no well-defined way for applications to find out the socket directory path that's actually in use. As an example of the latter problem, psql substituted DEFAULT_PGSOCKET_DIR for NULL in a couple of places, but this is subtly wrong because it's conceivable that psql is using a libpq shared library that was built with a different setting. Hence, change PQhost() to return DEFAULT_PGSOCKET_DIR when appropriate, and strip out the now-dead substitutions in psql. (There is still one remaining reference to DEFAULT_PGSOCKET_DIR in psql, in prompt.c, which I don't see a nice way to get rid of. But it only controls a prompt abbreviation decision, so it seems noncritical.) Also update the docs for PQhost, which had never previously mentioned the possibility of a socket directory path being returned. In passing fix the outright-incorrect code comment about PGconn.pgunixsocket.
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r--src/interfaces/libpq/fe-connect.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 9c51166b40a..4a1a0272b6b 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -5353,7 +5353,10 @@ PQhost(const PGconn *conn)
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