Commit a9cff89f authored by Peter Eisentraut's avatar Peter Eisentraut

Allow building without default socket directory

We have code paths for Unix socket support and no Unix socket support.
Now add a third variant: Unix socket support but do not use a Unix
socket by default in the client or the server, only if you explicitly
specify one.  This will be useful when we enable Unix socket support
on Windows.

To implement this, tweak things so that setting DEFAULT_PGSOCKET_DIR
to "" has the desired effect.  This mostly already worked like that;
only a few places needed to be adjusted.  Notably, the reference to
DEFAULT_PGSOCKET_DIR in UNIXSOCK_PATH() could be removed because all
callers already resolve an empty socket directory setting with a
default if appropriate.
Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/75f72249-8ae6-322a-63df-4fe03eeccb9f@2ndquadrant.com
parent 7c23bfd2
...@@ -68,10 +68,10 @@ typedef struct ...@@ -68,10 +68,10 @@ typedef struct
/* Configure the UNIX socket location for the well known port. */ /* Configure the UNIX socket location for the well known port. */
#define UNIXSOCK_PATH(path, port, sockdir) \ #define UNIXSOCK_PATH(path, port, sockdir) \
(AssertMacro(sockdir), \
AssertMacro(*(sockdir) != '\0'), \
snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \ snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
((sockdir) && *(sockdir) != '\0') ? (sockdir) : \ (sockdir), (port)))
DEFAULT_PGSOCKET_DIR, \
(port))
/* /*
* The maximum workable length of a socket path is what will fit into * The maximum workable length of a socket path is what will fit into
......
...@@ -191,6 +191,11 @@ ...@@ -191,6 +191,11 @@
* directory. But if you just hate the idea of sockets in /tmp, * 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 * here's where to twiddle it. You can also override this at runtime
* with the postmaster's -k switch. * 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" #define DEFAULT_PGSOCKET_DIR "/tmp"
......
...@@ -1095,12 +1095,17 @@ connectOptions2(PGconn *conn) ...@@ -1095,12 +1095,17 @@ connectOptions2(PGconn *conn)
if (ch->host) if (ch->host)
free(ch->host); free(ch->host);
#ifdef HAVE_UNIX_SOCKETS #ifdef HAVE_UNIX_SOCKETS
ch->host = strdup(DEFAULT_PGSOCKET_DIR); if (DEFAULT_PGSOCKET_DIR[0])
ch->type = CHT_UNIX_SOCKET; {
#else ch->host = strdup(DEFAULT_PGSOCKET_DIR);
ch->host = strdup(DefaultHost); ch->type = CHT_UNIX_SOCKET;
ch->type = CHT_HOST_NAME; }
else
#endif #endif
{
ch->host = strdup(DefaultHost);
ch->type = CHT_HOST_NAME;
}
if (ch->host == NULL) if (ch->host == NULL)
goto oom_error; goto oom_error;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment