From a44181d6b5b824b9adacad99171657d95171218d Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 10 Nov 1998 19:35:42 +0000 Subject: [PATCH] Fix (I hope) threading issues with DCE Threads. --- CHANGES | 6 ++++++ servers/slapd/connection.c | 17 +++++++++++++++++ servers/slapd/main.c | 37 +++++++++++++++++++++++++------------ servers/slurpd/main.c | 24 ++++++++++++++++++++++++ servers/slurpd/replica.c | 16 ++++++++++++++++ 5 files changed, 88 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 64cec68f6f..3d62a66f6e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,9 +1,15 @@ OpenLDAP Change Log +Changes included in OpenLDAP Stable + CVS Tag: OPENLDAP_STABLE + Fixed DCE Threading issues + Changes included in OpenLDAP Stable CVS Tag: OPENLDAP_STABLE_981105 Updated manual pages. Fixed libldif/line64 bug + Fixed slapd/back-passwd sizelimit bug + Fixed slapd/filterentry equality bug Changes included in OpenLDAP Stable CVS Tag: OPENLDAP_STABLE_981027 diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 5c3ebdf708..b5daaee6c3 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -203,6 +203,22 @@ connection_activity( pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); +#if !defined( THREAD_MIT_PTHREADS ) && !defined( THREAD_DCE_PTHREADS ) + /* POSIX_THREADS or compatible + * This is a draft 10 or standard pthreads implementation + */ + if ( pthread_create( &arg->co_op->o_tid, &attr, + (void *) connection_operation, (void *) arg ) != 0 ) { + Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 ); + } else { + pthread_mutex_lock( &active_threads_mutex ); + active_threads++; + pthread_mutex_unlock( &active_threads_mutex ); + } +#else /* draft 4 */ + /* + * This is a draft 4 or earlier pthreads implementation + */ if ( pthread_create( &arg->co_op->o_tid, attr, (void *) connection_operation, (void *) arg ) != 0 ) { Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 ); @@ -211,5 +227,6 @@ connection_activity( active_threads++; pthread_mutex_unlock( &active_threads_mutex ); } +#endif /* draft 4 */ pthread_attr_destroy( &attr ); } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 01930b9709..7ea253bdf6 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -10,16 +10,17 @@ #include "slap.h" #include "ldapconfig.h" -extern void daemon(); +extern void slapd_daemon(); extern int lber_debug; extern char Versionstr[]; + /* * read-only global variables or variables only written by the listener * thread (after they are initialized) - no need to protect them with a mutex. */ -int ldap_debug; +int ldap_debug = 0; #ifdef LDAP_DEBUG int ldap_syslog = LDAP_DEBUG_STATS; #else @@ -55,15 +56,12 @@ pthread_mutex_t num_sent_mutex; */ pthread_mutex_t entry2str_mutex; pthread_mutex_t replog_mutex; -#ifndef sunos5 -pthread_mutex_t regex_mutex; -#endif static usage( name ) char *name; { - fprintf( stderr, "usage: %s [-d debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name ); + fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name ); } main( argc, argv ) @@ -105,19 +103,19 @@ main( argc, argv ) LDAP_DEBUG_CONFIG ); printf( "\tLDAP_DEBUG_ACL\t\t%d\n", LDAP_DEBUG_ACL ); - printf( "\tLDAP_DEBUG_STATS\t\t%d\n", + printf( "\tLDAP_DEBUG_STATS\t%d\n", LDAP_DEBUG_STATS ); - printf( "\tLDAP_DEBUG_STATS2\t\t%d\n", + printf( "\tLDAP_DEBUG_STATS2\t%d\n", LDAP_DEBUG_STATS2 ); - printf( "\tLDAP_DEBUG_SHELL\t\t%d\n", + printf( "\tLDAP_DEBUG_SHELL\t%d\n", LDAP_DEBUG_SHELL ); - printf( "\tLDAP_DEBUG_PARSE\t\t%d\n", + printf( "\tLDAP_DEBUG_PARSE\t%d\n", LDAP_DEBUG_PARSE ); printf( "\tLDAP_DEBUG_ANY\t\t%d\n", LDAP_DEBUG_ANY ); exit( 0 ); } else { - ldap_debug = atoi( optarg ); + ldap_debug |= atoi( optarg ); lber_debug = (ldap_debug & LDAP_DEBUG_BER); } break; @@ -184,12 +182,27 @@ main( argc, argv ) pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); - if ( pthread_create( &listener_tid, attr, (void *) daemon, +#if !defined( THREAD_MIT_PTHREADS ) && !defined( THREAD_DCE_PTHREADS ) + /* POSIX_THREADS or compatible + * This is a draft 10 or standard pthreads implementation + */ + if ( pthread_create( &listener_tid, &attr, (void *) slapd_daemon, + (void *) port ) != 0 ) { + Debug( LDAP_DEBUG_ANY, + "listener pthread_create failed\n", 0, 0, 0 ); + exit( 1 ); + } +#else /* draft 4 */ + /* + * This is a draft 4 or earlier pthreads implementation + */ + if ( pthread_create( &listener_tid, attr, (void *) slapd_daemon, (void *) port ) != 0 ) { Debug( LDAP_DEBUG_ANY, "listener pthread_create failed\n", 0, 0, 0 ); exit( 1 ); } +#endif /* draft 4 */ pthread_attr_destroy( &attr ); pthread_join( listener_tid, (void *) &status ); pthread_exit( 0 ); diff --git a/servers/slurpd/main.c b/servers/slurpd/main.c index a3b935faa5..e1e8fa60d5 100644 --- a/servers/slurpd/main.c +++ b/servers/slurpd/main.c @@ -121,6 +121,21 @@ main( * Start the main file manager thread (in fm.c). */ pthread_attr_init( &attr ); +#if !defined( THREAD_MIT_PTHREADS ) && !defined( THREAD_DCE_PTHREADS ) + /* POSIX_THREADS or compatible + * This is a draft 10 or standard pthreads implementation + */ + if ( pthread_create( &(sglob->fm_tid), &attr, (void *) fm, (void *) NULL ) + != 0 ) { + Debug( LDAP_DEBUG_ANY, "file manager pthread_create failed\n", + 0, 0, 0 ); + exit( 1 ); + + } +#else /* draft 4 */ + /* + * This is a draft 4 or earlier pthreads implementation + */ if ( pthread_create( &(sglob->fm_tid), attr, (void *) fm, (void *) NULL ) != 0 ) { Debug( LDAP_DEBUG_ANY, "file manager pthread_create failed\n", @@ -128,17 +143,26 @@ main( exit( 1 ); } +#endif /* draft 4 */ pthread_attr_destroy( &attr ); /* * Wait for the fm thread to finish. */ +#ifdef POSIX_THREADS + pthread_join( sglob->fm_tid, (void *) NULL ); +#else pthread_join( sglob->fm_tid, (void *) &status ); +#endif /* * Wait for the replica threads to finish. */ for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) { +#ifdef POSIX_THREADS + pthread_join( sglob->replicas[ i ]->ri_tid, (void *) NULL ); +#else pthread_join( sglob->replicas[ i ]->ri_tid, (void *) &status ); +#endif } Debug( LDAP_DEBUG_ANY, "slurpd: terminating normally\n", 0, 0, 0 ); sglob->slurpd_shutdown = 1; diff --git a/servers/slurpd/replica.c b/servers/slurpd/replica.c index ed25a62907..1b5c085ad7 100644 --- a/servers/slurpd/replica.c +++ b/servers/slurpd/replica.c @@ -59,6 +59,21 @@ start_replica_thread( pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); +#if !defined( THREAD_MIT_PTHREADS ) && !defined( THREAD_DCE_PTHREADS ) + /* POSIX_THREADS or compatible + * This is a draft 10 or standard pthreads implementation + */ + if ( pthread_create( &(ri->ri_tid), &attr, (void *) replicate, + (void *) ri ) != 0 ) { + Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n", + ri->ri_hostname, ri->ri_port, 0 ); + pthread_attr_destroy( &attr ); + return -1; + } +#else /* draft 4 */ + /* + * This is a draft 4 or earlier pthreads implementation + */ if ( pthread_create( &(ri->ri_tid), attr, (void *) replicate, (void *) ri ) != 0 ) { Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n", @@ -66,6 +81,7 @@ start_replica_thread( pthread_attr_destroy( &attr ); return -1; } +#endif /* draft 4 */ pthread_attr_destroy( &attr ); return 0; } -- 2.47.2