From 861245e941f9286df4d7e750a2c26b85b5c8c4ee Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Fri, 8 Aug 2025 01:18:40 +0000 Subject: [PATCH] configure.ac: fix res_ninit detection For what I'm sure are very good reasons, libc implementations like to export the symbol as `__res_ninit` and have `res_ninit` as a `#define`. https://sourceware.org/git/?p=glibc.git;a=blob;f=resolv/resolv.h;h=b8a0f66a;hb=HEAD#l228 This means a naive check for the symbol always fails. --- configure.ac | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index da7a384..96269c1 100644 --- a/configure.ac +++ b/configure.ac @@ -94,9 +94,6 @@ AC_SEARCH_LIBS(inet_ntop, resolv nsl, AC_SEARCH_LIBS(getaddrinfo, resolv, AC_DEFINE(HAVE_GETADDRINFO, 1, [Define to 1 if you have the getaddrinfo() function.])) -AC_SEARCH_LIBS(res_ninit, resolv, - AC_DEFINE(HAVE_RES_NINIT, 1, - [Define to 1 if you have the res_ninit() function.])) AC_SEARCH_LIBS(res_setservers, resolv bind, AC_DEFINE(HAVE_RES_SETSERVERS, 1, [Define to 1 if you have the res_setservers() function.])) @@ -106,6 +103,41 @@ AC_SEARCH_LIBS(getopt_long, iberty, AC_HEADER_RESOLV +# AC_SEARCH_LIBS doesn't work for this check because glibc doesn't +# actually export the expected symbol, there's a #define in `resolv.h` +# that points to the real symbol. +AC_CACHE_CHECK( + [for library containing res_ninit], + [ac_cv_search_res_ninit], + [ + saved_LIBS=$LIBS + AC_LANG_CONFTEST([AC_LANG_PROGRAM([@%:@include ], [res_ninit(NULL);])]) + for ac_lib in '' resolv + do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + AC_LINK_IFELSE([], [AS_VAR_SET([ac_cv_search_res_ninit], [$ac_res])]) + AS_VAR_SET_IF([ac_cv_search_res_ninit], [break]) + done + AS_VAR_SET_IF([ac_cv_search_res_ninit], [], [AS_VAR_SET([ac_cv_search_res_ninit], [no])]) + rm conftest.$ac_ext + LIBS=$saved_LIBS + ] +) +AS_IF([test "$ac_cv_search_res_ninit" != no], + [ + test "$ac_cv_search_res_ninit" = "none required" || LIBS="$ac_res $LIBS" + AC_DEFINE( + HAVE_RES_NINIT, 1, + [Define to 1 if you have the res_ninit() function.] + ) + ] +) + # # Check for types #