Commit 05790d17 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

let children survive sigint, sigterm, etc.

this was biting us because ^c would get delivered to all of them,
maybe because they were all still listening to stdin?


svn:r2197
parent 76b284d2
......@@ -449,7 +449,7 @@ int circuit_extend(cell_t *cell, circuit_t *circ) {
} else if (rh.length == 4+2+ONIONSKIN_CHALLENGE_LEN+DIGEST_LEN) {
old_format = 0;
} else {
log_fn(LOG_WARN, "Wrong length on extend cell. Closing circuit.");
log_fn(LOG_WARN, "Wrong length %d on extend cell. Closing circuit.", rh.length);
return -1;
}
......
......@@ -207,6 +207,7 @@ static int cpuworker_main(void *data) {
#ifndef MS_WINDOWS
connection_free_all(); /* so the child doesn't hold the parent's fd's open */
#endif
handle_signals(0); /* ignore interrupts from the keyboard, etc */
dup_onion_keys(&onion_key, &last_onion_key);
......
......@@ -641,6 +641,7 @@ static int dnsworker_main(void *data) {
#ifndef MS_WINDOWS
connection_free_all(); /* so the child doesn't hold the parent's fd's open */
#endif
handle_signals(0); /* ignore interrupts from the keyboard, etc */
for(;;) {
......
......@@ -1002,6 +1002,26 @@ void exit_function(void)
#endif
}
/** Set up the signal handlers for either parent or child. */
void handle_signals(int is_parent)
{
#ifndef MS_WINDOWS /* do signal stuff only on unix */
struct sigaction action;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
action.sa_handler = is_parent ? catch : SIG_IGN;
sigaction(SIGINT, &action, NULL); /* do a controlled slow shutdown */
sigaction(SIGTERM, &action, NULL); /* to terminate now */
sigaction(SIGPIPE, &action, NULL); /* otherwise sigpipe kills us */
sigaction(SIGUSR1, &action, NULL); /* dump stats */
sigaction(SIGHUP, &action, NULL); /* to reload config, retry conns, etc */
if(is_parent)
sigaction(SIGCHLD, &action, NULL); /* handle dns/cpu workers that exit */
#endif /* signal stuff */
}
/** Main entry point for the Tor command-line client.
*/
static int tor_init(int argc, char *argv[]) {
......@@ -1031,21 +1051,7 @@ static int tor_init(int argc, char *argv[]) {
client_dns_init(); /* init the client dns cache */
}
#ifndef MS_WINDOWS /* do signal stuff only on unix */
{
struct sigaction action;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
action.sa_handler = catch;
sigaction(SIGINT, &action, NULL); /* do a controlled slow shutdown */
sigaction(SIGTERM, &action, NULL); /* to terminate now */
sigaction(SIGPIPE, &action, NULL); /* otherwise sigpipe kills us */
sigaction(SIGUSR1, &action, NULL); /* dump stats */
sigaction(SIGHUP, &action, NULL); /* to reload config, retry conns, etc */
sigaction(SIGCHLD, &action, NULL); /* handle dns/cpu workers that exit */
}
#endif /* signal stuff */
handle_signals(1);
crypto_global_init();
crypto_seed_rng();
......
......@@ -1204,6 +1204,7 @@ int server_mode(void);
int advertised_server_mode(void);
int proxy_mode(void);
void handle_signals(int is_parent);
void tor_cleanup(void);
/********************************* onion.c ***************************/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment