]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/main.c
Fix dbcache/entry lock deadlock. If dbcache lock is held, it's
[openldap] / servers / slapd / main.c
index 30dc6cf9afcf2142356ee94c491d6500d98460e8..3a2a136c276d1e20fae96bcd4c41f2605be64ed9 100644 (file)
 #include "lutil.h"                     /* Get lutil_detach() */
 
 
-/*
- * 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            slap_debug = 0;
-
-#ifdef LDAP_DEBUG
-int            ldap_syslog = LDAP_DEBUG_STATS;
-#else
-int            ldap_syslog;
-#endif
-
-int            ldap_syslog_level = LOG_DEBUG;
-int            udp;
-char           *default_referral;
-char           *configfile;
-time_t         starttime;
-pthread_t      listener_tid;
-int            g_argc;
-char           **g_argv;
-/*
- * global variables that need mutex protection
- */
-time_t         currenttime;
-pthread_mutex_t        currenttime_mutex;
-pthread_mutex_t        strtok_mutex;
-int            active_threads;
-pthread_mutex_t        active_threads_mutex;
-pthread_mutex_t        new_conn_mutex;
-#ifdef SLAPD_CRYPT
-pthread_mutex_t crypt_mutex;
-#endif
-long           ops_initiated;
-long           ops_completed;
-int            num_conns;
-pthread_mutex_t        ops_mutex;
-long           num_entries_sent;
-long           num_bytes_sent;
-pthread_mutex_t        num_sent_mutex;
-/*
- * these mutexes must be used when calling the entry2str()
- * routine since it returns a pointer to static data.
- */
-pthread_mutex_t        entry2str_mutex;
-pthread_mutex_t        replog_mutex;
-
 /*
  * when more than one slapd is running on one machine, each one might have
  * it's own LOCAL for syslogging and must have its own pid/args files
@@ -95,12 +49,6 @@ static int   cnvt_str2int();
 
 #endif  /* LOG_LOCAL4 */
 
-/*
- * the server's name must be accessible from the daemon module,
- * to construct the pid/args file names
- */
-char  *serverName = NULL;
-
 
 static void
 usage( char *name )
@@ -118,11 +66,14 @@ main( int argc, char **argv )
        int             i;
        int             inetd = 0;
        int             port;
+       int             udp;
        Backend         *be = NULL;
        FILE            *fp = NULL;
 #ifdef LOG_LOCAL4
     int     syslogUser = DEFAULT_SYSLOG_USER;
 #endif
+       char            *configfile;
+       char        *serverName;
 
        configfile = SLAPD_DEFAULT_CONFIGFILE;
        port = LDAP_PORT;
@@ -244,18 +195,16 @@ main( int argc, char **argv )
 
                time( &starttime );
 
-               if ( pthread_create( &listener_tid, NULL, slapd_daemon,
-                   (void *) port ) != 0 ) {
+               if ( status = ldap_pvt_thread_create( &listener_tid, 0,
+                       slapd_daemon, (void *) port ) != 0 )
+               {
                        Debug( LDAP_DEBUG_ANY,
-                           "listener pthread_create failed\n", 0, 0, 0 );
+                           "listener ldap_pvt_thread_create failed (%d)\n", status, 0, 0 );
                        exit( 1 );
                }
 
-#ifdef HAVE_PHREADS_FINAL
-               pthread_join( listener_tid, (void *) NULL );
-#else
-               pthread_join( listener_tid, (void *) &status );
-#endif
+               /* wait for the listener thread to complete */
+               ldap_pvt_thread_join( listener_tid, (void *) NULL );
 
                return 0;
 
@@ -270,6 +219,7 @@ main( int argc, char **argv )
                struct hostent          *hp;
 
                c.c_dn = NULL;
+               c.c_cdn = NULL;
                c.c_ops = NULL;
                c.c_sb.sb_sd = 0;
                c.c_sb.sb_options = 0;
@@ -277,9 +227,9 @@ main( int argc, char **argv )
                c.c_sb.sb_ber.ber_buf = NULL;
                c.c_sb.sb_ber.ber_ptr = NULL;
                c.c_sb.sb_ber.ber_end = NULL;
-               pthread_mutex_init( &c.c_dnmutex, pthread_mutexattr_default );
-               pthread_mutex_init( &c.c_opsmutex, pthread_mutexattr_default );
-               pthread_mutex_init( &c.c_pdumutex, pthread_mutexattr_default );
+               ldap_pvt_thread_mutex_init( &c.c_dnmutex );
+               ldap_pvt_thread_mutex_init( &c.c_opsmutex );
+               ldap_pvt_thread_mutex_init( &c.c_pdumutex );
 #ifdef notdefcldap
                c.c_sb.sb_addrs = (void **) saddrlist;
                c.c_sb.sb_fromaddr = &faddr;
@@ -309,9 +259,9 @@ main( int argc, char **argv )
 
                while ( (tag = ber_get_next( &c.c_sb, &len, &ber ))
                    == LDAP_TAG_MESSAGE ) {
-                       pthread_mutex_lock( &currenttime_mutex );
+                       ldap_pvt_thread_mutex_lock( &currenttime_mutex );
                        time( &currenttime );
-                       pthread_mutex_unlock( &currenttime_mutex );
+                       ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
 
                        if ( (tag = ber_get_int( &ber, &msgid ))
                            != LDAP_TAG_MSGID ) {