From 912b10a78965aae2a9ec1c49c2d16a89d81ff507 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Mon, 25 Aug 2014 12:00:30 +0000 Subject: [PATCH] - Fixup checklock code for log lock and its mutual initialization dependency. git-svn-id: file:///svn/unbound/trunk@3214 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 4 ++++ testcode/checklocks.c | 14 ++++++++++++++ testcode/lock_verify.c | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/doc/Changelog b/doc/Changelog index aabd7b677..a22d9e5eb 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +25 August 2014: Wouter + - Fixup checklock code for log lock and its mutual initialization + dependency. + 19 August 2014: Wouter - Update unbound manpage with more explanation (from Florian Obser). diff --git a/testcode/checklocks.c b/testcode/checklocks.c index ba020e70a..5815e4fd0 100644 --- a/testcode/checklocks.c +++ b/testcode/checklocks.c @@ -58,6 +58,8 @@ /** if key has been created */ static int key_created = 0; +/** if the key was deleted, i.e. we have quit */ +static int key_deleted = 0; /** we hide the thread debug info with this key. */ static ub_thread_key_t thr_debug_key; /** the list of threads, so all threads can be examined. NULL if unused. */ @@ -273,6 +275,15 @@ checklock_init(enum check_lock_type type, struct checked_lock** lock, thr_debug_key); if(!e) fatal_exit("%s %s %d: out of memory", func, file, line); + if(!thr) { + /* this is called when log_init() calls lock_init() + * functions, and the test check code has not yet + * been initialised. But luckily, the checklock_start() + * routine can be called multiple times without ill effect. + */ + checklock_start(); + thr = (struct thr_check*)pthread_getspecific(thr_debug_key); + } if(!thr) fatal_exit("%s %s %d: lock_init no thread info", func, file, line); @@ -676,6 +687,8 @@ static void* checklock_main(void* arg) /** init the main thread */ void checklock_start(void) { + if(key_deleted) + return; if(!key_created) { struct thr_check* thisthr = (struct thr_check*)calloc(1, sizeof(struct thr_check)); @@ -696,6 +709,7 @@ void checklock_stop(void) { if(key_created) { int i; + key_deleted = 1; if(check_locking_order) fclose(thread_infos[0]->order_info); free(thread_infos[0]); diff --git a/testcode/lock_verify.c b/testcode/lock_verify.c index 365fd6e4a..a46d5d99e 100644 --- a/testcode/lock_verify.c +++ b/testcode/lock_verify.c @@ -391,6 +391,11 @@ main(int argc, char* argv[]) rbtree_t* all_locks; int i; time_t starttime = time(NULL); +#ifdef USE_THREAD_DEBUG + /* do not overwrite the ublocktrace files with the ones generated + * by this program (i.e. when the log code creates a lock) */ + check_locking_order = 0; +#endif if(argc <= 1) { usage(); return 1; -- 2.47.2