From eb2a930e0ff09c830479df1aea5d8a4ce9354dc1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 12 Oct 2014 21:35:25 +0100 Subject: [PATCH] Reentrancy: Introduce adns__returning Replace all the adns__consistency calls on the return paths from adns with adns__returning (except in setup.c, whose functions never set up any queries). I have separately gone through the public entrypoints in adns.h and checked that they have the expected adns__consistency calls. So with this patch, the new imprecation about adns__returning is satisfied. Signed-off-by: Ian Jackson --- src/event.c | 22 +++++++++++----------- src/internal.h | 4 ++++ src/poll.c | 6 +++--- src/query.c | 12 ++++++++---- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/event.c b/src/event.c index 52a2efc..5b2b42d 100644 --- a/src/event.c +++ b/src/event.c @@ -286,7 +286,7 @@ void adns_firsttimeout(adns_state ads, struct timeval now) { adns__consistency(ads,0,cc_entex); adns__timeouts(ads, 0, tv_io,tvbuf, now); - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); } void adns_processtimeouts(adns_state ads, const struct timeval *now) { @@ -295,7 +295,7 @@ void adns_processtimeouts(adns_state ads, const struct timeval *now) { adns__consistency(ads,0,cc_entex); adns__must_gettimeofday(ads,&now,&tv_buf); if (now) adns__timeouts(ads, 1, 0,0, *now); - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); } /* fd handling functions. These are the top-level of the real work of @@ -426,7 +426,7 @@ int adns_processreadable(adns_state ads, int fd, const struct timeval *now) { } r= 0; xit: - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return r; } @@ -483,7 +483,7 @@ int adns_processwriteable(adns_state ads, int fd, const struct timeval *now) { } r= 0; xit: - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return r; } @@ -502,7 +502,7 @@ int adns_processexceptional(adns_state ads, int fd, default: abort(); } - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return 0; } @@ -579,7 +579,7 @@ void adns_beforeselect(adns_state ads, int *maxfd_io, fd_set *readfds_io, *maxfd_io= maxfd; xit: - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); } void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds, @@ -601,7 +601,7 @@ void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds, maxfd,readfds,writefds,exceptfds, *now, 0); xit: - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); } /* General helpful functions. */ @@ -623,7 +623,7 @@ void adns_globalsystemfailure(adns_state ads) { default: abort(); } - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); } int adns_processany(adns_state ads) { @@ -648,7 +648,7 @@ int adns_processany(adns_state ads) { 0,0,0,0, now,&r); - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return 0; } @@ -712,7 +712,7 @@ int adns_wait(adns_state ads, adns_afterselect(ads,maxfd,&readfds,&writefds,&exceptfds,0); } } - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return r; } @@ -728,6 +728,6 @@ int adns_check(adns_state ads, if (!r) adns__autosys(ads,now); r= adns__internal_check(ads,query_io,answer_r,context_r); - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return r; } diff --git a/src/internal.h b/src/internal.h index 0374acc..13740b2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -708,6 +708,10 @@ void adns__query_done(adns_query qu); void adns__query_fail(adns_query qu, adns_status stat); void adns__cancel_children(adns_query qu); +void adns__returning(adns_state ads, adns_query qu); +/* Must be called before returning from adns any time that we have + * progressed (including made, finished or destroyed) queries. */ + /* From reply.c: */ void adns__procdgram(adns_state ads, const byte *dgram, int len, diff --git a/src/poll.c b/src/poll.c index 25075ed..60ff6ec 100644 --- a/src/poll.c +++ b/src/poll.c @@ -77,7 +77,7 @@ int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io, } r= 0; xit: - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return r; } @@ -91,7 +91,7 @@ void adns_afterpoll(adns_state ads, const struct pollfd *fds, int nfds, adns__timeouts(ads, 1, 0,0, *now); adns__fdevents(ads, fds,nfds, 0,0,0,0, *now,0); } - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); } int adns_wait_poll(adns_state ads, @@ -123,7 +123,7 @@ int adns_wait_poll(adns_state ads, } xit: - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return r; } diff --git a/src/query.c b/src/query.c index 6a1ec75..3e93fc2 100644 --- a/src/query.c +++ b/src/query.c @@ -312,18 +312,18 @@ int adns_submit(adns_state ads, query_simple(ads,qu, owner,ol, typei,flags, now); } adns__autosys(ads,now); - adns__consistency(ads,qu,cc_entex); + adns__returning(ads,qu); return 0; x_adnsfail: adns__query_fail(qu,stat); - adns__consistency(ads,qu,cc_entex); + adns__returning(ads,qu); return 0; x_errno: r= errno; assert(r); - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); return r; } @@ -496,6 +496,10 @@ static void free_query_allocs(adns_query qu) { qu->query_dgram= 0; } +void adns__returning(adns_state ads, adns_query qu_for_caller) { + adns__consistency(ads,qu_for_caller,cc_entex); +} + void adns_cancel(adns_query qu) { adns_state ads; @@ -521,7 +525,7 @@ void adns_cancel(adns_query qu) { free_query_allocs(qu); free(qu->answer); free(qu); - adns__consistency(ads,0,cc_entex); + adns__returning(ads,0); } void adns__update_expires(adns_query qu, unsigned long ttl, -- 2.30.2