As of Windows 10 version 1803, Unix-domain sockets are supported on
Windows. But it's not automatically detected by configure because it
looks for struct sockaddr_un and Windows doesn't define that. So we
just make our own definition on Windows and override the configure
result.
Set DEFAULT_PGSOCKET_DIR to empty on Windows so by default no
Unix-domain socket is used, because there is no good standard
location.
In pg_upgrade, we have to do some extra tweaking to preserve the
existing behavior of not using Unix-domain sockets on Windows. Adding
support would be desirable, but it needs further work, in particular a
way to select whether to use Unix-domain sockets from the command-line
or with a run-time test.
The pg_upgrade test script needs a fix. The previous code passed
"localhost" to postgres -k, which only happened to work because
Windows used to ignore the -k argument value altogether. We instead
need to pass an empty string to get the desired effect.
The test suites will continue to not use Unix-domain sockets on
Windows. This requires a small tweak in pg_regress.c. The TAP tests
don't need to be changed because they decide by the operating system
rather than HAVE_UNIX_SOCKETS.
Reviewed-by: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Discussion: https://www.postgresql.org/message-id/flat/
54bde68c-d134-4eb8-5bd3-
8af33b72a010@2ndquadrant.com
# PGAC_STRUCT_SOCKADDR_UN
# -----------------------
-# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.
+# If `struct sockaddr_un' exists, define HAVE_STRUCT_SOCKADDR_UN.
+# If it is missing then one could define it.
# (Requires test for <sys/un.h>!)
AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN],
-[AC_CHECK_TYPE([struct sockaddr_un], [AC_DEFINE(HAVE_UNIX_SOCKETS, 1, [Define to 1 if you have unix sockets.])], [],
+[AC_CHECK_TYPES([struct sockaddr_un], [], [],
[#include <sys/types.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
"
if test "x$ac_cv_type_struct_sockaddr_un" = xyes; then :
-$as_echo "#define HAVE_UNIX_SOCKETS 1" >>confdefs.h
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_SOCKADDR_UN 1
+_ACEOF
+
fi
void
get_sock_dir(ClusterInfo *cluster, bool live_check)
{
-#ifdef HAVE_UNIX_SOCKETS
+#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
/*
* sockdir and port were added to postmaster.pid in PG 9.1. Pre-9.1 cannot
* default
*/
cluster->sockdir = NULL;
-#else /* !HAVE_UNIX_SOCKETS */
+#else /* !HAVE_UNIX_SOCKETS || WIN32 */
cluster->sockdir = NULL;
#endif
}
socket_string[0] = '\0';
-#ifdef HAVE_UNIX_SOCKETS
+#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
/* prevent TCP/IP connections, restrict socket access */
strcat(socket_string,
" -c listen_addresses='' -c unix_socket_permissions=0700");
case $testhost in
MINGW*)
LISTEN_ADDRESSES="localhost"
+ PG_REGRESS_SOCKET_DIR=""
PGHOST=localhost
;;
*)
LISTEN_ADDRESSES=""
# Select a socket directory. The algorithm is from the "configure"
# script; the outcome mimics pg_regress.c:make_temp_sockdir().
- PGHOST=$PG_REGRESS_SOCK_DIR
- if [ "x$PGHOST" = x ]; then
+ if [ x"$PG_REGRESS_SOCKET_DIR" = x ]; then
set +e
dir=`(umask 077 &&
mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null`
fi
fi
set -e
- PGHOST=$dir
- trap 'rm -rf "$PGHOST"' 0
+ PG_REGRESS_SOCKET_DIR=$dir
+ trap 'rm -rf "$PG_REGRESS_SOCKET_DIR"' 0
trap 'exit 3' 1 2 13 15
fi
+ PGHOST=$PG_REGRESS_SOCKET_DIR
;;
esac
-POSTMASTER_OPTS="-F -c listen_addresses=\"$LISTEN_ADDRESSES\" -k \"$PGHOST\""
+POSTMASTER_OPTS="-F -c listen_addresses=\"$LISTEN_ADDRESSES\" -k \"$PG_REGRESS_SOCKET_DIR\""
export PGHOST
# don't rely on $PWD here, as old shells don't set it
* ----------------------------------------------------------------
*/
+#ifdef HAVE_STRUCT_SOCKADDR_UN
+#define HAVE_UNIX_SOCKETS 1
+#endif
+
/*
* Invert the sign of a qsort-style comparison result, ie, exchange negative
* and positive integer values, being careful not to get the wrong answer
/* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */
#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
+/* Define to 1 if the system has the type `struct sockaddr_un'. */
+#undef HAVE_STRUCT_SOCKADDR_UN
+
/* Define to 1 if `tm_zone' is a member of `struct tm'. */
#undef HAVE_STRUCT_TM_TM_ZONE
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
-/* Define to 1 if you have unix sockets. */
-#undef HAVE_UNIX_SOCKETS
-
/* Define to 1 if you have the `unsetenv' function. */
#undef HAVE_UNSETENV
#define EXEC_BACKEND
#endif
-/*
- * Disable UNIX sockets for certain operating systems.
- */
-#if defined(WIN32)
-#undef HAVE_UNIX_SOCKETS
-#endif
-
/*
* USE_POSIX_FADVISE controls whether Postgres will attempt to use the
* posix_fadvise() kernel call. Usually the automatic configure tests are
* 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.
+ *
+ * This is done by default on Windows because there is no good standard
+ * location for AF_UNIX sockets and many installations on Windows don't
+ * support them yet.
*/
+#ifndef WIN32
#define DEFAULT_PGSOCKET_DIR "/tmp"
+#else
+#define DEFAULT_PGSOCKET_DIR ""
+#endif
/*
* This is the default event source for Windows event log.
#else
#define PGDLLEXPORT
#endif
+
+/*
+ * Windows headers don't define this structure, but you can define it yourself
+ * to use the functionality.
+ */
+struct sockaddr_un
+{
+ unsigned short sun_family;
+ char sun_path[108];
+};
+#define HAVE_STRUCT_SOCKADDR_UN 1
* remove the directory. Ignore errors; leaking a temporary directory is
* unimportant. This can run from a signal handler. The code is not
* acceptable in a Windows signal handler (see initdb.c:trapsig()), but
- * Windows is not a HAVE_UNIX_SOCKETS platform.
+ * on Windows, pg_regress does not use Unix sockets.
*/
static void
remove_temp(void)
atexit(stop_postmaster);
-#ifndef HAVE_UNIX_SOCKETS
- /* no unix domain sockets available, so change default */
+#if !defined(HAVE_UNIX_SOCKETS) || defined(WIN32)
+ /*
+ * No Unix-domain sockets available, so change default. For now, we also
+ * don't use them on Windows, even if the build supports them. (See
+ * comment at remove_temp() for a reason.)
+ */
hostname = "localhost";
#endif
HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN => undef,
HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY => undef,
HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN => undef,
+ HAVE_STRUCT_SOCKADDR_UN => undef,
HAVE_STRUCT_TM_TM_ZONE => undef,
HAVE_SYNC_FILE_RANGE => undef,
HAVE_SYMLINK => 1,
HAVE_UINT8 => undef,
HAVE_UNION_SEMUN => undef,
HAVE_UNISTD_H => 1,
- HAVE_UNIX_SOCKETS => undef,
HAVE_UNSETENV => undef,
HAVE_USELOCALE => undef,
HAVE_UUID_BSD => undef,