From c817dfc0ec2aead25e6fcd33f9e89bd55cb2c0b1 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 7 Aug 2019 15:44:19 +0200 Subject: [PATCH v2 1/7] 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. --- config/c-library.m4 | 5 +++-- configure | 5 ++++- src/include/c.h | 11 +++++++++++ src/include/pg_config.h.in | 6 +++--- src/include/pg_config.h.win32 | 6 +++--- src/include/pg_config_manual.h | 7 ------- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/config/c-library.m4 b/config/c-library.m4 index 6f2b0fbb4e..1469b07d2f 100644 --- a/config/c-library.m4 +++ b/config/c-library.m4 @@ -121,10 +121,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 7a6bfc2339..6e87537be3 100755 --- a/configure +++ b/configure @@ -14135,7 +14135,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 2a082afab1..434c403269 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1263,6 +1263,17 @@ extern unsigned long long strtoull(const char *str, char **endptr, int base); #define NON_EXEC_STATIC static #endif +#ifdef HAVE_STRUCT_SOCKADDR_UN +#define HAVE_UNIX_SOCKETS 1 +#elif defined(WIN32) +struct sockaddr_un +{ + unsigned short sun_family; + char sun_path[108]; +}; +#define HAVE_UNIX_SOCKETS 1 +#endif + /* /port compatibility functions */ #include "port.h" diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 512213aa32..e75c090f85 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -594,6 +594,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 @@ -682,9 +685,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.h.win32 b/src/include/pg_config.h.win32 index 2d903c82b8..b947a9fbde 100644 --- a/src/include/pg_config.h.win32 +++ b/src/include/pg_config.h.win32 @@ -463,6 +463,9 @@ /* Define to 1 if `__ss_len' is 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 member of `struct tm'. */ /* #undef HAVE_STRUCT_TM_TM_ZONE */ @@ -530,9 +533,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H 1 -/* 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 743401cb96..65d20d44b3 100644 --- a/src/include/pg_config_manual.h +++ b/src/include/pg_config_manual.h @@ -109,13 +109,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() */ base-commit: 66bde49d96a9ddacc49dcbdf1b47b5bd6e31ead5 -- 2.22.0