diff options
author | Roger Dingledine <arma@torproject.org> | 2003-08-12 07:35:17 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-08-12 07:35:17 +0000 |
commit | 5d9cfb71649f15db09290a7c390a0f9d95b52548 (patch) | |
tree | b7b1261d75f246c5d531093443107c13a91728e9 /src/or/dns.c | |
parent | e4a6ea5c464afbd03ef32c3d060185bf8c770d1e (diff) | |
download | tor-5d9cfb71649f15db09290a7c390a0f9d95b52548.tar tor-5d9cfb71649f15db09290a7c390a0f9d95b52548.tar.gz |
use the spawn_func / spawn_exit abstraction for dnsworkers
svn:r388
Diffstat (limited to 'src/or/dns.c')
-rw-r--r-- | src/or/dns.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/or/dns.c b/src/or/dns.c index 64a6bfb8a..8e735aa1a 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -21,7 +21,7 @@ int num_workers_busy=0; static int dns_assign_to_worker(connection_t *exitconn); static void dns_found_answer(char *question, uint32_t answer); -static void dnsworker_main(int fd); +int dnsworker_main(void *data); static int dns_spawn_worker(void); static void spawn_enough_workers(void); @@ -313,22 +313,27 @@ int connection_dns_process_inbuf(connection_t *conn) { return 0; } -static void dnsworker_main(int fd) { +int dnsworker_main(void *data) { char question[MAX_ADDRESSLEN]; unsigned char question_len; struct hostent *rent; + int fd; + int *fdarray = data; + + close(fdarray[0]); /* this is the side of the socketpair the parent uses */ + fd = fdarray[1]; /* this side is ours */ for(;;) { if(read(fd, &question_len, 1) != 1) { log(LOG_INFO,"dnsworker_main(): read length failed. Exiting."); - exit(0); + spawn_exit(); } assert(question_len > 0); if(read(fd, question, question_len) != question_len) { log(LOG_INFO,"dnsworker_main(): read hostname failed. Exiting."); - exit(0); + spawn_exit(); } question[question_len] = 0; /* null terminate it */ @@ -338,21 +343,21 @@ static void dnsworker_main(int fd) { /* XXX it's conceivable write could return 1 through 3. but that's never gonna happen, right? */ if(write(fd, "\0\0\0\0", 4) != 4) { log(LOG_INFO,"dnsworker_main(): writing nulls failed. Exiting."); - exit(0); + spawn_exit(); } } else { assert(rent->h_length == 4); /* break to remind us if we move away from ipv4 */ if(write(fd, rent->h_addr, 4) != 4) { log(LOG_INFO,"dnsworker_main(): writing answer failed. Exiting."); - exit(0); + spawn_exit(); } log(LOG_INFO,"dnsworker_main(): Answered question '%s'.",question); } } + return 0; /* windows wants this function to return an int */ } static int dns_spawn_worker(void) { - pid_t pid; int fd[2]; connection_t *conn; @@ -361,20 +366,9 @@ static int dns_spawn_worker(void) { exit(1); } - pid = fork(); - if(pid < 0) { - perror("fork"); - exit(1); - } - if(pid == 0) { /* i'm the child */ - close(fd[0]); - dnsworker_main(fd[1]); - assert(0); /* never gets here */ - } - - /* i'm the parent */ + spawn_func(dnsworker_main, (void*)fd); log(LOG_DEBUG,"dns_spawn_worker(): just spawned a worker."); - close(fd[1]); + close(fd[1]); /* we don't need the worker's side of the pipe */ conn = connection_new(CONN_TYPE_DNSWORKER); if(!conn) { |