X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fdaemon.c;h=a9372fdac21ac383649df8a66e7cc0140ef8d968;hb=d9cebead9f0edee451406384da7724dba8073780;hp=eded4e8f8c78cc8d7b9e67784b1eac7faf5bb2e9;hpb=2b62024753180017a640443d8f993269156543dd;p=openldap diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index eded4e8f8c..a9372fdac2 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -36,9 +36,14 @@ int deny_severity = LOG_NOTICE; int dtblsize; Connection *c; +static int slapd_shutdown = 0; static void set_shutdown(int sig); static void do_nothing (int sig); +/* a link to the slapd.conf configuration parameters */ +extern char *slapd_pid_file; +extern char *slapd_args_file; + void * slapd_daemon( void *port @@ -73,6 +78,7 @@ slapd_daemon( for ( i = 0; i < dtblsize; i++ ) { c[i].c_dn = NULL; + c[i].c_cdn = NULL; c[i].c_addr = NULL; c[i].c_domain = NULL; c[i].c_ops = NULL; @@ -134,21 +140,21 @@ slapd_daemon( (void) SIGNAL( SIGHUP, set_shutdown ); Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 ); -#ifdef SLAPD_PIDFILE - if ( (fp = fopen( SLAPD_PIDFILE, "w" )) != NULL ) { + + if (( slapd_pid_file != NULL ) && + (( fp = fopen( slapd_pid_file, "w" )) != NULL )) { fprintf( fp, "%d\n", (int) getpid() ); fclose( fp ); } -#endif -#ifdef SLAPD_ARGSFILE - if ( (fp = fopen( SLAPD_ARGSFILE, "w" )) != NULL ) { + + if (( slapd_args_file != NULL ) && + (( fp = fopen( slapd_args_file, "w" )) != NULL )) { for ( i = 0; i < g_argc; i++ ) { fprintf( fp, "%s ", g_argv[i] ); } fprintf( fp, "\n" ); fclose( fp ); } -#endif while ( !slapd_shutdown ) { struct sockaddr_in from; @@ -236,14 +242,9 @@ slapd_daemon( "FIONBIO ioctl on %d failed\n", ns, 0, 0 ); } - c[ns].c_sb.sb_sd = ns; Debug( LDAP_DEBUG_CONNS, "new connection on %d\n", ns, 0, 0 ); - pthread_mutex_lock( &ops_mutex ); - c[ns].c_connid = num_conns++; - pthread_mutex_unlock( &ops_mutex ); - len = sizeof(from); if ( getpeername( ns, (struct sockaddr *) &from, &len ) @@ -283,9 +284,9 @@ slapd_daemon( STRING_UNKNOWN)) { /* DENY ACCESS */ - Statslog( LDAP_DEBUG_STATS, - "conn=%d fd=%d connection from %s (%s) denied.\n", - c[ns].c_connid, ns, + Statslog( LDAP_DEBUG_ANY, + "fd=%d connection from %s (%s) denied.\n", + ns, client_name == NULL ? "unknown" : client_name, client_addr == NULL ? "unknown" : client_addr, 0 ); @@ -296,6 +297,11 @@ slapd_daemon( } #endif /* HAVE_TCPD */ + c[ns].c_sb.sb_sd = ns; + pthread_mutex_lock( &ops_mutex ); + c[ns].c_connid = num_conns++; + pthread_mutex_unlock( &ops_mutex ); + Statslog( LDAP_DEBUG_STATS, "conn=%d fd=%d connection from %s (%s) accepted.\n", c[ns].c_connid, ns, @@ -320,6 +326,10 @@ slapd_daemon( free( c[ns].c_dn ); c[ns].c_dn = NULL; } + if ( c[ns].c_cdn != NULL ) { + free( c[ns].c_cdn ); + c[ns].c_cdn = NULL; + } pthread_mutex_unlock( &c[ns].c_dnmutex ); c[ns].c_starttime = currenttime; c[ns].c_opsinitiated = 0; @@ -369,14 +379,13 @@ slapd_daemon( } close( tcps ); + pthread_mutex_lock( &active_threads_mutex ); Debug( LDAP_DEBUG_ANY, "slapd shutting down - waiting for %d threads to terminate\n", active_threads, 0, 0 ); while ( active_threads > 0 ) { - pthread_mutex_unlock( &active_threads_mutex ); - pthread_yield(); - pthread_mutex_lock( &active_threads_mutex ); + pthread_cond_wait(&active_threads_cond, &active_threads_mutex); } pthread_mutex_unlock( &active_threads_mutex );