postgres.git / summary / log / commit / refs
commit 87deb55a4723e3ee00e4324fca684c26cfa17cc6
Author: Noah Misch <noah@leadboat.com>
Date: Sun Nov 08 22:28:53 2015 +0000
First released in: 9.6.0, 9.1.20, 9.2.15, 9.3.11, 9.4.6, 9.5.0
Don't connect() to a wildcard address in test_postmaster_connection().
At least OpenBSD, NetBSD, and Windows don't support it. This repairs
pg_ctl for listen_addresses='0.0.0.0' and listen_addresses='::'. Since
pg_ctl prefers to test a Unix-domain socket, Windows users are most
likely to need this change. Back-patch to 9.1 (all supported versions).
This could change pg_ctl interaction with loopback-interface firewall
rules. Therefore, in 9.4 and earlier (released branches), activate the
change only on known-affected platforms.
Reported (bug #13611) and designed by Kondo Yuta.
src/bin/pg_ctl/pg_ctl.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 87c9bac50bf..6a44f2972ef 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -623,9 +623,22 @@ test_postmaster_connection(pgpid_t pm_pid, bool do_checkpoint)
return PQPING_NO_ATTEMPT;
}
- /* If postmaster is listening on "*", use localhost */
+ /*
+ * Map listen-only addresses to counterparts usable
+ * for establishing a connection. connect() to "::"
+ * or "0.0.0.0" is not portable to OpenBSD 5.0 or to
+ * Windows Server 2008, and connect() to "::" is
+ * additionally not portable to NetBSD 6.0. (Cygwin
+ * does handle both addresses, though.)
+ */
if (strcmp(host_str, "*") == 0)
strcpy(host_str, "localhost");
+#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(WIN32)
+ else if (strcmp(host_str, "0.0.0.0") == 0)
+ strcpy(host_str, "127.0.0.1");
+ else if (strcmp(host_str, "::") == 0)
+ strcpy(host_str, "::1");
+#endif
/*
* We need to set connect_timeout otherwise on Windows
[parent: 03ee6591dd30]