]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
smaller fixes.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 25 Jan 2008 16:17:36 +0000 (16:17 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 25 Jan 2008 16:17:36 +0000 (16:17 +0000)
git-svn-id: file:///svn/unbound/trunk@904 be551aaa-1e26-0410-a405-d3ace91eadb9

libunbound/unbound.c
libunbound/worker.c
testcode/asynclook.c

index 6a650592d3ee7231fc84afb03f6a27b7d959a811..81c8e46a21df04ed147e24c7c305bd73eb40de5e 100644 (file)
@@ -162,8 +162,21 @@ ub_val_ctx_delete(struct ub_val_ctx* ctx)
                        free(msg);
                }
                lock_basic_unlock(&ctx->rrpipe_lock);
+
+               /* if bg worker is a thread, wait for it to exit, so that all
+                * resources are really gone. */
+               lock_basic_lock(&ctx->cfglock);
+               if(ctx->dothread) {
+                       lock_basic_unlock(&ctx->cfglock);
+                       ub_thread_join(ctx->bg_tid);
+               } else {
+                       lock_basic_unlock(&ctx->cfglock);
+               }
+       }
+       else {
+               lock_basic_unlock(&ctx->cfglock);
        }
-       else lock_basic_unlock(&ctx->cfglock);
+
 
        modstack_desetup(&ctx->mods, ctx->env);
        a = ctx->alloc_list;
@@ -561,7 +574,9 @@ ub_val_resolve_async(struct ub_val_ctx* ctx, char* name, int rrtype,
                        lock_basic_unlock(&ctx->cfglock);
                        return r;
                }
-       } else lock_basic_unlock(&ctx->cfglock);
+       } else {
+               lock_basic_unlock(&ctx->cfglock);
+       }
 
        /* create new ctx_query and attempt to add to the list */
        q = context_new(ctx, name, rrtype, rrclass, callback, mydata);
@@ -583,7 +598,11 @@ ub_val_resolve_async(struct ub_val_ctx* ctx, char* name, int rrtype,
        lock_basic_unlock(&ctx->cfglock);
        
        lock_basic_lock(&ctx->qqpipe_lock);
-       libworker_write_msg(ctx->qqpipe[1], msg, len, 0);
+       if(!libworker_write_msg(ctx->qqpipe[1], msg, len, 0)) {
+               lock_basic_unlock(&ctx->qqpipe_lock);
+               free(msg);
+               return UB_PIPE;
+       }
        lock_basic_unlock(&ctx->qqpipe_lock);
        free(msg);
        return UB_NOERROR;
@@ -620,7 +639,11 @@ ub_val_cancel(struct ub_val_ctx* ctx, int async_id)
 
        /* send cancel to background worker */
        lock_basic_lock(&ctx->qqpipe_lock);
-       libworker_write_msg(ctx->qqpipe[1], msg, len, 0);
+       if(!libworker_write_msg(ctx->qqpipe[1], msg, len, 0)) {
+               lock_basic_unlock(&ctx->qqpipe_lock);
+               free(msg);
+               return UB_PIPE;
+       }
        lock_basic_unlock(&ctx->qqpipe_lock);
        free(msg);
        return UB_NOERROR;
index feb1985b758b09d87c3ce54de2302ca871df5b19..78bb1c496ef1fe16561ccca577ef34ed67e3e215 100644 (file)
@@ -280,6 +280,7 @@ libworker_dobg(void* arg)
                ctx->rrpipe[0] = -1;
        }
 #endif
+       log_info("dobg start");
        if(!w) {
                log_err("libunbound bg worker init failed, nomem");
                return NULL;
index ad8de9546d94f49ace1a32f6ad83aabdcaf32335..37ad2cb7c4ab213a774c1c338bc32fe1d8ea4e23 100644 (file)
@@ -246,7 +246,6 @@ ext_test(struct ub_val_ctx* ctx, int argc, char** argv)
        }
        printf("extended test end\n");
        ub_val_ctx_delete(ctx);
-       sleep(1); /* give bg thread time to exit */
        checklock_stop();
        return 0;
 }