Index: configure.in =================================================================== RCS file: /projects/cvsroot/pgsql/configure.in,v retrieving revision 1.571 diff -C6 -r1.571 configure.in *** configure.in 30 Oct 2008 12:28:51 -0000 1.571 --- configure.in 16 Nov 2008 05:15:59 -0000 *************** *** 1363,1374 **** --- 1363,1392 ---- if test "$PORTNAME" != "win32"; then AC_CHECK_HEADER(pthread.h, [], [AC_MSG_ERROR([pthread.h not found, required for --enable-thread-safety])]) fi AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r]) + # determines if the system has a 3 or 5 argument gethostbyname_r, only needed with threads + # there is also a 6 arg version used by linux + if test "$enable_thread_safety" = yes ; then + AC_MSG_CHECKING([gethostbyname_r argument count]) + AC_TRY_COMPILE( + [#undef _XOPEN_SOURCE_EXTENDED + #ifndef _REENTRANT + #define _REENTRANT + #endif + #ifndef _THREAD_SAFE + #define _THREAD_SAFE + #endif + #include ], + [gethostbyname_r((void *)0, (void *)0, (void *)0)], + [AC_DEFINE(GETHOSTBYNAME_R_ARGCNT, 3, [Define to the number of arguments gethostbyname_r accepts]) AC_MSG_RESULT(3)], + [AC_DEFINE(GETHOSTBYNAME_R_ARGCNT, 5, [Define to the number of arguments gethostbyname_r accepts]) AC_MSG_RESULT(5)]) + fi + # Do test here with the proper thread flags PGAC_FUNC_GETPWUID_R_5ARG PGAC_FUNC_STRERROR_R_INT CFLAGS="$_CFLAGS" LIBS="$_LIBS" Index: src/port/thread.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/port/thread.c,v retrieving revision 1.39 diff -C6 -r1.39 thread.c *** src/port/thread.c 22 Apr 2008 13:06:57 -0000 1.39 --- src/port/thread.c 16 Nov 2008 05:16:00 -0000 *************** *** 9,20 **** --- 9,27 ---- * * $PostgreSQL: pgsql/src/port/thread.c,v 1.39 2008/04/22 13:06:57 mha Exp $ * *------------------------------------------------------------------------- */ + /* When _XOPEN_SOURCE_EXTENDED is defined, struct hostent_data does + * not get declared. This structure is needed by hpux gethostbyname_r. + */ + #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && (defined(__hpux) || defined(__hpux__) || defined(hpux)) + #undef _XOPEN_SOURCE_EXTENDED + #endif + #include "c.h" #include #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) #endif *************** *** 126,142 **** --- 133,171 ---- char *buffer, size_t buflen, struct hostent ** result, int *herrno) { #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETHOSTBYNAME_R) + #if GETHOSTBYNAME_R_ARGCNT == 3 + *result = NULL; + + if (buflen < sizeof(struct hostent_data)) + { + /* linux man page says this gets set when buffer is too small */ + *herrno = ERANGE; + return -1; + } + + if (gethostbyname_r(name, resultbuf, (struct hostent_data *)buffer)) + { + *herrno = h_errno; + return -1; + } + + *result = resultbuf; + + /* 5 argument version. There is also a 6 arg version found on linux. */ + #else /* * broken (well early POSIX draft) gethostbyname_r() which returns 'struct * hostent *' */ *result = gethostbyname_r(name, resultbuf, buffer, buflen, herrno); + #endif /* GETHOSTBYNAME_R_ARGCNT */ + return (*result == NULL) ? -1 : 0; #else /* no gethostbyname_r(), just use gethostbyname() */ *result = gethostbyname(name);