cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: hostthre.c on POSIX

From: Jamie Lokier <jamie_at_shareable.org>
Date: Fri, 22 Jan 2010 21:25:21 +0000

Constantine Sapuntzakis wrote:
> Attached is the new hostthre patch which should apply against CVS.
> Now uses HAVE_GETADDRINFO_THREADSAFE in Curl_ipv4_resolve.
> Added infof into Curl_getaddrinfo for ipv4-only.

+ # POSIX - if the resolver has gethostbyname_r, then it should be
+ # thread-safe.
+ #
+ # getaddrinfo() is thread safe on most Linuxes worth caring about, OS X
+ # Tiger or above, FreeBSD 5.2 or above, NetBSD 4.0 (unreleased) and above,
+ # and DragonflyBSD (not sure which version it was added in.) That's an
+ # incomplete support table.
+ #
+ # To be safe, be generally exclusive and disable threaded resolve when we
+ # aren't entirely sure.
+ if test x$ac_cv_func_gethostbyname_r = xyes; then
+ have_threadsafe_resolver=yes
+ elif test x$ac_cv_func_getaddrinfo = xyes; then
+ case "$host" in
+ # Note: there was no darwin1, so simplify the expression for darwin{9,10}.
+ *-freebsd5.[[23456789]] | *-freebsd[[678]] | *-netbsd4.* | \
+ *-apple-darwin[[19]]* | *-dragonflybsd* | *-linux* )
+ have_threadsafe_resolver=yes
+ ;;
+ esac
+ fi
+ if test x$have_threadsafe_resolver = xyes && \
+ test x$acx_pthread_ok = xyes; then
+ curl_asynch_msg="yes (pthreads)"
+ THREADED_RESOLVE_CHECK_PASS=yes
+ fi

Few notes:

- gethostbyname_r is not thread safe on all systems :-(

  http://marc.info/?l=freeradius-devel&m=101551160406291&w=2

- gethostbyname/gethostbyaddr are reported to be thread-safe on
  32/64-bit Windows, AIX 4.3 and HP-UX 11. They use per-thread storage
  for the returned structure.

- DragonFly: The test for DragonFly BSD is unsafe, because it sets
  have_threadsafe_resolver=yes on versions of DragonFly where it is
  not safe. If you don't know what version, there is no safe version.

- FreeBSD: I think it was not fixed in FreeBSD 5.2, but in 5.3-RELEASE.
  That is from looking at these two URLs. The getaddrinfo reentrancy
  patch is not committed in the 5.2 version.

  http://svn.freebsd.org/viewvc/base/releng/5.3/lib/libc/net/getaddrinfo.c?view=log
  http://svn.freebsd.org/viewvc/base/releng/5.2/lib/libc/net/getaddrinfo.c?view=log

- FreeBSD: There is a bug prior to FreeBSD 6.0, where
  getaddrinfo and gethostbyname_r both leak file descriptors.

  http://www.rhyolite.com/pipermail/dcc/2006/003074.html
  http://lists.freebsd.org/pipermail/freebsd-threads/2005-May/003088.html
  http://lists.freebsd.org/pipermail/freebsd-bugs/2003-August/002891.html

  So it looks like neither function is safe to use until FreeBSD 6.0.

-- Jamie
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-01-22