Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Legacy
gitolite
user
andrea
Tor
Commits
5d9cfb71
Commit
5d9cfb71
authored
21 years ago
by
Roger Dingledine
Browse files
Options
Downloads
Patches
Plain Diff
use the spawn_func / spawn_exit abstraction for dnsworkers
svn:r388
parent
e4a6ea5c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/or/dns.c
+14
-20
14 additions, 20 deletions
src/or/dns.c
with
14 additions
and
20 deletions
src/or/dns.c
+
14
−
20
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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment