Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Goulet
Tor
Commits
5d9cfb71
Commit
5d9cfb71
authored
Aug 12, 2003
by
Roger Dingledine
Browse files
use the spawn_func / spawn_exit abstraction for dnsworkers
svn:r388
parent
e4a6ea5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/or/dns.c
View file @
5d9cfb71
...
...
@@ -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
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment