diff --git a/configure b/configure
index 99fb05aa65ea20e1a9d0a7305373dad34efa5701..1e842aeb60402986f5452f7522487b6069c78cc9 100755
--- a/configure
+++ b/configure
@@ -13292,7 +13292,7 @@ See the comment at the top of src/port/thread.c for more information.
 fi
 else
 # do not use values from template file
-THREAD_CFLAGS=
+THREAD_CPPFLAGS=
 THREAD_LIBS=
 fi
 
@@ -13312,7 +13312,7 @@ fi
 if test "$enable_thread_safety" = yes -a "$NEED_REENTRANT_FUNCS" = yes ; then
 _CFLAGS="$CFLAGS"
 _LIBS="$LIBS"
-CFLAGS="$CFLAGS $THREAD_CFLAGS"
+CFLAGS="$CFLAGS $THREAD_CPPFLAGS"
 LIBS="$LIBS $THREAD_LIBS"
 
 
@@ -18211,7 +18211,7 @@ s,@python_includespec@,$python_includespec,;t t
 s,@python_libspec@,$python_libspec,;t t
 s,@LIBOBJS@,$LIBOBJS,;t t
 s,@HAVE_IPV6@,$HAVE_IPV6,;t t
-s,@THREAD_CFLAGS@,$THREAD_CFLAGS,;t t
+s,@THREAD_CPPFLAGS@,$THREAD_CPPFLAGS,;t t
 s,@THREAD_LIBS@,$THREAD_LIBS,;t t
 s,@HAVE_POSIX_SIGNALS@,$HAVE_POSIX_SIGNALS,;t t
 s,@MSGFMT@,$MSGFMT,;t t
diff --git a/configure.in b/configure.in
index e9bd01b91c967b2a34dacbdbe42218ee469ca114..1606a54871a82e6ddfd7709c07b2ed0ccbda82a6 100644
--- a/configure.in
+++ b/configure.in
@@ -1,5 +1,5 @@
 \dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.290 2003/09/15 14:32:35 pgsql Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.291 2003/09/27 15:32:47 momjian Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -1013,10 +1013,10 @@ See the comment at the top of src/port/thread.c for more information.
 fi
 else
 # do not use values from template file
-THREAD_CFLAGS=
+THREAD_CPPFLAGS=
 THREAD_LIBS=
 fi
-AC_SUBST(THREAD_CFLAGS)
+AC_SUBST(THREAD_CPPFLAGS)
 AC_SUBST(THREAD_LIBS)
 
 
@@ -1033,7 +1033,7 @@ AC_SUBST(THREAD_LIBS)
 if test "$enable_thread_safety" = yes -a "$NEED_REENTRANT_FUNCS" = yes ; then
 _CFLAGS="$CFLAGS"
 _LIBS="$LIBS"
-CFLAGS="$CFLAGS $THREAD_CFLAGS"
+CFLAGS="$CFLAGS $THREAD_CPPFLAGS"
 LIBS="$LIBS $THREAD_LIBS"
 AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r])
 CFLAGS="$_CFLAGS"
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 1be4bc0a831f9907928120c3c168975ae4dae0dc..b4b2abb50eb476d963d820b5b8178f93959757b1 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -1,5 +1,5 @@
 # -*-makefile-*-
-# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.168 2003/09/07 03:36:02 tgl Exp $
+# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.169 2003/09/27 15:32:47 momjian Exp $
 
 #------------------------------------------------------------------------------
 # All PostgreSQL makefiles include this file and use the variables it sets,
@@ -150,7 +150,7 @@ TK_LIBS			= @TK_LIBS@
 TK_LIB_SPEC		= @TK_LIB_SPEC@
 TK_XINCLUDES		= @TK_XINCLUDES@
 
-THREAD_CFLAGS		= @THREAD_CFLAGS@
+THREAD_CPPFLAGS		= @THREAD_CPPFLAGS@
 THREAD_LIBS		= @THREAD_LIBS@
 
 have_docbook	= @have_docbook@
diff --git a/src/interfaces/ecpg/compatlib/Makefile b/src/interfaces/ecpg/compatlib/Makefile
index 73bf3389a19bff2836557c2ffba3bc6b78d425e2..cd05452aeae089ff0dd29f094fe15b6f11c4ffcc 100644
--- a/src/interfaces/ecpg/compatlib/Makefile
+++ b/src/interfaces/ecpg/compatlib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.8 2003/08/06 02:19:48 momjian Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.9 2003/09/27 15:32:47 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -16,7 +16,7 @@ NAME= ecpg_compat
 SO_MAJOR_VERSION= 1
 SO_MINOR_VERSION= 0
 
