On Sun, Aug 14, 2022 at 6:07 AM Tom Lane <t...@sss.pgh.pa.us> wrote:
> Thomas Munro <thomas.mu...@gmail.com> writes:
> > I tried to figure out how to get rid of
> > PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS, but there we're into genuine
> > non-standard cross-platform differences.
>
> Right.  I don't think it's worth sweating over.

I managed to get rid of four of these probes.  Some were unused, and
one could be consolidated into another leaving just one probe of this
ilk.

1.  src/common/ip.c already made a leap by assuming that if you have
ss_len then you must have sun_len.  We might as well change that to be
driven by the presence of sa_len instead.  That leap is fine: if you
have one, you have them all, and sa_len has the advantage of a stable
name across systems that have it (unlike ss_len, which AIX calls
__ss_len, requiring more configure gloop).

2.  src/backend/libpq/ifaddr.c only needs to know if you have sa_len.
This code is only used on AIX, so we could hard-wire it in theory, but
it's good to keep it general so you can still compile and test it on
systems without sa_len (mostly Linux).
From a4cc14b0de234102bfe6312e793d515797fa572e Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.mu...@gmail.com>
Date: Fri, 19 Aug 2022 16:16:34 +1200
Subject: [PATCH] Remove configure probes for sockaddr_storage members.

Previously we had to deal with implementation details of struct
sockaddr_storage in various replacement code, but now that we're able to
rely on newer standard facilities we don't need to do that.

We still need to keep a probe for sockaddr's sa_len, to use in a couple
of places.  In one place we previously assumed that the presence of
ss_len implied the presence sun_len, but it's no less justifiable to
test for sa_len there, since they all go together.
---
 config/c-library.m4        | 18 +++++---------
 configure                  | 48 --------------------------------------
 configure.ac               |  2 +-
 src/common/ip.c            |  2 +-
 src/include/libpq/pqcomm.h | 13 -----------
 src/include/pg_config.h.in | 12 ----------
 src/tools/msvc/Solution.pm |  4 ----
 7 files changed, 8 insertions(+), 91 deletions(-)

diff --git a/config/c-library.m4 b/config/c-library.m4
index 58453c4f76..c1dd804679 100644
--- a/config/c-library.m4
+++ b/config/c-library.m4
@@ -73,20 +73,14 @@ AC_DEFUN([PGAC_UNION_SEMUN],
 ])])# PGAC_UNION_SEMUN
 
 
-# PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
-# --------------------------------------
-# Check the members of `struct sockaddr_storage'.  We need to know about
-# ss_family and ss_len.  (Some platforms follow RFC 2553 and call them
-# __ss_family and __ss_len.)  We also check struct sockaddr's sa_len.
-AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS],
-[AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family,
-		   struct sockaddr_storage.__ss_family,
-		   struct sockaddr_storage.ss_len,
-		   struct sockaddr_storage.__ss_len,
-		   struct sockaddr.sa_len], [], [],
+# PGAC_STRUCT_SOCKADDR_MEMBERS
+# ----------------------------
+# Check if struct sockaddr and subtypes have 4.4BSD-style length.
+AC_DEFUN([PGAC_STRUCT_SOCKADDR_SA_LEN],
+[AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [],
 [#include <sys/types.h>
 #include <sys/socket.h>
-])])# PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
+])])# PGAC_STRUCT_SOCKADDR_MEMBERS
 
 
 # PGAC_TYPE_LOCALE_T
diff --git a/configure b/configure
index b28fccbc47..4bd050008b 100755
--- a/configure
+++ b/configure
@@ -14990,54 +14990,6 @@ _ACEOF
 
 fi
 
