]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- More fixes for bug#519: for the threaded case test if the bg
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 26 Aug 2013 12:24:27 +0000 (12:24 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 26 Aug 2013 12:24:27 +0000 (12:24 +0000)
  thread has been killed, on ub_ctx_delete, to avoid hangs.

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

doc/Changelog
libunbound/libunbound.c

index 4d75e0377f252bda7f09142b9f07ef91bd2843d6..286095dacf69088259fc74cdfca35cd2a4fd10f0 100644 (file)
@@ -1,3 +1,7 @@
+26 Aug 2013: Wouter
+       - More fixes for bug#519: for the threaded case test if the bg
+         thread has been killed, on ub_ctx_delete, to avoid hangs.
+
 22 Aug 2013: Wouter
        - more fixes that I overlooked.
        - review fixes from Willem.
index ae865a71eaeff0f528487128fab41a76c6012e01..999478ef38a298e071025f93559e357f8cec5ab8 100644 (file)
@@ -60,6 +60,9 @@
 #include "services/localzone.h"
 #include "services/cache/infra.h"
 #include "services/cache/rrset.h"
+#ifdef HAVE_PTHREAD
+#include <signal.h>
+#endif
 
 #if defined(UB_ON_WINDOWS) && defined (HAVE_WINDOWS_H)
 #include <windows.h>
@@ -155,11 +158,9 @@ delq(rbnode_t* n, void* ATTR_UNUSED(arg))
        context_query_delete(q);
 }
 
-void 
-ub_ctx_delete(struct ub_ctx* ctx)
+/** stop the bg thread */
+static void ub_stop_bg(struct ub_ctx* ctx)
 {
-       struct alloc_cache* a, *na;
-       if(!ctx) return;
        /* stop the bg thread */
        lock_basic_lock(&ctx->cfglock);
        if(ctx->created_bg) {
@@ -195,7 +196,28 @@ ub_ctx_delete(struct ub_ctx* ctx)
        else {
                lock_basic_unlock(&ctx->cfglock);
        }
+}
+
+void 
+ub_ctx_delete(struct ub_ctx* ctx)
+{
+       struct alloc_cache* a, *na;
+       int do_stop = 1;
+       if(!ctx) return;
 
+       /* see if bg thread is created and if threads have been killed */
+       /* no locks, because those may be held by terminated threads */
+       /* for processes the read pipe is closed and we see that on read */
+#ifdef HAVE_PTHREAD
+       if(ctx->created_bg && ctx->dothread) {
+               if(pthread_kill(ctx->bg_tid, 0) == ESRCH) {
+                       /* thread has been killed */
+                       do_stop = 0;
+               }
+       }
+#endif /* HAVE_PTHREAD */
+       if(do_stop)
+               ub_stop_bg(ctx);
 
        modstack_desetup(&ctx->mods, ctx->env);
        a = ctx->alloc_list;