]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
let children survive sigint, sigterm, etc.
authorRoger Dingledine <arma@torproject.org>
Sun, 8 Aug 2004 07:25:45 +0000 (07:25 +0000)
committerRoger Dingledine <arma@torproject.org>
Sun, 8 Aug 2004 07:25:45 +0000 (07:25 +0000)
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
src/or/cpuworker.c
src/or/dns.c
src/or/main.c
src/or/or.h

index 9eefc6768990823a277d547d45f56f43d443820b..e820c928771cf688196d98c00a0305cda40528f6 100644 (file)
@@ -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;
   }
 
index 4e66a40f49b50fab9f86f43ca16e902755960a44..6abcab5d9ac37fa107928b7ee222eac8e11f8754 100644 (file)
@@ -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);
 
index 2d976a78e52966ce570ed88efb5d7c1a6e6b3dec..6cbecc02b98fb166d38af054e278dc979dc14424 100644 (file)
@@ -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(;;) {
 
index 93f6c239eb9c8fce446a73eacdff30b2f80b2c3e..5dde1a7b934f2ae519d42cea1ecffa52bc296f3d 100644 (file)
@@ -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();
index f2bd9a17cf6bafdd1fa61645bff135e3bb2ecd2d..6bfff4946511ba6290985ad8796c4d3cc8a12d86 100644 (file)
@@ -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 ***************************/