summaryrefslogtreecommitdiff
path: root/src/or/main.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-08-08 07:25:45 +0000
committerRoger Dingledine <arma@torproject.org>2004-08-08 07:25:45 +0000
commit05790d17225f5ba71d378f49c52cba7ed20d43ee (patch)
tree646b23c1ca045de9a3cc14cf34c2a9a2fceea05b /src/or/main.c
parent76b284d2af2397c98b76e82369f977539eaf37bd (diff)
downloadtor-05790d17225f5ba71d378f49c52cba7ed20d43ee.tar.gz
tor-05790d17225f5ba71d378f49c52cba7ed20d43ee.zip
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
Diffstat (limited to 'src/or/main.c')
-rw-r--r--src/or/main.c36
1 files changed, 21 insertions, 15 deletions
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();