Updated pthread test and usage (avoid pthread_detach if possible)

don't use tmpnam()
This commit is contained in:
Kurt Zeilenga 2001-06-09 01:05:35 +00:00
parent 9ccd5880d1
commit 44bef574c8
8 changed files with 1914 additions and 1241 deletions

View File

@ -651,44 +651,65 @@ AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[
/* pthread test function */
pthread_t t;
int status;
#if HAVE_PTHREADS_FINAL && defined(PTHREAD_CREATE_UNDETACHED)
/* This system (e.g. AIX) defaults detached; must override */
int detach = 1;
#ifdef HAVE_PTHREADS_FINAL
/* Final pthreads */
pthread_attr_t attr;
status = pthread_attr_init(&attr);
if( status ) exit( status );
if( status ) return status;
status = pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_UNDETACHED);
if( status ) exit( status );
# define ATTR &attr
#elif defined( HAVE_PTHREADS_D4 )
# define ATTR pthread_attr_default
#if defined( PTHREAD_CREATE_JOINABLE ) || defined( PTHREAD_UNDETACHED )
if( !detach ) {
#if defined( PTHREAD_CREATE_JOINABLE )
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
#else
# define ATTR NULL
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
#endif
/* make sure pthread_create() isn't just a stub */
status = pthread_create(&t, ATTR, task, NULL);
if( status ) exit( status );
#ifdef PTHREAD_CREATE_DETACHED
} else {
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
#endif
}
if( status ) return status;
#endif
/* give the thread a chance to complete...
* it should remain joinable and hence detachable
*/
sleep( 1 );
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;
}
#endif
/* make sure pthread_detach() isn't just a stub */
#if HAVE_PTHREADS_D4
status = pthread_detach( &t );
#else
status = pthread_detach( t );
/* Draft 4 pthreads */
status = pthread_create( &t, pthread_attr_default, task, NULL );
if( status ) return status;
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;
}
#endif
#ifdef HAVE_LINUX_THREADS
pthread_kill_other_threads_np();
#endif
exit( status );
return 0;
])
AC_DEFUN([OL_PTHREAD_TEST_PROGRAM],

View File

@ -1070,13 +1070,9 @@ print_entry(
tmpdir, a );
tmpfp = NULL;
if ( mktemp( tmpfname ) == NULL ) {
perror( tmpfname );
continue;
}
tmpfd = mkstemp( tmpfname );
tmpfd = open( tmpfname, O_WRONLY|O_CREAT|O_EXCL, 0600 );
if ( tmpfd == -1 ) {
if ( tmpfd < 0 ) {
perror( tmpfname );
continue;
}

View File

@ -142,19 +142,20 @@ load_editor( void )
printf("->load_editor()\n");
#endif
/* write the entry into a temp file */
if (tmpnam(entry_temp_file) == NULL) {
perror("tmpnam");
return -1;
}
if ((tmpfd = open(entry_temp_file, O_WRONLY|O_CREAT|O_EXCL, 0600)) == -1) {
perror(entry_temp_file);
sprintf(entry_temp_file, "/tmp/udXXXXXX");
tmpfd = mkstemp(entry_temp_file);
if( tmpfd < 0 ) {
perror("mkstemp");
return -1;
}
if ((fp = fdopen(tmpfd, "w")) == NULL) {
perror("fdopen");
return(-1);
}
fprintf(fp, "## Directory entry of %s\n", Entry.name);
fprintf(fp, "##\n");
fprintf(fp, "## Syntax is:\n");

2982
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -2204,7 +2204,6 @@ AC_CHECK_FUNCS( \
lockf \
memcpy \
memmove \
mkstemp \
pipe \
read \
recv \
@ -2237,7 +2236,7 @@ AC_CHECK_FUNCS( \
)
dnl We actually may need to replace more than this.
AC_REPLACE_FUNCS(getopt tempnam)
AC_REPLACE_FUNCS(getopt)
if test "$ac_cv_func_getopt" != yes; then
LIBSRCS="$LIBSRCS getopt.c"

View File

@ -205,9 +205,6 @@
/* Define if you have the memmove function. */
#undef HAVE_MEMMOVE
/* Define if you have the mkstemp function. */
#undef HAVE_MKSTEMP
/* Define if you have the pipe function. */
#undef HAVE_PIPE
@ -307,9 +304,6 @@
/* Define if you have the sysconf function. */
#undef HAVE_SYSCONF
/* Define if you have the tempnam function. */
#undef HAVE_TEMPNAM
/* Define if you have the thr_getconcurrency function. */
#undef HAVE_THR_GETCONCURRENCY

View File

@ -83,26 +83,42 @@ ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
void *arg)
{
int rtn;
#if defined(HAVE_PTHREADS_FINAL) && defined(PTHREAD_CREATE_UNDETACHED)
#if defined( HAVE_PTHREADS_FINAL )
pthread_attr_t attr;
pthread_attr_init(&attr);
if (!detach)
#if defined( PTHREAD_CREATE_JOINABLE ) || defined( PTHREAD_UNDETACHED )
if (!detach) {
#if defined( PTHREAD_CREATE_JOINABLE )
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
#else
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
#endif
#ifdef PTHREAD_CREATE_DETACHED
} else {
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
#endif
}
#endif
rtn = pthread_create( thread, &attr, start_routine, arg );
#if !defined( PTHREAD_CREATE_JOINABLE ) && !defined( PTHREAD_UNDETACHED )
if( detach ) {
(void) pthread_detach( *thread );
}
#endif
#else
rtn = pthread_create( thread, LDAP_INT_THREAD_ATTR_DEFAULT,
start_routine, arg );
#endif
if( detach ) {
#ifdef HAVE_PTHREADS_FINAL
pthread_detach( *thread );
#else
pthread_detach( thread );
#endif
}
#endif
return rtn;
}

View File

@ -1,46 +0,0 @@
/* $OpenLDAP$ */
#include "portable.h"
#ifndef HAVE_TEMPNAM
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/unistd.h>
#include "lutil.h"
char *
(tempnam)( const char *dir, const char *pfx )
{
char *s;
if ( dir == NULL ) {
dir = LDAP_TMPDIR;
}
/*
* allocate space for dir + '/' + pfx (up to 5 chars) + 6 trailing 'X's + 0 byte
*/
if (( s = (char *)malloc( strlen( dir ) + 14 )) == NULL ) {
return( NULL );
}
strcpy( s, dir );
strcat( s, "/" );
if ( pfx != NULL ) {
strcat( s, pfx );
}
strcat( s, "XXXXXX" );
mktemp( s );
if ( *s == '\0' ) {
free( s );
s = NULL;
}
return( s );
}
#endif /* TEMPNAM */