Commit 1b0aeb6f authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

new pthreads detection

other changes for z/OS port
parent 403b440e
......@@ -28,6 +28,7 @@ OpenLDAP 2.1.5 Engineering
Added IPv6 sockaddr_storage check
Added Berkeley DB 4.1 support
Fixed module build issues (ITS#2047 ITS#2048 ITS#2065)
Updated pthreads detection
Updated test suite (ITS#2054)
Updated NT and zOS ports
Documentation
......
/*
* Copyright 1998-2002 The OpenLDAP Foundation, Redwood City, California, USA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License. A copy of this license is available at
* http://www.OpenLDAP.org/license.html or in file LICENSE in the
* top-level directory of the distribution.
*/
#ifndef _LDAP_PORTABLE_H
#define _LDAP_PORTABLE_H
/* end of preamble */
@TOP@
/* define this if needed to get reentrant functions */
#ifndef REENTRANT
#undef REENTRANT
#endif
#ifndef _REENTRANT
#undef _REENTRANT
#endif
/* define this if needed to get threadsafe functions */
#ifndef THREADSAFE
#undef THREADSAFE
#endif
#ifndef _THREADSAFE
#undef _THREADSAFE
#endif
#ifndef THREAD_SAFE
#undef THREAD_SAFE
#endif
#ifndef _THREAD_SAFE
#undef _THREAD_SAFE
#endif
#ifndef _SGI_MP_SOURCE
#undef _SGI_MP_SOURCE
#endif
/* define this if TIOCGWINSZ is defined in sys/ioctl.h */
#undef GWINSZ_IN_SYS_IOCTL
/* These are defined in ldap_features.h */
/*
LDAP_API_FEATURE_X_OPENLDAP_REENTRANT
LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
*/
/* These are defined in lber_types.h */
/*
LBER_INT_T
LBER_LEN_T
LBER_SOCKET_T
LBER_TAG_T
*/
/* define to character address type */
#undef caddr_t
/* define to signed size type */
#undef ssize_t
/* Leave that blank line there!! Autoheader needs it. */
@BOTTOM@
/* begin of postamble */
#ifdef _WIN32
/* don't suck in all of the win32 api */
# define WIN32_LEAN_AND_MEAN 1
#endif
#ifndef LDAP_NEEDS_PROTOTYPES
/* force LDAP_P to always include prototypes */
#define LDAP_NEEDS_PROTOTYPES 1
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#if defined(LDAP_DEVEL) && !defined(LDAP_TEST)
#define LDAP_TEST
#endif
#if defined(LDAP_TEST) && !defined(LDAP_DEBUG)
#define LDAP_DEBUG
#endif
#ifdef HAVE_EBCDIC
/* ASCII/EBCDIC converting replacements for stdio funcs
* vsnprintf and snprintf are used too, but they are already
* checked by the configure script
*/
#define fputs ber_pvt_fputs
#define fgets ber_pvt_fgets
#define printf ber_pvt_printf
#define fprintf ber_pvt_fprintf
#define vfprintf ber_pvt_vfprintf
#define vsprintf ber_pvt_vsprintf
#endif
#include "ldap_cdefs.h"
#include "ldap_features.h"
#include "ac/assert.h"
#endif /* _LDAP_PORTABLE_H */
#!/bin/sh -
#! /bin/sh -
# $OpenLDAP$
## Copyright 1998-2002 The OpenLDAP Foundation
## COPYING RESTRICTIONS APPLY. See COPYRIGHT File in top level directory
## of this package for details.
#
# Portions
# Copyright (c) 1987 Regents of the University of California.
# All rights reserved.
#
......@@ -25,29 +30,52 @@ set -e # exit immediately if any errors occur
MAKE=Makefile # default makefile name is "Makefile"
NOSLASH="no" # by default, / dependencies are included
CC=cc # default compiler is cc
SRCDIR=""
SED=cat
: ${CC=cc} # use cc by default
# We generally set these via the command line options
: ${MKDEP_CC=$CC} # select default compiler to generate dependencies
: ${MKDEP_CFLAGS="-M"} # cc -M usually produces dependencies
while :
do case "$1" in
# the -s flag removes dependencies to files that begin with /
-s)
NOSLASH=yes;
shift ;;
# -f allows you to select a makefile name
-f)
MAKE=$2
shift; shift ;;
# -c allows you to select a compiler to use (default is cc)
# -d allows you to select a VPATH directory
-d)
SRCDIR=$2
shift; shift ;;
# -c allows you to override the compiler used to generate dependencies
-c)
CC=$2
MKDEP_CC=$2
shift; shift ;;
# -m allows you to override the compiler flags used to generate
# dependencies.
-m)
MKDEP_CFLAGS=$2
shift; shift ;;
# the -p flag produces "program: program.c" style dependencies
# so .o's don't get produced
-p)
SED='s;\.o;;'
SED='sed -e s;\.o;;'
shift ;;
# the -s flag removes dependencies to files that begin with /
-s)
NOSLASH=yes;
# the -l flag produces libtool compatible dependencies
-l)
SED='sed -e s;\.o:;.lo:;'
shift ;;
# -*) shift ;;
......@@ -57,19 +85,19 @@ while :
esac
done
if [ $# = 0 ] ; then
echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
if test $# = 0 ; then
echo 'usage: mkdep [-p] [-s] [-c cc] [-m flags] [-f makefile] [-d srcdir] [cppflags] file ...'
exit 1
fi
if [ ! -w $MAKE ]; then
if test ! -w $MAKE ; then
echo "mkdep: no writeable file \"$MAKE\""
exit 1
fi
TMP=/tmp/mkdep$$
trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
trap 'rm -f $TMP.sed $TMP ; exit 1' 1 2 3 13 15
cp $MAKE ${MAKE}.bak
......@@ -81,46 +109,100 @@ cat << _EOF_ >> $TMP
_EOF_
# If your compiler doesn't have -M, add it. If you can't, the next two
# lines will try and replace the "cc -M". The real problem is that this
# hack can't deal with anything that requires a search path, and doesn't
# even try for anything using bracket (<>) syntax.
# If your compiler doesn't have -M, you may be able to use -E instead.
# The preprocessor must generate lines of the form
# #.* [0-9]* "dependent file" .*
# This script will parse out the "dependent file"s to generate the
# dependency list.
if test "x$SRCDIR" = "x" ; then
files=$*
else
files=
for i in $* ; do
if test -f $i ; then
files="$files $i"
elif test -f $SRCDIR/$i ; then
files="$files $SRCDIR/$i"
else
files="$files $i"
fi
done
MKDEP_CFLAGS="$MKDEP_CFLAGS -I$SRCDIR"
fi
cat << _EOF_ >> $TMP
#
# egrep '^#include[ ]*".*"' /dev/null $* |
# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
# files: $*
# command: $MKDEP_CC $MKDEP_CFLAGS $files
#
_EOF_
$CC -M $* |
sed "
s; \./; ;g
$SED" |
case $MKDEP_CFLAGS in
# Using regular preprocessor output
-E*)
FLAGS=""
FILES=""
for i in $files; do
case $i in
-*) FLAGS="$FLAGS $i" ;;
*) FILES="$FILES $i" ;;
esac
done
for i in $FILES; do
$MKDEP_CC $MKDEP_CFLAGS $FLAGS $i | egrep '^#.*"' > $TMP.sed
awk '
BEGIN {
file = "'$i'"
n = split(file, parts, "/")
filenm = substr(parts[n], 0, length(parts[n])-1) "o"
}
{
dep = split($3, parts, "\"")
dep = parts[2]
if (dep ~ "^\./.*") dep = substr(dep, 3, length(dep)-2)
if (( noslash == "yes") && (dep ~ /^\// )) continue
if (deps[dep] == 0) printf "%s: %s\n", filenm, dep
deps[dep] = 1
}' noslash="$NOSLASH" $TMP.sed >> $TMP
done
;;
*)
# Using -M or some other specific dependency-generating option
$MKDEP_CC $MKDEP_CFLAGS $files | \
sed -e 's; \./; ;g' -e 's/ :/:/' | \
$SED > $TMP.sed
# do not pipe to awk. SGI awk wants a filename as argument.
# (or '-', but I do not know if all other awks support that.)
awk '
$1 ~ /:/ {
$1 ~ /:$/ {
filenm=$1
dep=$2
dep=substr($0, length(filenm)+1)
}
$1 !~ /:/ {
dep=$1
$1 !~ /:$/ {
dep=$0
}
/.*/ {
if ( noslash = "yes" && dep ~ /^\// ) next
if (filenm != prev) {
if (rec != "")
print rec;
rec = filenm " " dep;
prev = filenm;
if ( length(filenm) < 2 ) next
if ( filenm ~ /:.*:$/ ) next
split(dep, depends, " ")
for(d in depends) {
dfile = depends[d]
if ( length(dfile) < 2 ) continue
if ( dfile ~ /:/ ) continue
if (( noslash == "yes") && (dfile ~ /^\// )) continue
rec = filenm " " dfile
print rec
}
else {
if (length(rec dep) > 78) {
print rec;
rec = filenm " " dep;
}
else
rec = rec " " dep
}
}
END {
print rec
}' noslash="$NOSLASH" >> $TMP
}
' noslash="$NOSLASH" $TMP.sed >> $TMP
;;
esac
cat << _EOF_ >> $TMP
......@@ -129,5 +211,5 @@ _EOF_
# copy to preserve permissions
cp $TMP $MAKE
rm -f ${MAKE}.bak $TMP
rm -f ${MAKE}.bak $TMP.sed $TMP
exit 0
......@@ -621,36 +621,47 @@ dnl
dnl ====================================================================
dnl Check POSIX Thread version
dnl
dnl defines ol_cv_posix_version to 'final' or 'draft' or 'unknown'
dnl 'unknown' implies that the version could not be detected
dnl or that pthreads.h does exist. Existance of pthreads.h
dnl should be tested separately.
dnl defines ol_cv_pthread_version to 4, 5, 6, 7, 10, depending on the
dnl version of the POSIX.4a Draft that is implemented.
dnl 10 == POSIX.4a Final == POSIX.1c-1996 for our purposes.
dnl Existence of pthreads.h should be tested separately.
dnl
dnl tests:
dnl pthread_yield() was dropped in Draft 9, so
dnl only a Draft <= 8 library will define this
dnl pthread_detach() was dropped in Draft 8, it is present
dnl in every other version
dnl PTHREAD_CREATE_UNDETACHED is only in Draft 7, it was called
dnl PTHREAD_CREATE_JOINABLE after that
dnl pthread_attr_default was dropped in Draft 6, only 4 and 5 have it
dnl PTHREAD_MUTEX_INITIALIZER was introduced in Draft 5. It's not
dnl interesting to us because we don't try to statically
dnl initialize mutexes. 5-10 has it.
dnl pthread_attr_create was renamed to pthread_attr_init in Draft 6.
dnl Draft 6-10 has _init, Draft 4-5 has _create.
dnl
dnl Draft 9 and 10 are equivalent for our purposes.
dnl
AC_DEFUN([OL_POSIX_THREAD_VERSION],
[AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
AC_EGREP_CPP(pthread_version_final,[
AC_EGREP_HEADER(pthread_yield,pthread.h,[
AC_EGREP_HEADER(pthread_detach,pthread.h,[
AC_EGREP_CPP(draft7,[
# include <pthread.h>
/* this check could be improved */
# ifdef PTHREAD_ONCE_INIT
pthread_version_final;
# ifdef PTHREAD_CREATE_UNDETACHED
draft7
# endif
], ol_pthread_final=yes, ol_pthread_final=no)
AC_EGREP_CPP(pthread_version_draft4,[
], ol_cv_pthread_version=7, [
AC_EGREP_HEADER(pthread_attr_default,pthread.h,[
AC_EGREP_CPP(draft5,[
# include <pthread.h>
/* this check could be improved */
# ifdef pthread_once_init
pthread_version_draft4;
# endif
], ol_pthread_draft4=yes, ol_pthread_draft4=no)
if test $ol_pthread_final = yes -a $ol_pthread_draft4 = no; then
ol_cv_pthread_version=final
elif test $ol_pthread_final = no -a $ol_pthread_draft4 = yes; then
ol_cv_pthread_version=draft4
else
ol_cv_pthread_version=unknown
fi
#ifdef PTHREAD_MUTEX_INITIALIZER
draft5
#endif
], ol_cv_pthread_version=5, ol_cv_pthread_version=4) ],
ol_cv_pthread_version=6) ]) ],
ol_cv_pthread_version=8) ],
ol_cv_pthread_version=10)
])
])dnl
dnl
......@@ -658,6 +669,9 @@ dnl --------------------------------------------------------------------
AC_DEFUN([OL_PTHREAD_TEST_INCLUDES],
[/* pthread test headers */
#include <pthread.h>
#if HAVE_PTHREADS < 7
#include <errno.h>
#endif
#ifndef NULL
#define NULL (void*)0
#endif
......@@ -670,60 +684,43 @@ static void *task(p)
])
AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[
/* pthread test function */
#ifndef PTHREAD_CREATE_DETACHED
#define PTHREAD_CREATE_DETACHED 1
#endif
pthread_t t;
int status;
int detach = 1;
int detach = PTHREAD_CREATE_DETACHED;
#ifdef HAVE_PTHREADS_FINAL
#if HAVE_PTHREADS > 4
/* Final pthreads */
pthread_attr_t attr;
status = pthread_attr_init(&attr);
if( status ) return status;
#if defined( PTHREAD_CREATE_JOINABLE ) || defined( PTHREAD_UNDETACHED )
if( !detach ) {
#if defined( PTHREAD_CREATE_JOINABLE )
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
#if HAVE_PTHREADS < 7
status = pthread_attr_setdetachstate(&attr, &detach);
if( status < 0 ) status = errno;
#else
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
#endif
#ifdef PTHREAD_CREATE_DETACHED
} else {
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
status = pthread_attr_setdetachstate(&attr, detach);
#endif
}
if( status ) return status;
#endif
status = pthread_create( &t, &attr, task, NULL );
if( status ) return status;
#if !defined( PTHREAD_CREATE_JOINABLE ) && !defined( PTHREAD_UNDETACHED )
if( detach ) {
/* give thread a chance to complete */
/* it should remain joinable and hence detachable */
sleep( 1 );
status = pthread_detach( t );
if( status ) return status;
}
#if HAVE_PTHREADS < 7
if( status < 0 ) status = errno;
#endif
if( status ) return status;
#else
/* Draft 4 pthreads */
status = pthread_create( &t, pthread_attr_default, task, NULL );
if( status ) return status;
if( status ) return errno;
if( detach ) {
/* give thread a chance to complete */
/* it should remain joinable and hence detachable */
sleep( 1 );
/* give thread a chance to complete */
/* it should remain joinable and hence detachable */
sleep( 1 );
status = pthread_detach( &t );
if( status ) return status;
}
status = pthread_detach( &t );
if( status ) return errno;
#endif
#ifdef HAVE_LINUX_THREADS
......
This diff is collapsed.
......@@ -713,6 +713,14 @@ AC_CHECK_LIB(s, afopen, [
AC_DEFINE(HAVE_AIX_SECURITY,1,[define if you have AIX security lib])
])
dnl ----------------------------------------------------------------
dnl Check for IBM OS/390
case "$target" in
*-ibm-openedition)
ac_cv_func_getopt=no
AC_DEFINE(BOTH_STRINGS_H,1,[define to use both <string.h> and <strings.h>])
;;
esac
dnl ----------------------------------------------------------------
dnl Check for module support
......@@ -1353,12 +1361,9 @@ if test $ol_with_threads = auto -o $ol_with_threads = yes \
if test $ac_cv_header_pthread_h = yes ; then
OL_POSIX_THREAD_VERSION
if test $ol_cv_pthread_version = final ; then
AC_DEFINE(HAVE_PTHREADS_FINAL,1,
[define if pthreads API compatible with final spec])
elif test $ol_cv_pthread_version = draft4 ; then
AC_DEFINE(HAVE_PTHREADS_D4,1,
[define if pthreads API compatible with draft4 spec])
if test $ol_cv_pthread_version != 0 ; then
AC_DEFINE_UNQUOTED(HAVE_PTHREADS,$ol_cv_pthread_version,
[define to pthreads API spec revision])
else
AC_MSG_ERROR([unknown pthread version])
fi
......@@ -1453,9 +1458,6 @@ dnl [ol_cv_pthread_lpthread_lexc])
OL_PTHREAD_TRY([-lpthreads],[ol_cv_pthread_lib_lpthreads])
if test $ol_link_threads != no ; then
AC_DEFINE(HAVE_PTHREADS,1,
[define if you have POSIX Threads])
LTHREAD_LIBS="$LTHREAD_LIBS $ol_link_pthreads"
dnl save flags
......@@ -1604,7 +1606,7 @@ int main(argc, argv)
#endif
#endif
#if HAVE_PTHREADS_D4
#if HAVE_PTHREADS < 6
pthread_create(&t, pthread_attr_default, task, NULL);
#else
pthread_create(&t, NULL, task, NULL);
......@@ -2374,7 +2376,7 @@ AC_FUNC_VPRINTF
if test $ac_cv_func_vprintf = yes ; then
dnl check for vsnprintf
AC_CHECK_FUNCS(vsnprintf vsprintf)
AC_CHECK_FUNCS(snprintf vsnprintf)
fi
AC_CHECK_FUNCS( \
......@@ -2439,6 +2441,14 @@ AC_REPLACE_FUNCS(getopt)
if test "$ac_cv_func_getopt" != yes; then
LIBSRCS="$LIBSRCS getopt.c"
fi
if test "$ac_cv_func_snprintf" != yes -o "$ac_cv_func_vsnprintf" != yes; then
if test "$ac_cv_func_snprintf" != yes; then
AC_DEFINE(snprintf, ber_pvt_snprintf, [define to snprintf routine])
fi
if test "$ac_cv_func_vsnprintf" != yes; then
AC_DEFINE(vsnprintf, ber_pvt_vsnprintf, [define to snprintf routine])
fi
fi
dnl ----------------------------------------------------------------
# Check Configuration
......
......@@ -43,7 +43,7 @@ ldap_pvt_thread_set_concurrency LDAP_P(( int ));
#ifndef LDAP_PVT_THREAD_STACK_SIZE
/* LARGE stack */
#define LDAP_PVT_THREAD_STACK_SIZE (16*1024*1024)
#define LDAP_PVT_THREAD_STACK_SIZE (2*1024*1024)
#endif
LDAP_F( int )
......
......@@ -266,6 +266,9 @@
/* Define if you have the sigset function. */
#undef HAVE_SIGSET
/* Define if you have the snprintf function. */
#undef HAVE_SNPRINTF
/* Define if you have the strdup function. */
#undef HAVE_STRDUP
......@@ -311,9 +314,6 @@
/* Define if you have the vsnprintf function. */
#undef HAVE_VSNPRINTF
/* Define if you have the vsprintf function. */
#undef HAVE_VSPRINTF
/* Define if you have the wait4 function. */
#undef HAVE_WAIT4
......@@ -629,6 +629,9 @@
/* define if you have AIX security lib */
#undef HAVE_AIX_SECURITY
/* define to use both <string.h> and <strings.h> */
#undef BOTH_STRINGS_H
/* define if you have libtool -ltdl */
#undef HAVE_LIBLTDL
......@@ -707,18 +710,12 @@
/* if you have NT Event Log */
#undef HAVE_NT_EVENT_LOG
/* define if pthreads API compatible with final spec */
#undef HAVE_PTHREADS_FINAL
/* define if pthreads API compatible with draft4 spec */
#undef HAVE_PTHREADS_D4
/* define to pthreads API spec revision */
#undef HAVE_PTHREADS
/* if you have LinuxThreads */
#undef HAVE_LINUX_THREADS
/* define if you have POSIX Threads */
#undef HAVE_PTHREADS
/* Define if you have the sched_yield function. */
#undef HAVE_SCHED_YIELD
......@@ -869,6 +866,12 @@
/* define to vsnprintf routine */
#undef vsnprintf
/* define to snprintf routine */