bg resolution works.

git-svn-id: file:///svn/unbound/trunk@890 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards
2008-01-23 15:15:37 +00:00
parent faa7ad14c6
commit e56a3a60ef
8 changed files with 235 additions and 95 deletions
+38 -19
View File
@@ -65,6 +65,8 @@ void usage(char* argv[])
{
printf("usage: %s name ...\n", argv[0]);
printf("names are looked up at the same time, asynchronously.\n");
printf("-d : enable debug output\n");
printf("-t : use a resolver thread instead of forking a process\n");
exit(1);
}
@@ -89,9 +91,28 @@ int main(int argc, char** argv)
if(argc == 1) {
usage(argv);
}
if(argc > 1 && strcmp(argv[1], "-h") == 0)
usage(argv);
argc--;
argv++;
/* create context */
ctx = ub_val_ctx_create();
if(!ctx) {
printf("could not create context, %s", strerror(errno));
return 1;
}
if(argc > 0 && strcmp(argv[0], "-d") == 0) {
ub_val_ctx_debuglevel(ctx, 3);
argc--;
argv++;
}
if(argc > 0 && strcmp(argv[0], "-t") == 0) {
ub_val_ctx_async(ctx, 1);
argc--;
argv++;
}
/* allocate array for results. */
lookups = (struct lookinfo*)calloc((size_t)argc,
sizeof(struct lookinfo));
@@ -99,20 +120,10 @@ int main(int argc, char** argv)
printf("out of memory\n");
return 1;
}
/* create context */
ctx = ub_val_ctx_create();
if(!ctx) {
printf("could not create context, %s", strerror(errno));
return 1;
}
/* perform asyncronous calls */
num_wait = argc;
for(i=0; i<argc; i++) {
if(strcmp(argv[i], "-d") == 0) {
ub_val_ctx_debuglevel(ctx, 3);
continue;
}
fprintf(stderr, "start lookup %s\n", argv[i]);
lookups[i].qname = argv[i];
r = ub_val_resolve_async(ctx, argv[i], LDNS_RR_TYPE_A,
@@ -142,22 +153,30 @@ int main(int argc, char** argv)
/* print lookup results */
for(i=0; i<argc; i++) {
char buf[100];
if(lookups[i].err)
if(lookups[i].err) /* error (from libunbound) */
printf("%s: error %s\n", lookups[i].qname,
ub_val_strerror(lookups[i].err));
else if(lookups[i].result->rcode != 0)
printf("%s: DNS error %d\n", lookups[i].qname,
lookups[i].result->rcode);
else if(!lookups[i].result->havedata)
printf("%s: no data %s\n", lookups[i].qname,
else if(lookups[i].result->havedata)
printf("%s: %s\n", lookups[i].qname,
inet_ntop(AF_INET, lookups[i].result->data[0],
buf, (socklen_t)sizeof(buf)));
else {
/* there is no data, why that? */
if(lookups[i].result->rcode == 0 /*noerror*/ ||
lookups[i].result->nxdomain)
printf("%s: no data %s\n", lookups[i].qname,
lookups[i].result->nxdomain?"(no such host)":
"(no IP4 address)");
else printf("%s: %s\n", lookups[i].qname,
inet_ntop(AF_INET, lookups[i].result->data[0],
buf, (socklen_t)sizeof(buf)));
else /* some error (from the server) */
printf("%s: DNS error %d\n", lookups[i].qname,
lookups[i].result->rcode);
}
}
ub_val_ctx_delete(ctx);
for(i=0; i<argc; i++) {
ub_val_result_free(lookups[i].result);
}
free(lookups);
return 0;
}
+3 -1
View File
@@ -658,7 +658,9 @@ static void* checklock_main(void* arg)
/* Hack to get same numbers as in log file */
thr->num = *(int*)(thr->arg);
log_assert(thr->num < THRDEBUG_MAX_THREADS);
log_assert(thread_infos[thr->num] == NULL);
/* as an aside, due to this, won't work for libunbound bg thread */
if(thread_infos[thr->num] != NULL)
log_warn("thread warning, thr->num %d not NULL", thr->num);
thread_infos[thr->num] = thr;
LOCKRET(pthread_setspecific(thr_debug_key, thr));
if(check_locking_order)