jerenkrantz 01/07/20 23:41:09 Modified: . configure.in acconfig.h network_io/unix sa_common.c Log: Add thread-safe resolver - with a high thread count, we can run into problems using a non-thread safe resolver function. We'll attempt to use gethostbyname_r if: APR_HAS_THREADS is defined, libc_r doesn't have gethostbyname (BSD), and gethostbyname_r even exists. I've tested this on Solaris 7. Ian Holsman has reported success on Solaris 8 (I wonder if he didn't have IPv6 support turned on - that would cause it to use the non-getaddrinfo() code path). Revision Changes Path 1.340 +3 -0 apr/configure.in Index: configure.in =================================================================== RCS file: /home/cvs/apr/configure.in,v retrieving revision 1.339 retrieving revision 1.340 diff -u -r1.339 -r1.340 --- configure.in 2001/07/14 00:13:36 1.339 +++ configure.in 2001/07/21 06:41:09 1.340 @@ -326,9 +326,12 @@ fi ac_cv_define_READDIR_IS_THREAD_SAFE=no +ac_cv_define_GETHOSTBYNAME_IS_THREAD_SAFE=no if test "$threads" = "1"; then echo "APR will use threads" AC_CHECK_LIB(c_r, readdir, AC_DEFINE(READDIR_IS_THREAD_SAFE)) + AC_CHECK_LIB(c_r, gethostbyname, AC_DEFINE(GETHOSTBYNAME_IS_THREAD_SAFE)) + AC_CHECK_FUNCS(gethostbyname_r) else echo "APR will be non-threaded" fi 1.47 +1 -0 apr/acconfig.h Index: acconfig.h =================================================================== RCS file: /home/cvs/apr/acconfig.h,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- acconfig.h 2001/07/02 18:54:05 1.46 +++ acconfig.h 2001/07/21 06:41:09 1.47 @@ -23,6 +23,7 @@ #undef USE_PTHREAD_SERIALIZE #undef READDIR_IS_THREAD_SAFE +#undef GETHOSTBYNAME_IS_THREAD_SAFE #undef NEED_RLIM_T #undef USEBCOPY 1.35 +26 -0 apr/network_io/unix/sa_common.c Index: sa_common.c =================================================================== RCS file: /home/cvs/apr/network_io/unix/sa_common.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- sa_common.c 2001/05/02 02:54:11 1.34 +++ sa_common.c 2001/07/21 06:41:09 1.35 @@ -77,6 +77,15 @@ #define SET_H_ERRNO(newval) h_errno = (newval) #endif +#if APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \ + defined(HAVE_GETHOSTBYNAME_R) +/* This is the maximum size that may be returned from the reentrant + * gethostbyname_r function. If the system tries to use more, it + * should return ERANGE. + */ +#define GETHOSTBYNAME_BUFLEN 512 +#endif + APR_DECLARE(apr_status_t) apr_sockaddr_port_set(apr_sockaddr_t *sockaddr, apr_port_t port) { @@ -380,6 +389,12 @@ struct hostent *hp; apr_sockaddr_t *cursa; int curaddr; +#if APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \ + defined(HAVE_GETHOSTBYNAME_R) + char tmp[GETHOSTBYNAME_BUFLEN]; + int hosterror; + struct hostent hs; +#endif if (family == APR_UNSPEC) { family = APR_INET; /* we don't support IPv6 here */ @@ -395,11 +410,22 @@ } else { #endif +#if APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \ + defined(HAVE_GETHOSTBYNAME_R) + hp = gethostbyname_r(hostname, &hs, tmp, GETHOSTBYNAME_BUFLEN - 1, + &hosterror); +#else hp = gethostbyname(hostname); +#endif if (!hp) { #ifdef WIN32 apr_get_netos_error(); +#elif APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \ + defined(HAVE_GETHOSTBYNAME_R) + /* If you see ERANGE, that means GETHOSBYNAME_BUFLEN needs to be + * bumped. */ + return (hosterror + APR_OS_START_SYSERR); #else return (h_errno + APR_OS_START_SYSERR); #endif