-override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS) $(THREAD_CFLAGS)
+override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS) $(THREAD_CPPFLAGS)
 SHLIB_LINK = -L../pgtypeslib -lpgtypes -L../ecpglib -lecpg $(THREAD_LIBS)
 
 OBJS= informix.o
diff --git a/src/interfaces/ecpg/ecpglib/Makefile b/src/interfaces/ecpg/ecpglib/Makefile
index bda52dc7dc9ae8697990e4acba49593ef601d453..75fcfc90236f90ee98d9381e380332a42efc4a6a 100644
--- a/src/interfaces/ecpg/ecpglib/Makefile
+++ b/src/interfaces/ecpg/ecpglib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.7 2003/08/01 16:18:04 petere Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.8 2003/09/27 15:32:47 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -16,7 +16,7 @@ NAME= ecpg
 SO_MAJOR_VERSION= 4
 SO_MINOR_VERSION= 0
 
-override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CFLAGS) 
+override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) 
 
 OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
 	connect.o misc.o
diff --git a/src/interfaces/ecpg/pgtypeslib/Makefile b/src/interfaces/ecpg/pgtypeslib/Makefile
index 790d87a660b6104b49523c527f562bcac8ae7845..71100084b1e07d2b0aac5cda468f7e53eff6666c 100644
--- a/src/interfaces/ecpg/pgtypeslib/Makefile
+++ b/src/interfaces/ecpg/pgtypeslib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.11 2003/08/07 04:03:18 momjian Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.12 2003/09/27 15:32:47 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -16,7 +16,7 @@ NAME= pgtypes
 SO_MAJOR_VERSION= 1
 SO_MINOR_VERSION= 0
 
-override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS) $(THREAD_CFLAGS) -g
+override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS) $(THREAD_CPPFLAGS) -g
 SHLIB_LINK += -lm
 
 OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
diff --git a/src/interfaces/ecpg/preproc/Makefile b/src/interfaces/ecpg/preproc/Makefile
index 9fe25529885142b5782e63dd28e87644dbaa028b..1238f809d13f6f4951595dc17c1199f9e6cde72b 100644
--- a/src/interfaces/ecpg/preproc/Makefile
+++ b/src/interfaces/ecpg/preproc/Makefile
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.93 2003/08/06 02:19:51 momjian Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.94 2003/09/27 15:32:48 momjian Exp $
 
 subdir = src/interfaces/ecpg/preproc
 top_builddir = ../../../..
@@ -8,7 +8,7 @@ MAJOR_VERSION=3
 MINOR_VERSION=0
 PATCHLEVEL=0
 
-override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) $(THREAD_CFLAGS) \
+override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) \
 	-DMAJOR_VERSION=$(MAJOR_VERSION) \
 	-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
 	-DINCLUDE_PATH=\"$(includedir)\" 
diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile
index ce8754284699b7d66f7e03ebae5e538bdc07298b..7f6835498da83e8a4be2c00425bc1dedb0dbeca7 100644
--- a/src/interfaces/ecpg/test/Makefile
+++ b/src/interfaces/ecpg/test/Makefile
@@ -1,10 +1,10 @@
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.40 2003/08/06 02:19:51 momjian Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.41 2003/09/27 15:32:48 momjian Exp $
 
 subdir = src/interfaces/ecpg/test
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
-override CPPFLAGS := -I$(srcdir)/../include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CFLAGS)
+override CPPFLAGS := -I$(srcdir)/../include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS)
 
 ECPG = ../preproc/ecpg -I$(srcdir)/../include
 
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index 1f7fc77fdd3d2dc02d87eee0f7af5a41d372bb28..90a7f8c634d4685a1d69279597249b851b7c7526 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.93 2003/09/07 03:43:57 momjian Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.94 2003/09/27 15:32:48 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -18,7 +18,7 @@ NAME= pq
 SO_MAJOR_VERSION= 3
 SO_MINOR_VERSION= 1
 
-override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"'
+override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"'
 
 OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
       fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index 9a2ac48698901ad5c38b193374545cc34b6ba56b..e9620d03a4c839e579a66c9452dfce136de8c953 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.30 2003/09/05 02:08:36 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.31 2003/09/27 15:32:48 momjian Exp $
  *
  * NOTES
  *	  The client *requires* a valid server certificate.  Since
@@ -469,7 +469,13 @@ verify_peer(PGconn *conn)
 		struct hostent hpstr;
 		char		buf[BUFSIZ];
 		int			herrno = 0;
