X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fdaemon.c;h=a9372fdac21ac383649df8a66e7cc0140ef8d968;hb=d9cebead9f0edee451406384da7724dba8073780;hp=48eb7f13d3a5212a2bcab052772c4ad67a6912c0;hpb=3952bc8e95a2b21aced14f890028f12d00e191fa;p=openldap diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 48eb7f13d3..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; @@ -127,37 +133,28 @@ slapd_daemon( } (void) SIGNAL( SIGPIPE, SIG_IGN ); -#ifdef HAVE_LINUX_THREADS - /* - * LinuxThreads are implemented using SIGUSR1/USR2, - * so we'll use SIGSTKFLT and SIGUNUSED - */ - (void) SIGNAL( SIGSTKFLT, do_nothing ); - (void) SIGNAL( SIGUNUSED, set_shutdown ); -#else /* !linux */ - (void) SIGNAL( SIGUSR1, do_nothing ); - (void) SIGNAL( SIGUSR2, set_shutdown ); -#endif /* !linux */ + (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); + (void) SIGNAL( LDAP_SIGUSR2, set_shutdown ); (void) SIGNAL( SIGTERM, set_shutdown ); (void) SIGNAL( SIGINT, set_shutdown ); (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; @@ -198,7 +195,7 @@ slapd_daemon( Debug( LDAP_DEBUG_CONNS, "before select active_threads %d\n", active_threads, 0, 0 ); -#ifdef PREEMPTIVE_THREADS +#if defined( HAVE_YIELDING_SELECT ) || defined( NO_THREADS ) tvp = NULL; #else tvp = active_threads ? &zero : NULL; @@ -245,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 ) @@ -286,13 +278,15 @@ slapd_daemon( } #ifdef HAVE_TCPD - if(!hosts_ctl("slapd", client_name, client_addr, + if(!hosts_ctl("slapd", + client_name != NULL ? client_name : STRING_UNKNOWN, + client_addr != NULL ? client_addr : STRING_UNKNOWN, 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 ); @@ -303,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, @@ -313,13 +312,13 @@ slapd_daemon( if ( c[ns].c_addr != NULL ) { free( c[ns].c_addr ); } - c[ns].c_addr = strdup( client_addr ); + c[ns].c_addr = ch_strdup( client_addr ); if ( c[ns].c_domain != NULL ) { free( c[ns].c_domain ); } - c[ns].c_domain = strdup( client_name == NULL + c[ns].c_domain = ch_strdup( client_name == NULL ? "" : client_name ); pthread_mutex_lock( &c[ns].c_dnmutex ); @@ -327,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; @@ -376,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 ); @@ -401,17 +403,8 @@ set_shutdown( int sig ) { Debug( LDAP_DEBUG_ANY, "slapd got shutdown signal %d\n", sig, 0, 0 ); slapd_shutdown = 1; -#ifdef HAVE_LINUX_THREADS - /* - * LinuxThreads are implemented using SIGUSR1/USR2, - * so we'll use SIGSTKFLT and SIGUNUSED - */ - pthread_kill( listener_tid, SIGSTKFLT ); - (void) SIGNAL( SIGUNUSED, set_shutdown ); -#else /* !linux */ - pthread_kill( listener_tid, SIGUSR1 ); - (void) SIGNAL( SIGUSR2, set_shutdown ); -#endif /* !linux */ + pthread_kill( listener_tid, LDAP_SIGUSR1 ); + (void) SIGNAL( LDAP_SIGUSR2, set_shutdown ); (void) SIGNAL( SIGTERM, set_shutdown ); (void) SIGNAL( SIGINT, set_shutdown ); (void) SIGNAL( SIGHUP, set_shutdown ); @@ -421,13 +414,5 @@ static void do_nothing( int sig ) { Debug( LDAP_DEBUG_TRACE, "slapd got do_nothing signal %d\n", sig, 0, 0 ); -#ifdef HAVE_LINUX_THREADS - /* - * LinuxThreads are implemented using SIGUSR1/USR2, - * so we'll use SIGSTKFLT and SIGUNUSED - */ - (void) SIGNAL( SIGSTKFLT, do_nothing ); -#else /* !linux */ - (void) SIGNAL( SIGUSR1, do_nothing ); -#endif /* !linux */ + (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); }