v3-0007-Disable-Unix-sockets-by-default-on-Windows.patch

text/plain

Filename: v3-0007-Disable-Unix-sockets-by-default-on-Windows.patch
Type: text/plain
Part: 6
Message: Re: Unix-domain socket support on Windows

Patch

Format: format-patch
Series: patch v3-0007
Subject: Disable Unix sockets by default on Windows
File+
src/backend/utils/misc/guc.c 1 1
src/bin/initdb/initdb.c 1 1
src/bin/psql/prompt.c 2 0
src/bin/scripts/pg_isready.c 4 0
src/include/libpq/pqcomm.h 8 0
src/include/port/win32.h 8 0
src/interfaces/libpq/fe-connect.c 3 1
From 9752500fa24f305ca075ae839bd8890002db2136 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 13 Aug 2019 00:47:59 +0200
Subject: [PATCH v3 7/7] Disable Unix sockets by default on Windows

---
 src/backend/utils/misc/guc.c      | 2 +-
 src/bin/initdb/initdb.c           | 2 +-
 src/bin/psql/prompt.c             | 2 ++
 src/bin/scripts/pg_isready.c      | 4 ++++
 src/include/libpq/pqcomm.h        | 8 ++++++++
 src/include/port/win32.h          | 8 ++++++++
 src/interfaces/libpq/fe-connect.c | 4 +++-
 7 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 90ffd89339..e4a82c7f07 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -3939,7 +3939,7 @@ static struct config_string ConfigureNamesString[] =
 			GUC_SUPERUSER_ONLY
 		},
 		&Unix_socket_directories,
-#ifdef HAVE_UNIX_SOCKETS
+#if defined(HAVE_UNIX_SOCKETS) && defined(DEFAULT_PGSOCKET_DIR)
 		DEFAULT_PGSOCKET_DIR,
 #else
 		"",
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index ffbcf685d5..5931e6baad 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1118,7 +1118,7 @@ setup_config(void)
 				 n_buffers * (BLCKSZ / 1024));
 	conflines = replace_token(conflines, "#shared_buffers = 32MB", repltok);
 
-#ifdef HAVE_UNIX_SOCKETS
+#if defined(HAVE_UNIX_SOCKETS) && defined(DEFAULT_PGSOCKET_DIR)
 	if (unix_sockets_work)
 		snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",
 				 DEFAULT_PGSOCKET_DIR);
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index f8edc942da..7764bae064 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -138,7 +138,9 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
 						else
 						{
 							if (!host
+#ifdef DEFAULT_PGSOCKET_DIR
 								|| strcmp(host, DEFAULT_PGSOCKET_DIR) == 0
+#endif
 								|| *p == 'm')
 								strlcpy(buf, "[local]", sizeof(buf));
 							else
diff --git a/src/bin/scripts/pg_isready.c b/src/bin/scripts/pg_isready.c
index 079447f951..4dfc8712bf 100644
--- a/src/bin/scripts/pg_isready.c
+++ b/src/bin/scripts/pg_isready.c
@@ -164,7 +164,11 @@ main(int argc, char **argv)
 			else if (def->val)
 				pghost_str = def->val;
 			else
+#ifdef DEFAULT_PGSOCKET_DIR
 				pghost_str = DEFAULT_PGSOCKET_DIR;
+#else
+				pghost_str = "";
+#endif
 		}
 		else if (strcmp(def->keyword, "hostaddr") == 0)
 		{
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index baf6a4b6c0..8fe332c1e4 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -67,11 +67,19 @@ typedef struct
 
 /* Configure the UNIX socket location for the well known port. */
 
+#ifdef DEFAULT_PGSOCKET_DIR
 #define UNIXSOCK_PATH(path, port, sockdir) \
 		snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
 				((sockdir) && *(sockdir) != '\0') ? (sockdir) : \
 				DEFAULT_PGSOCKET_DIR, \
 				(port))
+#else
+#define UNIXSOCK_PATH(path, port, sockdir) \
+		(AssertMacro((sockdir) && *(sockdir) != '\0'), \
+		 snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
+				  (sockdir), \
+				  (port)))
+#endif
 
 /*
  * The maximum workable length of a socket path is what will fit into
diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index 9f48a58aed..47c1868149 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -56,3 +56,11 @@
 #else
 #define PGDLLEXPORT
 #endif
+
+
+/*
+ * On Windows, there is no good standard location for AF_UNIX sockets, and
+ * many builds of Windows don't support them yet, so don't create one by
+ * default.
+ */
+#undef DEFAULT_PGSOCKET_DIR
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 79323114e4..1b5ddc92ff 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -1065,7 +1065,7 @@ connectOptions2(PGconn *conn)
 		{
 			if (ch->host)
 				free(ch->host);
-#ifdef HAVE_UNIX_SOCKETS
+#if defined(HAVE_UNIX_SOCKETS) && defined(DEFAULT_PGSOCKET_DIR)
 			ch->host = strdup(DEFAULT_PGSOCKET_DIR);
 			ch->type = CHT_UNIX_SOCKET;
 #else
@@ -6853,6 +6853,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
 	/* 'localhost' matches pghost of '' or the default socket directory */
 	if (hostname == NULL || hostname[0] == '\0')
 		hostname = DefaultHost;
+#ifdef DEFAULT_PGSOCKET_DIR
 	else if (is_absolute_path(hostname))
 
 		/*
@@ -6861,6 +6862,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
 		 */
 		if (strcmp(hostname, DEFAULT_PGSOCKET_DIR) == 0)
 			hostname = DefaultHost;
+#endif
 
 	if (port == NULL || port[0] == '\0')
 		port = DEF_PGPORT_STR;
-- 
2.22.0