-
+		
+		/*
+		 *	Currently, pqGethostbyname() is used only on platforms that
+		 *	don't have getaddrinfo().  If you enable this function,
+		 *	you should convert the pqGethostbyname() function call to
+		 *	use getaddrinfo().
+		 */
 		pqGethostbyname(conn->peer_cn, &hpstr, buf, sizeof(buf),
 						&h, &herrno);
 	}
diff --git a/src/port/Makefile b/src/port/Makefile
index 740c58657eda0735c164fcae5bcfee6ca21e5895..5d06432e2d2a51017320059e116db675cb475628 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -7,7 +7,7 @@
 # with broken/missing library files.
 
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/port/Makefile,v 1.6 2003/08/13 03:12:04 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/port/Makefile,v 1.7 2003/09/27 15:32:48 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -23,7 +23,7 @@ libpgport.a: $(LIBOBJS)
 	$(AR) crs $@ $^
 
 thread.o: thread.c
-	$(CC) $(CFLAGS) $(CPPFLAGS) $(THREAD_CFLAGS) -c $<
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(THREAD_CPPFLAGS) -c $<
 
 clean distclean maintainer-clean:
 	rm -f libpgport.a $(LIBOBJS)
diff --git a/src/port/thread.c b/src/port/thread.c
index bfc315cc0e4bc21d73ed80a53069b68c95b8a742..19b12fe0ba62831469a5cdaf5787030c4dc970ee 100644
--- a/src/port/thread.c
+++ b/src/port/thread.c
@@ -7,7 +7,7 @@
  *
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  *
- * $Id: thread.c,v 1.8 2003/09/15 02:30:29 momjian Exp $
+ * $Id: thread.c,v 1.9 2003/09/27 15:32:48 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -165,7 +165,9 @@ pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer,
 /*
  * Wrapper around gethostbyname() or gethostbyname_r() to mimic
  * POSIX gethostbyname_r() behaviour, if it is not available or required.
+ * This function is called _only_ by our getaddinfo() portability function.
  */
