aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/libpq/pqcomm.h6
-rw-r--r--src/include/pg_config_manual.h5
-rw-r--r--src/interfaces/libpq/fe-connect.c15
3 files changed, 18 insertions, 8 deletions
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index 6c8bc29acea..781d86c8efa 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -68,10 +68,10 @@ typedef struct
/* Configure the UNIX socket location for the well known port. */
#define UNIXSOCK_PATH(path, port, sockdir) \
+ (AssertMacro(sockdir), \
+ AssertMacro(*(sockdir) != '\0'), \
snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
- ((sockdir) && *(sockdir) != '\0') ? (sockdir) : \
- DEFAULT_PGSOCKET_DIR, \
- (port))
+ (sockdir), (port)))
/*
* The maximum workable length of a socket path is what will fit into
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
index 569af6997cc..b4ce53300b3 100644
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -191,6 +191,11 @@
* directory. But if you just hate the idea of sockets in /tmp,
* here's where to twiddle it. You can also override this at runtime
* with the postmaster's -k switch.
+ *
+ * If set to an empty string, then AF_UNIX sockets are not used by default: A
+ * server will not create an AF_UNIX socket unless the run-time configuration
+ * is changed, a client will connect via TCP/IP by default and will only use
+ * an AF_UNIX socket if one is explicitly specified.
*/
#define DEFAULT_PGSOCKET_DIR "/tmp"
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 2e2d217352d..99cd6c41176 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -1095,12 +1095,17 @@ connectOptions2(PGconn *conn)
if (ch->host)
free(ch->host);
#ifdef HAVE_UNIX_SOCKETS
- ch->host = strdup(DEFAULT_PGSOCKET_DIR);
- ch->type = CHT_UNIX_SOCKET;
-#else
- ch->host = strdup(DefaultHost);
- ch->type = CHT_HOST_NAME;
+ if (DEFAULT_PGSOCKET_DIR[0])
+ {
+ ch->host = strdup(DEFAULT_PGSOCKET_DIR);
+ ch->type = CHT_UNIX_SOCKET;
+ }
+ else
#endif
+ {
+ ch->host = strdup(DefaultHost);
+ ch->type = CHT_HOST_NAME;
+ }
if (ch->host == NULL)
goto oom_error;
}