From 9ca09c6f6d59182cdc0c2a28912490471626038a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 7 Aug 2019 15:44:19 +0200 Subject: [PATCH v6 1/5] Enable Unix-domain sockets support on Windows 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. Also set DEFAULT_PGSOCKET_DIR to empty on Windows so by default no Unix-domain socket is used, because there is no good standard location. --- config/c-library.m4 | 5 +++-- configure | 5 ++++- src/include/c.h | 4 ++++ src/include/pg_config.h.in | 6 +++--- src/include/pg_config_manual.h | 15 ++++++++------- src/include/port/win32.h | 11 +++++++++++ src/tools/msvc/Solution.pm | 2 +- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/config/c-library.m4 b/config/c-library.m4 index d9a31d7664..163ad5742d 100644 --- a/config/c-library.m4 +++ b/config/c-library.m4 @@ -102,10 +102,11 @@ AC_DEFUN([PGAC_UNION_SEMUN], # 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 !) 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 #ifdef HAVE_SYS_UN_H #include diff --git a/configure b/configure index 37aa82dcd4..8b770cb67f 100755 --- a/configure +++ b/configure @@ -14061,7 +14061,10 @@ ac_fn_c_check_type "$LINENO" "struct sockaddr_un" "ac_cv_type_struct_sockaddr_un " 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 diff --git a/src/include/c.h b/src/include/c.h index d10b9812fb..9562569d2a 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1077,6 +1077,10 @@ extern void ExceptionalCondition(const char *conditionName, * ---------------------------------------------------------------- */ +#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 diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 60dcf42974..8449e02123 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -605,6 +605,9 @@ /* 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 @@ -689,9 +692,6 @@ /* Define to 1 if you have the 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 diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h index b4ce53300b..4ee0efaed8 100644 --- a/src/include/pg_config_manual.h +++ b/src/include/pg_config_manual.h @@ -122,13 +122,6 @@ */ #define ALIGNOF_BUFFER 32 -/* - * Disable UNIX sockets for certain operating systems. - */ -#if defined(WIN32) -#undef HAVE_UNIX_SOCKETS -#endif - /* * Define this if your operating system supports link() */ @@ -196,8 +189,16 @@ * 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. diff --git a/src/include/port/win32.h b/src/include/port/win32.h index bb2f7540b3..c280c131c0 100644 --- a/src/include/port/win32.h +++ b/src/include/port/win32.h @@ -56,3 +56,14 @@ #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 diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 8412ef298e..f90cdfe887 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -371,6 +371,7 @@ sub GenerateFiles 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, @@ -399,7 +400,6 @@ sub GenerateFiles HAVE_UINTPTR_T => undef, HAVE_UNION_SEMUN => undef, HAVE_UNISTD_H => 1, - HAVE_UNIX_SOCKETS => undef, HAVE_UNSETENV => undef, HAVE_USELOCALE => undef, HAVE_UTIME => 1, base-commit: 997563dfcb2501a7a199589cd6f15f2bb8af3d04 -- 2.25.0