]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fixup checklock code for log lock and its mutual initialization
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 25 Aug 2014 12:00:30 +0000 (12:00 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 25 Aug 2014 12:00:30 +0000 (12:00 +0000)
  dependency.

git-svn-id: file:///svn/unbound/trunk@3214 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
testcode/checklocks.c
testcode/lock_verify.c

index aabd7b67727d014ddb6ffa89d72d3d52d73d9903..a22d9e5ebb08e4471be073af26302d818dbc463e 100644 (file)
@@ -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).
 
index ba020e70a79d607cdea16d122165067ef86eb462..5815e4fd08878d1a3efc97a56b0fa6326ec3ad6f 100644 (file)
@@ -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]);
index 365fd6e4af0ce0a208c72e73660be5953ba2f9ed..a46d5d99ea9354d6f59e49d1aea8ff449a2b6d3d 100644 (file)
@@ -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;