Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a9cff89

Browse files
committed
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: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/75f72249-8ae6-322a-63df-4fe03eeccb9f@2ndquadrant.com
1 parent 7c23bfd commit a9cff89

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/include/libpq/pqcomm.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ typedef struct
6868
/* Configure the UNIX socket location for the well known port. */
6969

7070
#define UNIXSOCK_PATH(path, port, sockdir) \
71+
(AssertMacro(sockdir), \
72+
AssertMacro(*(sockdir) != '\0'), \
7173
snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
72-
((sockdir) && *(sockdir) != '\0') ? (sockdir) : \
73-
DEFAULT_PGSOCKET_DIR, \
74-
(port))
74+
(sockdir), (port)))
7575

7676
/*
7777
* The maximum workable length of a socket path is what will fit into

src/include/pg_config_manual.h

+5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@
191191
* directory. But if you just hate the idea of sockets in /tmp,
192192
* here's where to twiddle it. You can also override this at runtime
193193
* with the postmaster's -k switch.
194+
*
195+
* If set to an empty string, then AF_UNIX sockets are not used by default: A
196+
* server will not create an AF_UNIX socket unless the run-time configuration
197+
* is changed, a client will connect via TCP/IP by default and will only use
198+
* an AF_UNIX socket if one is explicitly specified.
194199
*/
195200
#define DEFAULT_PGSOCKET_DIR "/tmp"
196201

src/interfaces/libpq/fe-connect.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -1095,12 +1095,17 @@ connectOptions2(PGconn *conn)
10951095
if (ch->host)
10961096
free(ch->host);
10971097
#ifdef HAVE_UNIX_SOCKETS
1098-
ch->host = strdup(DEFAULT_PGSOCKET_DIR);
1099-
ch->type = CHT_UNIX_SOCKET;
1100-
#else
1101-
ch->host = strdup(DefaultHost);
1102-
ch->type = CHT_HOST_NAME;
1098+
if (DEFAULT_PGSOCKET_DIR[0])
1099+
{
1100+
ch->host = strdup(DEFAULT_PGSOCKET_DIR);
1101+
ch->type = CHT_UNIX_SOCKET;
1102+
}
1103+
else
11031104
#endif
1105+
{
1106+
ch->host = strdup(DefaultHost);
1107+
ch->type = CHT_HOST_NAME;
1108+
}
11041109
if (ch->host == NULL)
11051110
goto oom_error;
11061111
}

0 commit comments

Comments
 (0)