From 3371b658c3c38e6ce5b945e09fb4fce6f7b01809 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Tue, 6 Feb 2024 11:56:37 +0100 Subject: [PATCH 1/2] Refactor utsname.domainname struct member Autoconf check Autoconf's AC_CHECK_MEMBERS macro (available since Autoconf 2.50) can be used instead of the compile check. This was originally implemented for IRIX compatibility, when Autoconf 2.13 didn't have the struct members checking macro yet. Macro by default here defines the HAVE_STRUCT_UTSNAME_DOMAINNAME symbol. --- UPGRADING.INTERNALS | 1 + ext/posix/config.m4 | 21 +++++---------------- ext/posix/posix.c | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 99e42a445c291..d3613efbc63a3 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -50,6 +50,7 @@ PHP 8.4 INTERNALS UPGRADE NOTES - The configure option --with-zlib-dir has been removed. - COOKIE_IO_FUNCTIONS_T symbol has been removed (use cookie_io_functions_t). - HAVE_SOCKADDR_UN_SUN_LEN symbol renamed to HAVE_STRUCT_SOCKADDR_UN_SUN_LEN. + - HAVE_UTSNAME_DOMAINNAME symbol renamed to HAVE_STRUCT_UTSNAME_DOMAINNAME. - PHP_CHECK_IN_ADDR_T M4 macro and 'in_addr_t' fallback definition to 'u_int' removed (use AC_CHECK_TYPES Autoconf macro instead). - HAVE_ODBC2 symbol has been removed in ext/odbc. diff --git a/ext/posix/config.m4 b/ext/posix/config.m4 index 72deacc42ed83..8d5ad1ce69f8b 100644 --- a/ext/posix/config.m4 +++ b/ext/posix/config.m4 @@ -36,21 +36,10 @@ int main(int argc, char *argv[]) AC_MSG_RESULT([no, cannot detect working ttyname_r() when cross compiling. posix_ttyname() will be thread-unsafe]) ]) - AC_CACHE_CHECK([for utsname.domainname], ac_cv_have_utsname_domainname, [ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #ifndef _GNU_SOURCE - #define _GNU_SOURCE - #endif - #include - ]],[[ - return sizeof(((struct utsname *)0)->domainname); - ]])],[ - ac_cv_have_utsname_domainname=yes - ],[ - ac_cv_have_utsname_domainname=no - ]) + AC_CHECK_MEMBERS([struct utsname.domainname],,,[ + #ifndef _GNU_SOURCE + #define _GNU_SOURCE + #endif + #include ]) - if test "$ac_cv_have_utsname_domainname" = yes; then - AC_DEFINE(HAVE_UTSNAME_DOMAINNAME, 1, [Whether struct utsname has domainname]) - fi fi diff --git a/ext/posix/posix.c b/ext/posix/posix.c index 8c111ea5acf53..63b24c74b302f 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -358,7 +358,7 @@ PHP_FUNCTION(posix_uname) add_assoc_string(return_value, "version", u.version); add_assoc_string(return_value, "machine", u.machine); -#if defined(_GNU_SOURCE) && !defined(DARWIN) && defined(HAVE_UTSNAME_DOMAINNAME) +#if defined(_GNU_SOURCE) && !defined(DARWIN) && defined(HAVE_STRUCT_UTSNAME_DOMAINNAME) add_assoc_string(return_value, "domainname", u.domainname); #endif } From 7262733bdcf8447f8b9908b4559f1e96173912bd Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Tue, 6 Feb 2024 21:46:41 +0100 Subject: [PATCH 2/2] Remove also redundant DARWIN symbol check Checking in the configuration step also correctly detects missing struct member on Darwin systems (macos...). --- ext/posix/posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/posix/posix.c b/ext/posix/posix.c index 63b24c74b302f..aa17cc95d8046 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -358,7 +358,7 @@ PHP_FUNCTION(posix_uname) add_assoc_string(return_value, "version", u.version); add_assoc_string(return_value, "machine", u.machine); -#if defined(_GNU_SOURCE) && !defined(DARWIN) && defined(HAVE_STRUCT_UTSNAME_DOMAINNAME) +#if defined(_GNU_SOURCE) && defined(HAVE_STRUCT_UTSNAME_DOMAINNAME) add_assoc_string(return_value, "domainname", u.domainname); #endif }