X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fdaemon.c;h=b0db47f7652cb2acd6bf42c819a4a2a399c828ca;hb=9647ccd9456b8781066dbba5a063bf6c6c9dab6d;hp=5aec3841081e039d8708fd20968abb1fa7b5c667;hpb=0e69c86461bbe8460bdf407db53659c4ac02ce70;p=openldap diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 5aec384108..b0db47f765 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -1,7 +1,26 @@ /* $OpenLDAP$ */ -/* - * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2003 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* Portions Copyright (c) 1995 Regents of the University of Michigan. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that this notice is preserved and that due credit is given + * to the University of Michigan at Ann Arbor. The name of the University + * may not be used to endorse or promote products derived from this + * software without specific prior written permission. This software + * is provided ``as is'' without express or implied warranty. */ #include "portable.h" @@ -20,6 +39,8 @@ #include "lutil.h" #include "slap.h" +#include "ldap_rq.h" + #ifdef HAVE_TCPD #include #define SLAP_STRING_UNKNOWN STRING_UNKNOWN @@ -51,6 +72,7 @@ Listener **slap_listeners = NULL; #define SLAPD_LISTEN 10 static ber_socket_t wake_sds[2]; +static int emfile; #if defined(NO_THREADS) || defined(HAVE_GNU_PTH) static int waking; @@ -65,6 +87,7 @@ do { if (w) tcp_write( wake_sds[1], "0", 1 ); } while(0) static #endif volatile sig_atomic_t slapd_shutdown = 0, slapd_gentle_shutdown = 0; +volatile sig_atomic_t slapd_abrupt_shutdown = 0; static struct slap_daemon { ldap_pvt_thread_mutex_t sd_mutex; @@ -107,7 +130,7 @@ void slapd_slp_init( const char* urls ) { if( strcmp( slapd_srvurls[i], "ldap:///" ) == 0) { char *host = ldap_pvt_get_fqdn( NULL ); if ( host != NULL ) { - slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i], + slapd_srvurls[i] = (char *) ch_realloc( slapd_srvurls[i], strlen( host ) + sizeof( LDAP_SRVTYPE_PREFIX ) ); strcpy( lutil_strcopy(slapd_srvurls[i], @@ -119,7 +142,7 @@ void slapd_slp_init( const char* urls ) { } else if ( strcmp( slapd_srvurls[i], "ldaps:///" ) == 0) { char *host = ldap_pvt_get_fqdn( NULL ); if ( host != NULL ) { - slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i], + slapd_srvurls[i] = (char *) ch_realloc( slapd_srvurls[i], strlen( host ) + sizeof( LDAPS_SRVTYPE_PREFIX ) ); strcpy( lutil_strcopy(slapd_srvurls[i], @@ -155,6 +178,8 @@ void slapd_slp_regreport( void slapd_slp_reg() { int i; + if( slapd_srvurls == NULL ) return; + for( i=0; slapd_srvurls[i] != NULL; i++ ) { if( strncmp( slapd_srvurls[i], LDAP_SRVTYPE_PREFIX, sizeof( LDAP_SRVTYPE_PREFIX ) - 1 ) == 0 || @@ -176,6 +201,8 @@ void slapd_slp_reg() { void slapd_slp_dereg() { int i; + if( slapd_srvurls == NULL ) return; + for( i=0; slapd_srvurls[i] != NULL; i++ ) { SLPDereg( slapd_hslp, slapd_srvurls[i], @@ -187,8 +214,13 @@ void slapd_slp_dereg() { /* * Add a descriptor to daemon control + * + * If isactive, the descriptor is a live server session and is subject + * to idletimeout control. Otherwise, the descriptor is a passive + * listener or an outbound client session, and not subject to + * idletimeout. */ -static void slapd_add(ber_socket_t s) { +static void slapd_add(ber_socket_t s, int isactive) { ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); assert( !FD_ISSET( s, &slap_daemon.sd_actives )); @@ -201,7 +233,9 @@ static void slapd_add(ber_socket_t s) { } #endif - slap_daemon.sd_nactives++; + if ( isactive ) { + slap_daemon.sd_nactives++; + } FD_SET( s, &slap_daemon.sd_actives ); FD_SET( s, &slap_daemon.sd_readers ); @@ -223,10 +257,12 @@ static void slapd_add(ber_socket_t s) { /* * Remove the descriptor from daemon control */ -void slapd_remove(ber_socket_t s, int wake) { +void slapd_remove(ber_socket_t s, int wasactive, int wake) { ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); - slap_daemon.sd_nactives--; + if ( wasactive ) { + slap_daemon.sd_nactives--; + } #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, DETAIL1, @@ -243,6 +279,28 @@ void slapd_remove(ber_socket_t s, int wake) { FD_CLR( s, &slap_daemon.sd_readers ); FD_CLR( s, &slap_daemon.sd_writers ); + /* If we ran out of file descriptors, we dropped a listener from + * the select() loop. Now that we're removing a session from our + * control, we can try to resume a dropped listener to use. + */ + if ( emfile ) { + int i; + for ( i = 0; slap_listeners[i] != NULL; i++ ) { + if ( slap_listeners[i]->sl_sd != AC_SOCKET_INVALID ) { + if ( slap_listeners[i]->sl_sd == s ) continue; + if ( slap_listeners[i]->sl_is_mute ) { + slap_listeners[i]->sl_is_mute = 0; + emfile--; + break; + } + } + } + /* Walked the entire list without enabling anything; emfile + * counter is stale. Reset it. + */ + if ( slap_listeners[i] == NULL ) + emfile = 0; + } ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); WAKE_LISTENER(wake || slapd_gentle_shutdown == 2); } @@ -613,6 +671,7 @@ static int slap_open_listener( } l.sl_url.bv_val = NULL; + l.sl_is_mute = 0; #ifndef HAVE_TLS if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) { @@ -663,9 +722,6 @@ static int slap_open_listener( return -1; #endif } else { -#ifdef LDAP_CONNECTIONLESS - l.sl_is_udp = ( tmp == LDAP_PROTO_UDP ); -#endif if( lud->lud_host == NULL || lud->lud_host[0] == '\0' || strcmp(lud->lud_host, "*") == 0 ) { @@ -674,12 +730,15 @@ static int slap_open_listener( err = slap_get_listener_addresses(lud->lud_host, port, &sal); } } +#ifdef LDAP_CONNECTIONLESS + l.sl_is_udp = ( tmp == LDAP_PROTO_UDP ); +#endif #if defined(LDAP_PF_LOCAL) || defined(SLAP_X_LISTENER_MOD) if ( lud->lud_exts ) { err = get_url_perms( lud->lud_exts, &l.sl_perms, &crit ); } else { - l.sl_perms = S_IRWXU; + l.sl_perms = S_IRWXU | S_IRWXO; } #endif /* LDAP_PF_LOCAL || SLAP_X_LISTENER_MOD */ @@ -699,15 +758,21 @@ static int slap_open_listener( psal = sal; while ( *sal != NULL ) { + char *af; switch( (*sal)->sa_family ) { case AF_INET: + af = "IPv4"; + break; #ifdef LDAP_PF_INET6 case AF_INET6: + af = "IPv6"; + break; #endif #ifdef LDAP_PF_LOCAL case AF_LOCAL: -#endif + af = "Local"; break; +#endif default: sal++; continue; @@ -720,12 +785,12 @@ static int slap_open_listener( int err = sock_errno(); #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, ERR, - "slap_open_listener: socket() failed errno=%d (%s)\n", - err, sock_errstr(err), 0 ); + "slap_open_listener: %s socket() failed errno=%d (%s)\n", + af, err, sock_errstr(err) ); #else Debug( LDAP_DEBUG_ANY, - "daemon: socket() failed errno=%d (%s)\n", err, - sock_errstr(err), 0 ); + "daemon: %s socket() failed errno=%d (%s)\n", + af, err, sock_errstr(err) ); #endif sal++; continue; @@ -738,8 +803,8 @@ static int slap_open_listener( "great %ld\n", (long)l.sl_sd, (long)dtblsize, 0 ); #else Debug( LDAP_DEBUG_ANY, - "daemon: listener descriptor %ld is too great %ld\n", - (long) l.sl_sd, (long) dtblsize, 0 ); + "daemon: listener descriptor %ld is too great %ld\n", + (long) l.sl_sd, (long) dtblsize, 0 ); #endif tcp_close( l.sl_sd ); sal++; @@ -756,7 +821,7 @@ static int slap_open_listener( /* enable address reuse */ tmp = 1; rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR, - (char *) &tmp, sizeof(tmp) ); + (char *) &tmp, sizeof(tmp) ); if ( rc == AC_SOCKET_ERROR ) { int err = sock_errno(); #ifdef NEW_LOGGING @@ -826,6 +891,7 @@ static int slap_open_listener( #ifdef LDAP_PF_LOCAL case AF_LOCAL: { char *addr = ((struct sockaddr_un *)*sal)->sun_path; +#if 0 /* don't muck with socket perms */ if ( chmod( addr, l.sl_perms ) < 0 && crit ) { int err = sock_errno(); #ifdef NEW_LOGGING @@ -840,6 +906,7 @@ static int slap_open_listener( slap_free_listener_addresses(psal); return -1; } +#endif l.sl_name.bv_len = strlen(addr) + sizeof("PATH=") - 1; l.sl_name.bv_val = ber_memalloc( l.sl_name.bv_len + 1 ); snprintf( l.sl_name.bv_val, l.sl_name.bv_len + 1, @@ -998,7 +1065,7 @@ int slapd_daemon_init( const char *urls ) for( i=0; u[i] != NULL; i++ ) { #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, DETAIL1, - "slap_daemon_init: listen on %s\n.", u[i], 0, 0 ); + "slap_daemon_init: listen on %s\n", u[i], 0, 0 ); #else Debug( LDAP_DEBUG_TRACE, "daemon_init: listen on %s\n", u[i], 0, 0 ); @@ -1080,7 +1147,7 @@ close_listeners( for ( l = 0; slap_listeners[l] != NULL; l++ ) { if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) { if ( remove ) - slapd_remove( slap_listeners[l]->sl_sd, 0 ); + slapd_remove( slap_listeners[l]->sl_sd, 0, 0 ); #ifdef LDAP_PF_LOCAL if ( slap_listeners[l]->sl_sa.sa_addr.sa_family == AF_LOCAL ) { unlink( slap_listeners[l]->sl_sa.sa_un_addr.sun_path ); @@ -1105,11 +1172,24 @@ slapd_daemon_task( { int l; time_t last_idle_check = 0; - time( &starttime ); + struct timeval idle; + +#define SLAPD_IDLE_CHECK_LIMIT 4 if ( global_idletimeout > 0 ) { last_idle_check = slap_get_time(); + /* Set the select timeout. + * Don't just truncate, preserve the fractions of + * seconds to prevent sleeping for zero time. + */ + idle.tv_sec = global_idletimeout/SLAPD_IDLE_CHECK_LIMIT; + idle.tv_usec = global_idletimeout - idle.tv_sec * SLAPD_IDLE_CHECK_LIMIT; + idle.tv_usec *= 1000000 / SLAPD_IDLE_CHECK_LIMIT; + } else { + idle.tv_sec = 0; + idle.tv_usec = 0; } + for ( l = 0; slap_listeners[l] != NULL; l++ ) { if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ) continue; @@ -1119,7 +1199,7 @@ slapd_daemon_task( * are unnecessary. */ if ( slap_listeners[l]->sl_is_udp ) { - slapd_add( slap_listeners[l]->sl_sd ); + slapd_add( slap_listeners[l]->sl_sd, 1 ); continue; } #endif @@ -1176,7 +1256,7 @@ slapd_daemon_task( return( (void*)-1 ); } - slapd_add( slap_listeners[l]->sl_sd ); + slapd_add( slap_listeners[l]->sl_sd, 0 ); } #ifdef HAVE_NT_SERVICE_MANAGER @@ -1193,32 +1273,28 @@ slapd_daemon_task( ber_socket_t nfds; #define SLAPD_EBADF_LIMIT 16 int ebadf = 0; - int emfile = 0; -#define SLAPD_IDLE_CHECK_LIMIT 4 time_t now; - fd_set readfds; fd_set writefds; Sockaddr from; -#if defined(SLAPD_RLOOKUPS) - struct hostent *hp; -#endif - struct timeval zero; + struct timeval tv; struct timeval *tvp; - if( emfile ) { - now = slap_get_time(); + struct timeval *cat; + time_t tdelta = 1; + struct re_s* rtask; + now = slap_get_time(); + + if( ( global_idletimeout > 0 ) && + difftime( last_idle_check + + global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, now ) < 0 ) { connections_timeout_idle( now ); + last_idle_check = now; } - else if ( global_idletimeout > 0 ) { - now = slap_get_time(); - if ( difftime( last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, now ) < 0 ) { - connections_timeout_idle( now ); - } - } + tv = idle; #ifdef SIGHUP if( slapd_gentle_shutdown ) { @@ -1244,8 +1320,7 @@ slapd_daemon_task( FD_ZERO( &writefds ); FD_ZERO( &readfds ); - zero.tv_sec = 0; - zero.tv_usec = 0; + at = 0; ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); @@ -1268,6 +1343,9 @@ slapd_daemon_task( for ( l = 0; slap_listeners[l] != NULL; l++ ) { if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ) continue; + if ( slap_listeners[l]->sl_is_mute ) + FD_CLR( slap_listeners[l]->sl_sd, &readfds ); + else if (!FD_ISSET(slap_listeners[l]->sl_sd, &readfds)) FD_SET( slap_listeners[l]->sl_sd, &readfds ); } @@ -1277,19 +1355,51 @@ slapd_daemon_task( #else nfds = dtblsize; #endif + if ( global_idletimeout && slap_daemon.sd_nactives ) + at = 1; ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); - at = ldap_pvt_thread_pool_backload(&connection_pool); - -#if defined( HAVE_YIELDING_SELECT ) || defined( NO_THREADS ) - tvp = NULL; -#else - tvp = at ? &zero : NULL; + if ( at +#if defined(HAVE_YIELDING_SELECT) || defined(NO_THREADS) + && ( tv.tv_sec || tv.tv_usec ) #endif + ) + tvp = &tv; + else + tvp = NULL; + + ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex ); + rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat ); + while ( cat && cat->tv_sec && cat->tv_sec <= now ) { + if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) { + ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 ); + } else { + ldap_pvt_runqueue_runtask( &syncrepl_rq, rtask ); + ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 ); + ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex ); + ldap_pvt_thread_pool_submit( &connection_pool, + rtask->routine, (void *) rtask ); + ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex ); + } + rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat ); + } + ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex ); + + if ( cat != NULL ) { + time_t diff = difftime( cat->tv_sec, now ); + if ( diff == 0 ) + diff = tdelta; + if ( tvp == NULL || diff < tv.tv_sec ) { + tv.tv_sec = diff; + tv.tv_usec = 0; + tvp = &tv; + } + } for ( l = 0; slap_listeners[l] != NULL; l++ ) { - if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ) + if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID || + slap_listeners[l]->sl_is_mute ) continue; #ifdef NEW_LOGGING @@ -1351,6 +1461,7 @@ slapd_daemon_task( Debug( LDAP_DEBUG_CONNS, "daemon: select timeout - yielding\n", 0, 0, 0 ); #endif + ldap_pvt_thread_yield(); continue; @@ -1382,19 +1493,20 @@ slapd_daemon_task( socklen_t len = sizeof(from); long id; slap_ssf_t ssf = 0; - char *authid = NULL; + struct berval authid = { 0, NULL }; #ifdef SLAPD_RLOOKUPS - char *hebuf = NULL; + char hbuf[NI_MAXHOST]; #endif char *dnsname = NULL; char *peeraddr = NULL; #ifdef LDAP_PF_LOCAL - char peername[MAXPATHLEN + sizeof("PATH=")]; + char peername[MAXPATHLEN + sizeof("PATH=")]; #elif defined(LDAP_PF_INET6) - char peername[sizeof("IP=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535")]; + char peername[sizeof( + "IP=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535")]; #else - char peername[sizeof("IP=255.255.255.255:65336")]; + char peername[sizeof("IP=255.255.255.255:65336")]; #endif /* LDAP_PF_LOCAL */ peername[0] = '\0'; @@ -1404,7 +1516,7 @@ slapd_daemon_task( if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) ) continue; - + #ifdef LDAP_CONNECTIONLESS if ( slap_listeners[l]->sl_is_udp ) { /* The first time we receive a query, we set this @@ -1412,60 +1524,55 @@ slapd_daemon_task( * of the slapd. */ if ( slap_listeners[l]->sl_is_udp < 2 ) { - id = connection_init( - slap_listeners[l]->sl_sd, - slap_listeners[l], "", "", - 2, ssf, authid ); + id = connection_init( + slap_listeners[l]->sl_sd, + slap_listeners[l], "", "", + CONN_IS_UDP, ssf, NULL ); slap_listeners[l]->sl_is_udp++; } continue; } #endif + /* Don't need to look at this in the data loops */ + FD_CLR( slap_listeners[l]->sl_sd, &readfds ); + FD_CLR( slap_listeners[l]->sl_sd, &writefds ); + s = accept( slap_listeners[l]->sl_sd, (struct sockaddr *) &from, &len ); if ( s == AC_SOCKET_INVALID ) { int err = sock_errno(); + if( #ifdef EMFILE - if( err == EMFILE ) { - emfile++; - } else + err == EMFILE || #endif #ifdef ENFILE - if( err == ENFILE ) { - emfile++; - } else + err == ENFILE || #endif + 0 ) { - emfile=0; + ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); + emfile++; + /* Stop listening until an existing session closes */ + slap_listeners[l]->sl_is_mute = 1; + ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); } - if( emfile < 3 ) { #ifdef NEW_LOGGING - LDAP_LOG( CONNECTION, ERR, - "slapd_daemon_task: accept(%ld) failed errno=%d (%s)\n", - (long)slap_listeners[l]->sl_sd, - err, sock_errstr(err) ); + LDAP_LOG( CONNECTION, ERR, + "slapd_daemon_task: accept(%ld) failed errno=%d (%s)\n", + (long)slap_listeners[l]->sl_sd, + err, sock_errstr(err) ); #else - Debug( LDAP_DEBUG_ANY, - "daemon: accept(%ld) failed errno=%d (%s)\n", - (long) slap_listeners[l]->sl_sd, err, - sock_errstr(err) ); -#endif - } else { - /* prevent busy loop */ -# ifdef HAVE_USLEEP - if( emfile % 4 == 3 ) usleep( 250 ); -# else - if( emfile % 8 == 7 ) sleep( 1 ); -# endif - } - + Debug( LDAP_DEBUG_ANY, + "daemon: accept(%ld) failed errno=%d (%s)\n", + (long) slap_listeners[l]->sl_sd, err, + sock_errstr(err) ); +#endif ldap_pvt_thread_yield(); continue; } - emfile = 0; #ifndef HAVE_WINSOCK /* make sure descriptor number isn't too great */ @@ -1563,12 +1670,13 @@ slapd_daemon_task( gid_t gid; if( getpeereid( s, &uid, &gid ) == 0 ) { - authid = ch_malloc( - sizeof("uidNumber=4294967295+gidNumber=4294967295," - "cn=peercred,cn=external,cn=auth")); - sprintf(authid, "uidNumber=%d+gidNumber=%d," + authid.bv_val = ch_malloc( + sizeof("uidnumber=4294967295+gidnumber=4294967295," + "cn=peercred,cn=external,cn=auth")); + authid.bv_len = sprintf( authid.bv_val, + "uidnumber=%d+gidnumber=%d," "cn=peercred,cn=external,cn=auth", - uid, gid); + (int) uid, (int) gid); } } dnsname = "local"; @@ -1615,23 +1723,12 @@ slapd_daemon_task( ) { #ifdef SLAPD_RLOOKUPS if ( use_reverse_lookup ) { - struct hostent he; - int herr; - struct hostent *hp = NULL; -# ifdef LDAP_PF_INET6 - if ( from.sa_addr.sa_family == AF_INET6 ) - ldap_pvt_gethostbyaddr_a( - (char *)&(from.sa_in6_addr.sin6_addr), - sizeof(from.sa_in6_addr.sin6_addr), - AF_INET6, &he, &hebuf, - &hp, &herr ); - else -# endif /* LDAP_PF_INET6 */ - ldap_pvt_gethostbyaddr_a( - (char *) &(from.sa_in_addr.sin_addr), - sizeof(from.sa_in_addr.sin_addr), - AF_INET, &he, &hebuf, &hp, &herr ); - dnsname = hp ? ldap_pvt_str2lower( hp->h_name ) : NULL; + char *herr; + if (ldap_pvt_get_hname( (const struct sockaddr *)&from, len, hbuf, + sizeof(hbuf), &herr ) == 0) { + ldap_pvt_str2lower( hbuf ); + dnsname = hbuf; + } } #else dnsname = NULL; @@ -1645,7 +1742,7 @@ slapd_daemon_task( { /* DENY ACCESS */ Statslog( LDAP_DEBUG_STATS, - "fd=%ld DENIED from %s (%s)", + "fd=%ld DENIED from %s (%s)\n", (long) s, dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN, peeraddr != NULL ? peeraddr : SLAP_STRING_UNKNOWN, @@ -1661,17 +1758,14 @@ slapd_daemon_task( dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN, peername, #ifdef HAVE_TLS - slap_listeners[l]->sl_is_tls, + slap_listeners[l]->sl_is_tls ? CONN_IS_TLS : 0, #else 0, #endif ssf, - authid ); + authid.bv_val ? &authid : NULL ); - if( authid ) ch_free(authid); -#ifdef SLAPD_RLOOKUPS - if( hebuf ) ldap_memfree(hebuf); -#endif + if( authid.bv_val ) ch_free(authid.bv_val); if( id < 0 ) { #ifdef NEW_LOGGING @@ -1694,14 +1788,13 @@ slapd_daemon_task( } Statslog( LDAP_DEBUG_STATS, - "conn=%ld fd=%ld ACCEPT from %s " - "(%s)\n", + "conn=%ld fd=%ld ACCEPT from %s (%s)\n", id, (long) s, peername, slap_listeners[l]->sl_name.bv_val, 0 ); - slapd_add( s ); + slapd_add( s, 1 ); continue; } @@ -1735,23 +1828,7 @@ slapd_daemon_task( #else for ( i = 0; i < nfds; i++ ) { int r, w; - int is_listener = 0; - for ( l = 0; slap_listeners[l] != NULL; l++ ) { - if ( i == slap_listeners[l]->sl_sd ) { -#ifdef LDAP_CONNECTIONLESS - /* The listener is the data port. Don't - * skip it. - */ - if (slap_listeners[l]->sl_is_udp) continue; -#endif - is_listener = 1; - break; - } - } - if ( is_listener ) { - continue; - } r = FD_ISSET( i, &readfds ); w = FD_ISSET( i, &writefds ); if ( r || w ) { @@ -1781,7 +1858,6 @@ slapd_daemon_task( #endif { ber_socket_t wd; - int is_listener = 0; #ifdef HAVE_WINSOCK wd = writefds.fd_array[i]; #else @@ -1791,18 +1867,6 @@ slapd_daemon_task( wd = i; #endif - for ( l = 0; slap_listeners[l] != NULL; l++ ) { - if ( i == slap_listeners[l]->sl_sd ) { -#ifdef LDAP_CONNECTIONLESS - if (slap_listeners[l]->sl_is_udp) continue; -#endif - is_listener = 1; - break; - } - } - if ( is_listener ) { - continue; - } #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, DETAIL2, "slapd_daemon_task: write active on %d\n", wd, 0, 0 ); @@ -1831,8 +1895,6 @@ slapd_daemon_task( #endif { ber_socket_t rd; - int is_listener = 0; - #ifdef HAVE_WINSOCK rd = readfds.fd_array[i]; #else @@ -1842,19 +1904,6 @@ slapd_daemon_task( rd = i; #endif - for ( l = 0; slap_listeners[l] != NULL; l++ ) { - if ( rd == slap_listeners[l]->sl_sd ) { -#ifdef LDAP_CONNECTIONLESS - if (slap_listeners[l]->sl_is_udp) continue; -#endif - is_listener = 1; - break; - } - } - if ( is_listener ) { - continue; - } - #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, DETAIL2, "slapd_daemon_task: read activity on %d\n", rd, 0, 0 ); @@ -1920,11 +1969,18 @@ slapd_daemon_task( #endif } - if( slapd_gentle_shutdown != 2 ) + if( slapd_gentle_shutdown != 2 ) { close_listeners ( 0 ); + } + free ( slap_listeners ); slap_listeners = NULL; + if( !slapd_gentle_shutdown ) { + slapd_abrupt_shutdown = 1; + connections_shutdown(); + } + #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, CRIT, "slapd_daemon_task: shutdown waiting for %d threads to terminate.\n", @@ -2031,11 +2087,13 @@ int sockdestroy(void) RETSIGTYPE slap_sig_shutdown( int sig ) { +#if 0 #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, CRIT, "slap_sig_shutdown: signal %d\n", sig, 0, 0 ); #else Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: signal %d\n", sig, 0, 0); +#endif #endif /* @@ -2046,13 +2104,7 @@ slap_sig_shutdown( int sig ) #if HAVE_NT_SERVICE_MANAGER && SIGBREAK if (is_NT_Service && sig == SIGBREAK) -#ifdef NEW_LOGGING - LDAP_LOG( CONNECTION, CRIT, - "slap_sig_shutdown: SIGBREAK ignored.\n", 0, 0, 0 ); -#else - Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: SIGBREAK ignored.\n", - 0, 0, 0); -#endif + ; else #endif #ifdef SIGHUP @@ -2078,8 +2130,8 @@ slap_sig_wake( int sig ) } -void slapd_add_internal(ber_socket_t s) { - slapd_add(s); +void slapd_add_internal(ber_socket_t s, int isactive) { + slapd_add(s, isactive); } Listener ** slapd_get_listeners(void) {