cURL / Mailing Lists / curl-library / Single Mail


Re: Detection of HAVE_GETADDRINFO_THREADSAFE in configure

From: Mason <>
Date: Tue, 27 Mar 2012 17:27:37 +0200

Yang Tse wrote:

> Mason wrote:
>> Yang Tse wrote:
>>> Do you have a system on which current git version detection of
>>> getaddrinfo() thread-safeness is wrong?
>> It doesn't work with lwip, where, in the typical configuration,
>> 1) gethostbyname is not thread-safe
>> 2) getaddrinfo is thread-safe (AFAICT)
>> 3) netdb.h declares extern int h_errno; (as permitted by POSIX)
> Given that current LWIP git version [1] lwip_getaddrinfo()
> implementation is using atoi() and that lwip_getaddrinfo() header does
> not state that it is thread safe, and given that [1]
> lwip_gethostbyname_r() header comment states that "Thread-safe variant
> of lwip_gethostbyname: instead of using a static buffer, this function
> takes buffer and errno pointers as arguments and uses these for the
> result." I can only conclude that:
> lwip_getaddrinfo() is not thread-safe and that lwip_gethostbyname_r()
> is thtread-safe.

I do not follow your assertion that "lwip_getaddrinfo is not
thread-safe because it uses atoi".

POSIX provides an exhaustive list of "not thread-safe" functions.
(The exact wording is:
"All functions defined by this volume of IEEE Std 1003.1-2001 [sic]
shall be thread-safe, except that the following functions need not
be thread-safe.")

Neither atoi nor strtol are mentioned in the list, therefore atoi
and strtol must be thread-safe on POSIX-compliant implementations
(otherwise it's an implementation bug, which may happen).

Are you saying atoi is not thread-safe because it might call
isspace, which might be affected by setlocale?

>> I'll take a look at the getaddrinfo code in FreeBSD 4 to understand
>> why libcurl declare this implementation not thread-safe. Do you know,
>> off-hand?
> Implementation of getaddrinfo() in FreeBSD 5.4 and older versions is
> not thread-safe [2]. FreeBSD 5.5 and newer versions have a thread-safe
> getaddrinfo().

Relevant bug report (for my own reference)

> Up to now lwip_gethostbyname_r() is the right choice and not defining
> HAVE_GETADDRINFO_THREADSAFE the proper result for the getaddrinfo()
> thread-safeness check when using LWIP.

IIUC, libcurl prefers a thread-safe getaddrinfo over gethostbyname_r, right?

> If in any future things change we'll adapt as required when the moment arrives.

Roger that.

> [1];a=blob;f=src/api/netdb.c;h=6a4bac561ce65ee0f599608705cdaae5174ef93e;hb=HEAD
> [2]

List admin:
Received on 2012-03-27