From 05790d17225f5ba71d378f49c52cba7ed20d43ee Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Sun, 8 Aug 2004 07:25:45 +0000 Subject: [PATCH] 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 --- src/or/circuitbuild.c | 2 +- src/or/cpuworker.c | 1 + src/or/dns.c | 1 + src/or/main.c | 36 +++++++++++++++++++++--------------- src/or/or.h | 1 + 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 9eefc67689..e820c92877 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -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; } diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index 4e66a40f49..6abcab5d9a 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -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); diff --git a/src/or/dns.c b/src/or/dns.c index 2d976a78e5..6cbecc02b9 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -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(;;) { diff --git a/src/or/main.c b/src/or/main.c index 93f6c239eb..5dde1a7b93 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -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(); diff --git a/src/or/or.h b/src/or/or.h index f2bd9a17cf..6bfff49465 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -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 ***************************/