diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 36e19e9771e6fa22f41337335df945d5720cd5bb..c5f92b8761b306e3c32dbf91fbc0339226a388b1 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -28,7 +28,7 @@ ldbm_cache_open( { struct ldbminfo *li = (struct ldbminfo *) be->be_private; int i, lru, empty; - time_t oldtime, curtime; + time_t oldtime; char buf[MAXPATHLEN]; #ifdef HAVE_ST_BLKSIZE struct stat st; @@ -61,13 +61,12 @@ ldbm_cache_open( #endif - curtime = slap_get_time(); empty = MAXDBCACHE; ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); do { lru = 0; - oldtime = curtime; + oldtime = 1; for ( i = 0; i < MAXDBCACHE; i++ ) { /* see if this slot is free */ if ( li->li_dbcache[i].dbc_name == NULL) { @@ -113,8 +112,9 @@ ldbm_cache_open( } /* keep track of lru db */ - if ( li->li_dbcache[i].dbc_lastref < oldtime - && li->li_dbcache[i].dbc_refcnt == 0 ) + if (( li->li_dbcache[i].dbc_refcnt == 0 ) && + (( oldtime == 1 ) || + ( li->li_dbcache[i].dbc_lastref < oldtime )) ) { lru = i; oldtime = li->li_dbcache[i].dbc_lastref; @@ -170,7 +170,7 @@ ldbm_cache_open( } li->li_dbcache[i].dbc_name = ch_strdup( buf ); li->li_dbcache[i].dbc_refcnt = 1; - li->li_dbcache[i].dbc_lastref = curtime; + li->li_dbcache[i].dbc_lastref = slap_get_time(); li->li_dbcache[i].dbc_flags = flags; li->li_dbcache[i].dbc_dirty = 0; #ifdef HAVE_ST_BLKSIZE diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 1b95248dd6988e0cab6f1352edcbf37151977ebe..3f8d76a2ad9cd0566a1abc331777cb5d49a57fcf 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -299,7 +299,7 @@ searchit: ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex ); /* check time limit */ - if ( tlimit != -1 && slap_get_time() > stoptime ) { + if ( tlimit != -1 && (ID_BLOCK_NIDS(candidates) > 2) && slap_get_time() > stoptime ) { send_search_result( conn, op, LDAP_TIMELIMIT_EXCEEDED, NULL, NULL, v2refs, NULL, nentries ); rc = 0; diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 46d84cfd9c1775a7f60879eaec025b97faeb560f..4d8fa9b3fb80fad30047b634df92b43f9a071a61 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -300,7 +300,13 @@ static Connection* connection_get( ber_socket_t s ) assert( c->c_conn_state != SLAP_C_INVALID ); assert( sd != AC_SOCKET_INVALID ); - c->c_activitytime = slap_get_time(); +#ifdef SLAPD_MONITOR + c->c_activitytime = slap_get_time(); +#else + if( global_idletimeout > 0 ) { + c->c_activitytime = slap_get_time(); + } +#endif } return c; @@ -474,7 +480,13 @@ long connection_init( /* set to zero until bind, implies LDAP_VERSION3 */ c->c_protocol = 0; - c->c_activitytime = c->c_starttime = slap_get_time(); +#ifdef SLAPD_MONITOR + c->c_activitytime = c->c_starttime = slap_get_time(); +#else + if( global_idletimeout > 0 ) { + c->c_activitytime = c->c_starttime = slap_get_time(); + } +#endif #ifdef LDAP_CONNECTIONLESS c->c_is_udp = 0; diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 8e6ef5b1ff66e5f056121d6b680da0432ea5554f..ddb202bfea46408b0b7a5b14872e70601195973a 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -940,9 +940,12 @@ slapd_daemon_task( ) { int l; - time_t last_idle_check = slap_get_time(); + time_t last_idle_check; time( &starttime ); + if ( global_idletimeout > 0 ) { + last_idle_check = slap_get_time(); + } for ( l = 0; slap_listeners[l] != NULL; l++ ) { if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ) continue; @@ -993,7 +996,7 @@ slapd_daemon_task( int emfile = 0; #define SLAPD_IDLE_CHECK_LIMIT 4 - time_t now = slap_get_time(); + time_t now; fd_set readfds; @@ -1006,11 +1009,15 @@ slapd_daemon_task( struct timeval zero; struct timeval *tvp; - if( emfile || ( global_idletimeout > 0 && difftime( - last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, - now ) < 0 )) - { - connections_timeout_idle(now); + if( emfile ) { + now = slap_get_time(); + connections_timeout_idle( 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 ); + } } FD_ZERO( &writefds );