From e12c4ca230a85be7f554a7291e6db5710925e81a Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 13 Jun 2005 19:14:40 +0000 Subject: [PATCH] preemptive time limit check in proxy backends --- servers/slapd/back-ldap/search.c | 15 +++++++-- servers/slapd/back-meta/search.c | 57 +++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 3a16c4d818..19bddf422c 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -137,6 +137,7 @@ ldap_back_search( { struct ldapconn *lc; struct timeval tv; + time_t stoptime; LDAPMessage *res, *e; int rc = 0, @@ -171,6 +172,7 @@ ldap_back_search( if ( op->ors_tlimit != SLAP_NO_LIMIT ) { tv.tv_sec = op->ors_tlimit; tv.tv_usec = 0; + stoptime = op->o_time + op->ors_tlimit; } else { tv.tv_sec = 0; @@ -260,9 +262,18 @@ fail:; tv.tv_usec = 100000; ldap_pvt_thread_yield(); + /* check time limit */ + if ( op->ors_tlimit != SLAP_NO_LIMIT + && slap_get_time() > stoptime ) + { + ldap_abandon_ext( lc->lc_ld, msgid, NULL, NULL ); + rc = rs->sr_err = LDAP_TIMELIMIT_EXCEEDED; + goto finish; + } + } else if ( rc == LDAP_RES_SEARCH_ENTRY ) { - Entry ent = {0}; - struct berval bdn; + Entry ent = { 0 }; + struct berval bdn = BER_BVNULL; int abort = 0; do_retry = 0; diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index fff12ab215..fe1e403a21 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -54,13 +54,13 @@ meta_back_search_start( ) { metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; - struct berval realbase = op->o_req_dn; - int realscope = op->ors_scope; - ber_len_t suffixlen = 0; - struct berval mbase = BER_BVNULL; - struct berval mfilter = BER_BVNULL; - char **mapped_attrs = NULL; - int rc; + struct berval realbase = op->o_req_dn; + int realscope = op->ors_scope; + ber_len_t suffixlen = 0; + struct berval mbase = BER_BVNULL; + struct berval mfilter = BER_BVNULL; + char **mapped_attrs = NULL; + int rc; /* should we check return values? */ if ( op->ors_deref != -1 ) { @@ -228,18 +228,19 @@ done:; int meta_back_search( Operation *op, SlapReply *rs ) { - metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; - metaconn_t *mc; - struct timeval tv = { 0, 0 }; - LDAPMessage *res = NULL, *e; - int rc = 0, sres = LDAP_SUCCESS; - char *matched = NULL; - int i, last = 0, ncandidates = 0, - initial_candidates = 0, candidate_match = 0; - dncookie dc; - int is_ok = 0; - void *savepriv; - SlapReply *candidates = meta_back_candidates_get( op ); + metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; + metaconn_t *mc; + struct timeval tv = { 0, 0 }; + time_t stoptime; + LDAPMessage *res = NULL, *e; + int rc = 0, sres = LDAP_SUCCESS; + char *matched = NULL; + int i, last = 0, ncandidates = 0, + initial_candidates = 0, candidate_match = 0; + dncookie dc; + int is_ok = 0; + void *savepriv; + SlapReply *candidates = meta_back_candidates_get( op ); /* * controls are set in ldap_back_dobind() @@ -321,6 +322,11 @@ meta_back_search( Operation *op, SlapReply *rs ) * but this is necessary for version matching, and for ACL processing. */ + if ( op->ors_tlimit != SLAP_NO_LIMIT ) { + stoptime = op->o_time + op->ors_tlimit; + tv.tv_sec = 0; + } + /* * In case there are no candidates, no cycle takes place... * @@ -358,6 +364,19 @@ meta_back_search( Operation *op, SlapReply *rs ) /* FIXME: res should not need to be freed */ assert( res == NULL ); + /* check time limit */ + if ( op->ors_tlimit != SLAP_NO_LIMIT + && slap_get_time() > stoptime ) + { + doabandon = 1; + rc = rs->sr_err = LDAP_TIMELIMIT_EXCEEDED; + savepriv = op->o_private; + op->o_private = (void *)i; + send_ldap_result( op, rs ); + op->o_private = savepriv; + goto finish; + } + continue; } else if ( rc == -1 ) { -- 2.39.5