summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2003-09-27 15:32:48 +0000
committerBruce Momjian2003-09-27 15:32:48 +0000
commit4020ff8dc385cb0e3fbd9e5ffd82593f63bbe7a1 (patch)
treed54cc5cde1dca00175ae1b962eaec043b86d5ee5
parent600536439d4340c9b929b97216759c8a8d0cf567 (diff)
Rename thread compile flag. Move thread test program to tools/thread,
and improve tests.
-rwxr-xr-xconfigure6
-rw-r--r--configure.in6
-rw-r--r--src/Makefile.global.in2
-rw-r--r--src/interfaces/ecpg/compatlib/Makefile2
-rw-r--r--src/interfaces/ecpg/ecpglib/Makefile2
-rw-r--r--src/interfaces/ecpg/pgtypeslib/Makefile2
-rw-r--r--src/interfaces/ecpg/preproc/Makefile2
-rw-r--r--src/interfaces/ecpg/test/Makefile2
-rw-r--r--src/interfaces/libpq/Makefile2
-rw-r--r--src/interfaces/libpq/fe-secure.c8
-rw-r--r--src/port/Makefile2
-rw-r--r--src/port/thread.c6
-rw-r--r--src/template/bsdi2
-rw-r--r--src/template/freebsd3
-rw-r--r--src/template/linux2
-rw-r--r--src/template/osf2
-rw-r--r--src/template/solaris2
-rw-r--r--src/template/unixware6
-rw-r--r--src/tools/thread/Makefile25
-rw-r--r--src/tools/thread/README8
-rw-r--r--src/tools/thread/thread_test.c (renamed from src/tools/test_thread_funcs.c)38
21 files changed, 100 insertions, 30 deletions
diff --git a/configure b/configure
index 99fb05aa65..1e842aeb60 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 c5ef4cc80b..a3b67addc3 100644
--- a/configure.in
+++ b/configure.in
@@ -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 f32e1d6d61..42395a29d0 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -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 633f5b80e2..ef8370a316 100644
--- a/src/interfaces/ecpg/compatlib/Makefile
+++ b/src/interfaces/ecpg/compatlib/Makefile
@@ -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 3837cb381f..4c3f69fd3b 100644
--- a/src/interfaces/ecpg/ecpglib/Makefile
+++ b/src/interfaces/ecpg/ecpglib/Makefile
@@ -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 cfb3f03dcf..14ea7b1707 100644
--- a/src/interfaces/ecpg/pgtypeslib/Makefile
+++ b/src/interfaces/ecpg/pgtypeslib/Makefile
@@ -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 ced2fc02ad..7661fbf33c 100644
--- a/src/interfaces/ecpg/preproc/Makefile
+++ b/src/interfaces/ecpg/preproc/Makefile
@@ -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 b2ea39c51b..c2e30d2887 100644
--- a/src/interfaces/ecpg/test/Makefile
+++ b/src/interfaces/ecpg/test/Makefile
@@ -4,7 +4,7 @@ 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 b53f325dd6..9041188aba 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -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 7477956f4d..2869a3e19c 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -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 805ddffb51..e6f4a892a7 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -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 80eaf9e4aa..1fb5f6adf4 100644
--- a/src/port/thread.c
+++ b/src/port/thread.c
@@ -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 d6b16a2417..a5996a5402 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 71e5014066..0711a83212 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 2c4f393e75..a690b44968 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 7305395a0b..0856f5c898 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 d839f935cc..b333f00660 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 21d4314d87..a228fa56ef 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 0000000000..61665ae0e9
--- /dev/null
+++ b/src/tools/thread/Makefile
@@ -0,0 +1,25 @@
+#-------------------------------------------------------------------------
+#
+# Makefile for tools/thread
+#
+# Copyright (C) 2003 by PostgreSQL Global Development Team
+#
+# $Header$
+#
+#-------------------------------------------------------------------------
+
+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 0000000000..f17e59248f
--- /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
index a6a58fba78..b152162fd4 100644
--- a/src/tools/test_thread_funcs.c
+++ b/src/tools/thread/thread_test.c
@@ -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);