+#ifndef HAVE_GETADDRINFO
 int
 pqGethostbyname(const char *name,
 				struct hostent *resultbuf,
@@ -213,7 +215,7 @@ pqGethostbyname(const char *name,
 		for (i = 0; (*result)->h_aliases[i]; i++, pointers++)
 			len += (*result)->h_length;
 
-		if (MAXALIGN(len) + pointers * sizeof(char *) + strlen((*result)->h_name) + 1 <= buflen)
+		if (pointers * sizeof(char *) + MAXALIGN(len) + strlen((*result)->h_name) + 1 <= buflen)
 		{
 			memcpy(resultbuf, *result, sizeof(struct hostent));
 
@@ -242,6 +244,7 @@ pqGethostbyname(const char *name,
 			pbuffer++;
 
 			/* Place at end for cleaner alignment */			
+			buffer = MAXALIGN(buffer);
 			strcpy(buffer, (*result)->h_name);
 			resultbuf->h_name = buffer;
 			buffer += strlen(resultbuf->h_name) + 1;
@@ -269,3 +272,4 @@ pqGethostbyname(const char *name,
 		return -1;
 #endif
 }
+#endif
diff --git a/src/template/bsdi b/src/template/bsdi
index d6b16a2417d2a784b59d99f8e0688f307df26c3a..a5996a5402d2e2f24f5fca2433f38879f03b9078 100644
--- a/src/template/bsdi
+++ b/src/template/bsdi
@@ -11,4 +11,4 @@ case $host_os in
 esac
 
 SUPPORTS_THREADS=yes
-NEED_REENTRANT_FUNCS=no	# verified 4.3 2003-09-03
+NEED_REENTRANT_FUNCS=no		# verified 4.3 2003-09-26
diff --git a/src/template/freebsd b/src/template/freebsd
index 71e501406607e0a1befd1927bc2fdc15a54c53bd..0711a83212c14ff5e62484828a9fda0d6e9bde90 100644
--- a/src/template/freebsd
+++ b/src/template/freebsd
@@ -7,9 +7,10 @@ esac
 SUPPORTS_THREADS=yes
 NEED_REENTRANT_FUNCS=yes 	# 4.8, 5.1  2003-09-12
 
+THREAD_CPPFLAGS="-D_THREAD_SAFE"
 case $host_os in
 		freebsd2*|freebsd3*|freebsd4*)
-			THREAD_CFLAGS="-pthread"
+			THREAD_LIBS="-pthread"
 			;;
 		*)
 			THREAD_LIBS="-lc_r"
diff --git a/src/template/linux b/src/template/linux
index 2c4f393e75add9b551c1bd3f73fdfbed59795846..a690b44968cf4155f009992a0097d1f0101f632a 100644
--- a/src/template/linux
+++ b/src/template/linux
@@ -4,6 +4,6 @@ CPPFLAGS="-D_GNU_SOURCE"
 
 SUPPORTS_THREADS=yes
 NEED_REENTRANT_FUNCS=yes	# verified glibc 2.1 2003-09-03
-THREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
+THREAD_CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
 THREAD_LIBS="-lpthread"
 
diff --git a/src/template/osf b/src/template/osf
index 7305395a0b2e23c38deb21f7fe0753bdabbf78d9..0856f5c898170084d11f69ee135f36656940e26e 100644
--- a/src/template/osf
+++ b/src/template/osf
@@ -7,4 +7,4 @@ fi
 
 SUPPORTS_THREADS=yes
 NEED_REENTRANT_FUNCS=no		# 4.0 2003-09-13
-THREAD_CFLAGS="-pthread"
+THREAD_LIBS="-pthread"
diff --git a/src/template/solaris b/src/template/solaris
index d839f935ccb4701506b6329d4cd3cd95d5cd5167..b333f006602e5f407e71a527872d1b35ce83b119 100644
--- a/src/template/solaris
+++ b/src/template/solaris
@@ -7,5 +7,5 @@ fi
 
 SUPPORTS_THREADS=yes
 NEED_REENTRANT_FUNCS=yes	# 5.6 2003-09-13
-THREAD_CFLAGS="-pthread"
+THREAD_LIBS="-pthread"
 
diff --git a/src/template/unixware b/src/template/unixware
index 21d4314d87d549399ab33f816fc02a57eaa0dda9..a228fa56ef82bf59f84cfd36012447e276fd0981 100644
--- a/src/template/unixware
+++ b/src/template/unixware
@@ -1,14 +1,14 @@
 if test "$GCC" = yes; then
   CFLAGS=-O2
-  THREAD_CFLAGS="-pthread"
+  THREAD_CPPFLAGS="-pthread"
 else
 # the -Kno_host is temporary for a bug in the compiler.  See -hackers
 # discussion on 7-8/Aug/2003.
 # when the 7.1.3UP3 or later compiler is out, we can do a version check.
   CFLAGS='-O -Kinline,no_host'
-  THREAD_CFLAGS="-K pthread"
+  THREAD_CPPFLAGS="-K pthread"
 fi
 
 SUPPORTS_THREADS=yes
 NEED_REENTRANT_FUNCS=no		# verified 7.1.3 2003-09-03
-THREAD_CFLAGS="$THREAD_CFLAGS -D_REENTRANT"
+THREAD_CPPFLAGS="$THREAD_CPPFLAGS -D_REENTRANT"
diff --git a/src/tools/thread/Makefile b/src/tools/thread/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..ed5be7f5c77d3d825356b49abaebbad5c594209a
--- /dev/null
+++ b/src/tools/thread/Makefile
@@ -0,0 +1,25 @@
+#-------------------------------------------------------------------------
+#
+# Makefile for tools/thread
+#
+# Copyright (C) 2003 by PostgreSQL Global Development Team
+#
+# $Header: /cvsroot/pgsql/src/tools/thread/Attic/Makefile,v 1.1 2003/09/27 15:32:48 momjian Exp $
+#
+#-------------------------------------------------------------------------
+
+subdir = tools/thread
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+override CFLAGS += $(THREAD_CPPFLAGS)
+
+LDFLAGS += $(THREAD_LIBS)
+
+all: thread_test
+
+thread_test: thread_test.o
+	$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
+
+clean distclean maintainer-clean:
+	rm -f thread_test$(X) thread_test.o
diff --git a/src/tools/thread/README b/src/tools/thread/README
new file mode 100644
index 0000000000000000000000000000000000000000..f17e59248fdacf90bcb7924c2cbd17ed322041cb
--- /dev/null
+++ b/src/tools/thread/README
@@ -0,0 +1,8 @@
+This program should be run by developers wishing to enable threading on
+new platforms.
+
+Run thread_test program to determine if your native libc functions are
+thread-safe, or if we should use *_r functions or thread locking.
+
+Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'
+defines to your template/${port} file before compiling this program.
diff --git a/src/tools/test_thread_funcs.c b/src/tools/thread/thread_test.c
similarity index 79%
rename from src/tools/test_thread_funcs.c
rename to src/tools/thread/thread_test.c
index 6fc781a2b64f40ebaf540782cd8e53d3cf291dad..7beb63dff4ae7225bdfed73a56a83723a4a8674c 100644
--- a/src/tools/test_thread_funcs.c
+++ b/src/tools/thread/thread_test.c
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *	$Header: /cvsroot/pgsql/src/tools/Attic/test_thread_funcs.c,v 1.3 2003/09/03 22:34:08 momjian Exp $
+ *	$Header: /cvsroot/pgsql/src/tools/thread/Attic/thread_test.c,v 1.1 2003/09/27 15:32:48 momjian Exp $
  *
  *	This program tests to see if your standard libc functions use
  *	pthread_setspecific()/pthread_getspecific() to be thread-safe.
@@ -17,9 +17,6 @@
  *	to see if the pointers are different for different threads.  If they
  *	are, the function is thread-safe.
  *
- *	This program must be compiled with the thread flags required by your
- *	operating system.  See src/template for the appropriate flags, if any.
- *
  *-------------------------------------------------------------------------
  */
 
@@ -37,8 +34,10 @@
 void func_call_1(void);
 void func_call_2(void);
 
+#ifndef HAVE_GETADDRINFO
 struct hostent *hostent_p1;
 struct hostent *hostent_p2;
+#endif
 
 struct passwd *passwd_p1;
 struct passwd *passwd_p2;
@@ -57,24 +56,47 @@ int main(int argc, char *argv[])
 			return 1;
 	}
 
+	printf("\
+Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'\n\
+defines to your template/${port} file before compiling this program.\n\n"
+);
 	pthread_create(&thread1, NULL, (void * (*)(void *)) func_call_1, NULL);
 	pthread_create(&thread2, NULL, (void * (*)(void *)) func_call_2, NULL);
 	pthread_join(thread1, NULL);
 	pthread_join(thread2, NULL);
 
+#ifndef HAVE_GETADDRINFO
 	if (hostent_p1 == hostent_p2)
 		printf("Your gethostbyname() is _not_ thread-safe\n");
+#endif
 	if (passwd_p1 == passwd_p2)
 		printf("Your getpwuid() is _not_ thread-safe\n");
 	if (strerror_p1 == strerror_p2)
 		printf("Your strerror() is _not_ thread-safe\n");
 
-	if (hostent_p1 != hostent_p2 &&
+	if (
+#ifndef HAVE_GETADDRINFO
+		hostent_p1 != hostent_p2 &&
+#endif
 		passwd_p1 != passwd_p2 &&
 		strerror_p1 != strerror_p2)
-		printf("Your functions are all thread-safe\n");
+	{
+		printf("All your non-*_r functions are thread-safe.\n");
+		printf("Add this to your template/${port} file:\n\n");
+		printf("\
+SUPPORTS_THREADS=yes\n\
+NEED_REENTRANT_FUNCS=no\n"
+			  );
+	}
 	else
-		printf("Your functions are _not_ all thread-safe\n");
+	{
+		printf("Not all non-*_r functions are thread-safe.\n");
+		printf("Add this to your template/${port} file:\n\n");
+		printf("\
+SUPPORTS_THREADS=yes\n\
+NEED_REENTRANT_FUNCS=yes\n"
+			  );
+	}
 
 	return 0;
 }
@@ -82,6 +104,7 @@ int main(int argc, char *argv[])
 void func_call_1(void) {
 	void *p;
 
+#ifndef HAVE_GETADDRINFO
 	hostent_p1 = gethostbyname("yahoo.com");
 	p = gethostbyname("slashdot.org");
 	if (hostent_p1 != p)
@@ -89,6 +112,7 @@ void func_call_1(void) {
 		printf("Your gethostbyname() changes the static memory area between calls\n");
 		hostent_p1 = NULL;	/* force thread-safe failure report */
 	}
+#endif
 
 	passwd_p1 = getpwuid(0);
 	p = getpwuid(1);
@@ -109,6 +133,7 @@ void func_call_1(void) {
 void func_call_2(void) {
 	void *p;
 
+#ifndef HAVE_GETADDRINFO
 	hostent_p2 = gethostbyname("google.com");
 	p = gethostbyname("postgresql.org");
 	if (hostent_p2 != p)
@@ -116,6 +141,7 @@ void func_call_2(void) {
 		printf("Your gethostbyname() changes the static memory area between calls\n");
 		hostent_p2 = NULL;	/* force thread-safe failure report */
 	}
+#endif
 
 	passwd_p2 = getpwuid(2);
 	p = getpwuid(3);