-ac_fn_c_check_member "$LINENO" "struct sockaddr_storage" "ss_family" "ac_cv_member_struct_sockaddr_storage_ss_family" "#include <sys/types.h>
-#include <sys/socket.h>
-
-"
-if test "x$ac_cv_member_struct_sockaddr_storage_ss_family" = xyes; then :
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
-_ACEOF
-
-
-fi
-ac_fn_c_check_member "$LINENO" "struct sockaddr_storage" "__ss_family" "ac_cv_member_struct_sockaddr_storage___ss_family" "#include <sys/types.h>
-#include <sys/socket.h>
-
-"
-if test "x$ac_cv_member_struct_sockaddr_storage___ss_family" = xyes; then :
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY 1
-_ACEOF
-
-
-fi
-ac_fn_c_check_member "$LINENO" "struct sockaddr_storage" "ss_len" "ac_cv_member_struct_sockaddr_storage_ss_len" "#include <sys/types.h>
-#include <sys/socket.h>
-
-"
-if test "x$ac_cv_member_struct_sockaddr_storage_ss_len" = xyes; then :
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
-_ACEOF
-
-
-fi
-ac_fn_c_check_member "$LINENO" "struct sockaddr_storage" "__ss_len" "ac_cv_member_struct_sockaddr_storage___ss_len" "#include <sys/types.h>
-#include <sys/socket.h>
-
-"
-if test "x$ac_cv_member_struct_sockaddr_storage___ss_len" = xyes; then :
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN 1
-_ACEOF
-
-
-fi
 ac_fn_c_check_member "$LINENO" "struct sockaddr" "sa_len" "ac_cv_member_struct_sockaddr_sa_len" "#include <sys/types.h>
 #include <sys/socket.h>
 
diff --git a/configure.ac b/configure.ac
index dd368290a6..6ff294d405 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1614,7 +1614,7 @@ PGAC_C_COMPUTED_GOTO
 PGAC_STRUCT_TIMEZONE
 PGAC_UNION_SEMUN
 AC_CHECK_TYPES(socklen_t, [], [], [#include <sys/socket.h>])
-PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
+PGAC_STRUCT_SOCKADDR_SA_LEN
 
 PGAC_TYPE_LOCALE_T
 
diff --git a/src/common/ip.c b/src/common/ip.c
index 0149d07ae7..9b611cdc8c 100644
--- a/src/common/ip.c
+++ b/src/common/ip.c
@@ -227,7 +227,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
 	 * something with it.  To suppress the warning, clamp the struct size to
 	 * what will fit in sun_len.
 	 */
-#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
 	unp->sun_len = Min(sizeof(struct sockaddr_un),
 					   ((size_t) 1 << (sizeof(unp->sun_len) * BITS_PER_BYTE)) - 1);
 #endif
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index 7e2f1495f3..fcf68df39b 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -21,19 +21,6 @@
 #include <netdb.h>
 #include <netinet/in.h>
 
-#ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
-#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
-#define ss_family __ss_family
-#else
-#error struct sockaddr_storage does not provide an ss_family member
-#endif
-#endif
-
-#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
-#define ss_len __ss_len
-#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
-#endif
-
 typedef struct
 {
 	struct sockaddr_storage addr;
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 26eb6a2dfe..109776e465 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -442,18 +442,6 @@
 /* Define to 1 if `sa_len' is a member of `struct sockaddr'. */
 #undef HAVE_STRUCT_SOCKADDR_SA_LEN
 
-/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */
-#undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
-
-/* Define to 1 if `ss_len' is a member of `struct sockaddr_storage'. */
-#undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
-
-/* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */
-#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
-
-/* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */
-#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
-
 /* Define to 1 if `tm_zone' is a member of `struct tm'. */
 #undef HAVE_STRUCT_TM_TM_ZONE
 
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index fead5c2a72..a3da3f748a 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -343,10 +343,6 @@ sub GenerateFiles
 		HAVE_STRUCT_CMSGCRED                     => undef,
 		HAVE_STRUCT_OPTION                       => undef,
 		HAVE_STRUCT_SOCKADDR_SA_LEN              => undef,
-		HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY   => 1,
-		HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN      => undef,
-		HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY => undef,
-		HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN    => undef,
 		HAVE_STRUCT_TM_TM_ZONE                   => undef,
 		HAVE_SYNC_FILE_RANGE                     => undef,
 		HAVE_SYNCFS                              => undef,
-- 
2.36.1

Reply via email to