Re: solaris libpq threaded build fails - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: solaris libpq threaded build fails
Date
Msg-id 200901142206.n0EM6LH12008@momjian.us
Whole thread Raw
In response to Re: solaris libpq threaded build fails  (Bruce Momjian <bruce@momjian.us>)
Responses Re: solaris libpq threaded build fails  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Bruce Momjian wrote:
> Merlin Moncure wrote:
> > On 1/14/09, Bruce Momjian <bruce@momjian.us> wrote:
> > > OK, patch attached and applied to CVS HEAD.  The nsl (not 'nls') library
> > >  check was removed in Postgres 8.2 here:
> >
> > As long as you are looking at this, can you take a peek at this patch?
> > http://archives.free.net.ph/message/20081116.053100.15b5801d.fi.html
> >
> > We had a similar problem on hpux 10.20.  This was more invasive change
> > though..  At the time, Tom was ambivalent and Dunstan voted that the
> > platform was too old, so it never went in.
>
> Thanks, I looked it over.  It does have the danger of affecting other
> platforms, so there would have to be more checks in there.  Also the
> calling of the function with all null pointers seems dangerous, though I
> am not sure how else we could test this.  It might be safer to create a
> conflicting function prototype and see if that throws a warning.
>
> I did a Google search and it seems there isn't an easy way to do the
> configure check except the approach you have taken.  Your changes to
> thread.c seem fine.
>
> Comp.programming.threads, has a pretty ugly autoconf example in their
> FAQ with the conclusion:
>
>     http://www.lambdacs.com/cpt/FAQ.html
>
>     > Whom do I shoot?
>
>     take your pick :-(
>
> Let me see if I can work up a more minimal patch.

OK, I ended up doing a compile test as you suggested because I was
worried that a mismatched 'const' might throw an error.

The patch is very similar to the one posted, though perhaps a little
cleaner.

I don't need the  #undef _XOPEN_SOURCE_EXTENDED in autoconf because I am
testing for the 5-argument version.

Would someone please test this to make sure it works on their platforms.

Is there any objection to applying this to 8.4?  While the operating
system is old, it seems we are having new users use threading on these
older operating systems, hence the need for a patch.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: configure
===================================================================
RCS file: /cvsroot/pgsql/configure,v
retrieving revision 1.628
diff -c -c -r1.628 configure
*** configure    14 Jan 2009 18:10:21 -0000    1.628
--- configure    14 Jan 2009 22:00:25 -0000
***************
*** 20379,20384 ****
--- 20379,20440 ----



+ if test "$enable_thread_safety" = yes -a x"$ac_cv_func_gethostbyname_r" = x"yes" ; then
+   { echo "$as_me:$LINENO: checking gethostbyname_r argument count" >&5
+ echo $ECHO_N "checking gethostbyname_r argument count... $ECHO_C" >&6; }
+ # Check to see if 5-argument call generates an error
+   cat >conftest.$ac_ext <<_ACEOF
+ /* confdefs.h.  */
+ _ACEOF
+ cat confdefs.h >>conftest.$ac_ext
+ cat >>conftest.$ac_ext <<_ACEOF
+ /* end confdefs.h.  */
+ #include <netdb.h>
+ int
+ main ()
+ {
+ (void) gethostbyname_r (NULL, NULL, NULL, 0, NULL);
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (ac_try="$ac_compile"
+ case "(($ac_try" in
+   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+   *) ac_try_echo=$ac_try;;
+ esac
+ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+   (eval "$ac_compile") 2>conftest.er1
+   ac_status=$?
+   grep -v '^ *+' conftest.er1 >conftest.err
+   rm -f conftest.er1
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } && {
+      test -z "$ac_c_werror_flag" ||
+      test ! -s conftest.err
+        } && test -s conftest.$ac_objext; then
+
+ cat >>confdefs.h <<\_ACEOF
+ #define GETHOSTBYNAME_R_ARGCNT 3
+ _ACEOF
+  { echo "$as_me:$LINENO: result: 5" >&5
+ echo "${ECHO_T}5" >&6; }
+ else
+   echo "$as_me: failed program was:" >&5
+ sed 's/^/| /' conftest.$ac_ext >&5
+
+
+ cat >>confdefs.h <<\_ACEOF
+ #define GETHOSTBYNAME_R_ARGCNT 5
+ _ACEOF
+  { echo "$as_me:$LINENO: result: 3" >&5
+ echo "${ECHO_T}3" >&6; }
+ fi
+
+ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ fi

  # This test makes sure that run tests work at all.  Sometimes a shared
  # library is found by the linker, but the runtime linker can't find it.
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql/configure.in,v
retrieving revision 1.587
diff -c -c -r1.587 configure.in
*** configure.in    14 Jan 2009 18:10:21 -0000    1.587
--- configure.in    14 Jan 2009 22:00:25 -0000
***************
*** 1417,1422 ****
--- 1417,1430 ----
  AC_SUBST(LDAP_LIBS_FE)
  AC_SUBST(LDAP_LIBS_BE)

+ if test "$enable_thread_safety" = yes -a x"$ac_cv_func_gethostbyname_r" = x"yes" ; then
+   AC_MSG_CHECKING([gethostbyname_r argument count])
+ # Check to see if 5-argument call generates an error
+   AC_TRY_COMPILE([#include <netdb.h>],
+   [(void) gethostbyname_r (NULL, NULL, NULL, 0, NULL);],
+   [AC_DEFINE(GETHOSTBYNAME_R_ARGCNT, 3, [Define to the number of arguments gethostbyname_r accepts])
AC_MSG_RESULT(5)],
+   [AC_DEFINE(GETHOSTBYNAME_R_ARGCNT, 5, [Define to the number of arguments gethostbyname_r accepts])
AC_MSG_RESULT(3)])
+ fi

  # This test makes sure that run tests work at all.  Sometimes a shared
  # library is found by the linker, but the runtime linker can't find it.
Index: src/port/thread.c
===================================================================
RCS file: /cvsroot/pgsql/src/port/thread.c,v
retrieving revision 1.41
diff -c -c -r1.41 thread.c
*** src/port/thread.c    14 Jan 2009 21:18:30 -0000    1.41
--- src/port/thread.c    14 Jan 2009 22:00:28 -0000
***************
*** 12,17 ****
--- 12,22 ----
   *-------------------------------------------------------------------------
   */

+ /* Required to access struct hostent_data from c.h on older HPUX (e.g. 11) */
+ #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_STRERROR_R) && defined(__hpux)
+ #undef _XOPEN_SOURCE_EXTENDED
+ #endif
+
  #include "c.h"

  #include <pwd.h>
***************
*** 127,132 ****
--- 132,138 ----
  {
  #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETHOSTBYNAME_R)

+ #if GETHOSTBYNAME_R_ARGCNT == 5
      /*
       * broken (well early POSIX draft) gethostbyname_r() which returns 'struct
       * hostent *'
***************
*** 134,140 ****
--- 140,163 ----
      *result = gethostbyname_r(name, resultbuf, buffer, buflen, herrno);
      return (*result == NULL) ? -1 : 0;
  #else
+     /* even older 3-argument version of gethostbyname_r() */
+     *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;
+ #endif

+ #else
      /* no gethostbyname_r(), just use gethostbyname() */
      *result = gethostbyname(name);


pgsql-hackers by date:

Previous
From: "Lawrence, Ramon"
Date:
Subject: Re: Proposed Patch to Improve Performance of Multi-BatchHash Join for Skewed Data Sets
Next
From: Bruce Momjian
Date:
Subject: Re: async notification patch for dblink