From: Wouter Wijngaards Date: Tue, 22 May 2007 15:02:39 +0000 (+0000) Subject: Fixes. X-Git-Tag: release-0.4~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc48ec587f1448ed2deacafabd6df6e9d08bc0b0;p=thirdparty%2Funbound.git Fixes. git-svn-id: file:///svn/unbound/trunk@330 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index d9c37c8b3..53b8af6a5 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -4,6 +4,9 @@ - testbound support for new serviced queries. - test for retry to TCP cannot use testbound any longer. - testns test for EDNS fallback, test for TCP fallback already exists. + - fixes for no-locking compile. + - mini_event timer precision and fix for change in timeouts during + timeout callback. Fix for fwd_three tests, performed nonexit query. 21 May 2007: Wouter - small comment on hash table locking. diff --git a/services/cache/infra.c b/services/cache/infra.c index fbc0d0502..5e9c861bc 100644 --- a/services/cache/infra.c +++ b/services/cache/infra.c @@ -75,7 +75,7 @@ infra_host_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il) struct infra_host_key* key = (struct infra_host_key*)k; if(!key) return; - if(il) lock_rw_unlock(&key->entry.lock); + if(il) { lock_rw_unlock(&key->entry.lock); } lock_rw_destroy(&key->entry.lock); free(key); } @@ -322,7 +322,7 @@ infra_lame_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il) struct infra_lame_key* key = (struct infra_lame_key*)k; if(!key) return; - if(il) lock_rw_unlock(&key->entry.lock); + if(il) { lock_rw_unlock(&key->entry.lock); } lock_rw_destroy(&key->entry.lock); free(key->zonename); free(key); @@ -397,7 +397,7 @@ infra_set_lame(struct infra_cache* infra, log_err("set_lame: malloc failure"); if(needtoinsert) slabhash_insert(infra->hosts, e->hash, e, e->data, NULL); - else lock_rw_unlock(&e->lock); + else { lock_rw_unlock(&e->lock); } free(k->zonename); free(k); free(d); @@ -409,7 +409,7 @@ infra_set_lame(struct infra_cache* infra, if(needtoinsert) slabhash_insert(infra->hosts, e->hash, e, e->data, NULL); - else lock_rw_unlock(&e->lock); + else { lock_rw_unlock(&e->lock); } return 1; } @@ -436,7 +436,7 @@ infra_rtt_update(struct infra_cache* infra, if(needtoinsert) slabhash_insert(infra->hosts, e->hash, e, e->data, NULL); - else lock_rw_unlock(&e->lock); + else { lock_rw_unlock(&e->lock); } return 1; } @@ -461,6 +461,6 @@ infra_edns_update(struct infra_cache* infra, if(needtoinsert) slabhash_insert(infra->hosts, e->hash, e, e->data, NULL); - else lock_rw_unlock(&e->lock); + else { lock_rw_unlock(&e->lock); } return 1; } diff --git a/testcode/unitlruhash.c b/testcode/unitlruhash.c index d03f5a9ce..489df9424 100644 --- a/testcode/unitlruhash.c +++ b/testcode/unitlruhash.c @@ -526,7 +526,7 @@ static int test_compfunc(void* key1, void* key2) static void test_delkey(void* key, void* ATTR_UNUSED(arg), int l) { - if(l) lock_rw_unlock(&((struct testkey*)key)->entry.lock); + if(l) { lock_rw_unlock(&((struct testkey*)key)->entry.lock); } delkey((struct testkey*)key); } diff --git a/testcode/unitslabhash.c b/testcode/unitslabhash.c index c525e1df7..32d17838a 100644 --- a/testcode/unitslabhash.c +++ b/testcode/unitslabhash.c @@ -406,7 +406,7 @@ static int test_compfunc(void* key1, void* key2) static void test_delkey(void* key, void* ATTR_UNUSED(arg), int l) { - if(l) lock_rw_unlock(&((struct slabtestkey*)key)->entry.lock); + if(l) { lock_rw_unlock(&((struct slabtestkey*)key)->entry.lock); } delkey((struct slabtestkey*)key); } diff --git a/testdata/fwd_three.tpkg b/testdata/fwd_three.tpkg index 86a1aab3d..ce0a7414b 100644 Binary files a/testdata/fwd_three.tpkg and b/testdata/fwd_three.tpkg differ diff --git a/testdata/fwd_three_service.tpkg b/testdata/fwd_three_service.tpkg index 9decdba89..b0e74bc83 100644 Binary files a/testdata/fwd_three_service.tpkg and b/testdata/fwd_three_service.tpkg differ diff --git a/util/data/msgreply.c b/util/data/msgreply.c index 6fd26841b..d4f3a82d0 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -499,8 +499,9 @@ void query_entry_delete(void *k, void* ATTR_UNUSED(arg), int is_locked) { struct msgreply_entry* q = (struct msgreply_entry*)k; - if(is_locked) + if(is_locked) { lock_rw_unlock(&q->entry.lock); + } lock_rw_destroy(&q->entry.lock); query_info_clear(&q->key); free(q); diff --git a/util/data/packed_rrset.c b/util/data/packed_rrset.c index 1393c58c2..23aa080a2 100644 --- a/util/data/packed_rrset.c +++ b/util/data/packed_rrset.c @@ -106,8 +106,9 @@ ub_rrset_key_delete(void* key, void* userdata, int is_locked) struct ub_packed_rrset_key* k = (struct ub_packed_rrset_key*)key; struct alloc_cache* a = (struct alloc_cache*)userdata; k->id = 0; - if(is_locked) + if(is_locked) { lock_rw_unlock(&k->entry.lock); + } free(k->rk.dname); k->rk.dname = NULL; alloc_special_release(a, k); diff --git a/util/mini_event.c b/util/mini_event.c index aec29d089..6eb5b500c 100644 --- a/util/mini_event.c +++ b/util/mini_event.c @@ -115,46 +115,56 @@ const char *event_get_method(void) } /** call timeouts handlers, and return how long to wait for next one or -1 */ -static void handle_timeouts(struct event_base* base, time_t now, time_t *wait) +static void handle_timeouts(struct event_base* base, struct timeval* now, + struct timeval* wait) { - struct event* p, *np; - *wait = (time_t)-1; + struct event* p; +#ifndef S_SPLINT_S + wait->tv_sec = (time_t)-1; +#endif - p = (struct event*)rbtree_first(base->times); - while((rbnode_t*)p!=RBTREE_NULL) { - /* store next to make deletion possible */ - np = (struct event*)rbtree_next((rbnode_t*)p); - if(!p || p->ev_timeout.tv_sec > now || - (p->ev_timeout.tv_sec==now && p->ev_timeout.tv_usec>0)) { + while((rbnode_t*)(p = (struct event*)rbtree_first(base->times)) + !=RBTREE_NULL) { +#ifndef S_SPLINT_S + if(p->ev_timeout.tv_sec > now->tv_sec || + (p->ev_timeout.tv_sec==now->tv_sec && + p->ev_timeout.tv_usec > now->tv_usec)) { /* there is a next larger timeout. wait for it */ - *wait = p->ev_timeout.tv_sec - now; - if(p->ev_timeout.tv_usec > 0) - *wait+=1; /* wait a bit longer */ + wait->tv_sec = p->ev_timeout.tv_sec - now->tv_sec; + if(now->tv_usec > p->ev_timeout.tv_usec) { + wait->tv_sec--; + wait->tv_usec = 1000000 - (now->tv_usec - + p->ev_timeout.tv_usec); + } else { + wait->tv_usec = p->ev_timeout.tv_usec + - now->tv_usec; + } return; } +#endif /* event times out, remove it */ (void)rbtree_delete(base->times, p); p->ev_events &= ~EV_TIMEOUT; (*p->ev_callback)(p->ev_fd, EV_TIMEOUT, p->ev_arg); - /* next is a valid pointer and next larger element */ - p = np; } } /** call select and callbacks for that */ -static int handle_select(struct event_base* base, time_t wait) +static int handle_select(struct event_base* base, struct timeval* wait) { - struct timeval tv; fd_set r, w; int ret, i; - tv.tv_sec = wait; - tv.tv_usec = 0; +#ifndef S_SPLINT_S + if(wait->tv_sec==(time_t)-1) + wait = NULL; +#endif + if(wait) log_info("waiting for %d %d", wait->tv_sec, wait->tv_usec); + else log_info("wait forever"); memmove(&r, &base->reads, sizeof(fd_set)); memmove(&w, &base->writes, sizeof(fd_set)); - if((ret = select(base->maxfd+1, &r, &w, NULL, - (wait==(time_t)-1)?NULL:&tv)) == -1) { + if((ret = select(base->maxfd+1, &r, &w, NULL, wait)) == -1) { return -1; } @@ -185,13 +195,15 @@ static int handle_select(struct event_base* base, time_t wait) /** run select in a loop */ int event_base_dispatch(struct event_base* base) { + struct timeval now, wait; while(!base->need_to_exit) { - time_t now = time(NULL), wait; + if(gettimeofday(&now, NULL) < 0) + return -1; /* see if timeouts need handling */ - handle_timeouts(base, now, &wait); + handle_timeouts(base, &now, &wait); /* do select */ - if(handle_select(base, wait) < 0) { + if(handle_select(base, &wait) < 0) { if(base->need_to_exit) return 0; return -1; @@ -258,8 +270,15 @@ int event_add(struct event* ev, struct timeval* tv) } if(tv && ev->ev_events&EV_TIMEOUT) { #ifndef S_SPLINT_S - ev->ev_timeout.tv_sec = tv->tv_sec + time(NULL); - ev->ev_timeout.tv_usec = tv->tv_usec; + struct timeval now; + if(gettimeofday(&now, NULL) < 0) + return -1; + ev->ev_timeout.tv_sec = tv->tv_sec + now.tv_sec; + ev->ev_timeout.tv_usec = tv->tv_usec + now.tv_usec; + while(ev->ev_timeout.tv_usec > 1000000) { + ev->ev_timeout.tv_usec -= 1000000; + ev->ev_timeout.tv_sec++; + } #endif (void)rbtree_insert(ev->ev_base->times, &ev->node); }