Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9cff89

Browse filesBrowse 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
Copy full SHA for a9cff89

File tree

Expand file treeCollapse file tree

3 files changed

+18
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+18
-8
lines changed

‎src/include/libpq/pqcomm.h

Copy file name to clipboardExpand all lines: src/include/libpq/pqcomm.h
+3-3Lines changed: 3 additions & 3 deletions
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

Copy file name to clipboardExpand all lines: src/include/pg_config_manual.h
+5Lines changed: 5 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: src/interfaces/libpq/fe-connect.c
+10-5Lines changed: 10 additions & 5 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.