cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Detection of HAVE_GETADDRINFO_THREADSAFE in configure

From: Mason <mpeg.blue_at_free.fr>
Date: Thu, 22 Mar 2012 11:09:44 +0100

Mason wrote:

> In the configure script, the program to detect whether
> getaddrinfo is thread-safe is (pre-processor directives
> omitted for brevity):
>
> int main (void)
> {
> #ifdef h_errno
> return 0;
> #else
> force compilation error
> #endif
> }
>
> There are two problems with this strategy.
>
> 1) In the latest POSIX standard (Issue 7), h_errno has been removed
> altogether.
>
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netdb.h.html
>
>> The obsolescent h_errno external integer, and the obsolescent gethostbyaddr(),
>> and gethostbyname() functions are removed, along with the HOST_NOT_FOUND,
>> NO_DATA, NO_RECOVERY, and TRY_AGAIN macros.
>
> 2) In the previous POSIX standard (Issue 6), h_errno existed,
> but it didn't have to be a macro.
>
> http://pubs.opengroup.org/onlinepubs/009695399/basedefs/netdb.h.html
>
>> When the <netdb.h> header is included, h_errno shall be available as a modifiable
>> lvalue of type int. It is unspecified whether h_errno is a macro or an identifier
>> declared with external linkage.
>
> Thus if h_errno is an identifier declared with external linkage,
> the macro test will fail.
>
>
> Now what?
>
> getaddrinfo is thread-safe /by definition/
> (both in Issue 6 and in Issue 7)
>
> http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
>
>> The freeaddrinfo() and getaddrinfo() functions shall be thread-safe.
>
> Maybe it would be sufficient to test for the POSIX feature macro?
>
> http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html
>
> int main (void)
> {
> #if _POSIX_C_SOURCE >= 200112L (or 199506L ??)
> return 0;
> #else
> force compilation error
> #endif
> }

Did someone get a chance to ponder this issue?

Thinking it over, I don't think it's a good idea to test for
POSIX feature macros: In the case of third-party network
libraries, the environment may or may not be POSIX-compliant,
while the library may or may not be POSIX-compliant. The two
are mostly unrelated.

The current behavior is to set tst_tsafe_getaddrinfo to "yes"
or "no" for known host_os (when it is known /a priori/ whether
getaddrinfo is thread-safe or not)and fall back to the h_errno
test for platforms that have not been explicitly enumerated.

Since the h_errno test is irrelevant, I propose removing it
altogether. I propose that getaddrinfo should be considered
thread-safe /by default/ (because the POSIX function is
defined as such) and explicitly marked "not thread-safe" for
platforms where it is the case.

Below is the comment written for getaddrinfo.

dnl CURL_CHECK_FUNC_GETADDRINFO
dnl -------------------------------------------------
dnl Verify if getaddrinfo is available, prototyped, can
dnl be compiled and seems to work. If all of these are
dnl true, and usage has not been previously disallowed
dnl with shell variable curl_disallow_getaddrinfo, then
dnl HAVE_GETADDRINFO will be defined. Additionally when
dnl HAVE_GETADDRINFO gets defined this will also attempt
dnl to find out if getaddrinfo happens to be threadsafe,
dnl defining HAVE_GETADDRINFO_THREADSAFE when true.

Proposed patch (untested, as an illustration)

--- curl-functions.m4.orig 2011-11-04 23:32:57.000000000 +0100
+++ curl-functions.m4 2012-03-22 11:02:16.984375000 +0100
@@ -2026,7 +2026,7 @@
   tst_compi_getaddrinfo="unknown"
   tst_works_getaddrinfo="unknown"
   tst_allow_getaddrinfo="unknown"
- tst_tsafe_getaddrinfo="unknown"
+ tst_tsafe_getaddrinfo="yes"
   #
   AC_MSG_CHECKING([if getaddrinfo can be linked])
   AC_LINK_IFELSE([
@@ -2196,18 +2196,6 @@
         tst_tsafe_getaddrinfo="yes"
         ;;
     esac
- if test "$tst_tsafe_getaddrinfo" = "unknown"; then
- CURL_CHECK_DEF_CC([h_errno], [
- $curl_includes_ws2tcpip
- $curl_includes_sys_socket
- $curl_includes_netdb
- ], [silent])
- if test "$curl_cv_have_def_h_errno" = "no"; then
- tst_tsafe_getaddrinfo="no"
- fi
- fi
- if test "$tst_tsafe_getaddrinfo" = "unknown"; then
- tst_tsafe_getaddrinfo="yes"
     fi
     AC_MSG_RESULT([$tst_tsafe_getaddrinfo])
     if test "$tst_tsafe_getaddrinfo" = "yes"; then

Comments? Thoughts?

-- 
Regards.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2012-03-22