[tor-commits] [chutney/master] Make all chutney tors exit when tools/test-network.sh exits

teor at torproject.org teor at torproject.org
Mon May 8 05:38:45 UTC 2017


commit 5adda26c1b889df0ba2c5ccf5c1339f224ba2e3f
Author: teor <teor2345 at gmail.com>
Date:   Mon Apr 10 13:20:06 2017 +1000

    Make all chutney tors exit when tools/test-network.sh exits
    
    Fixes #20409, as long as chutney and tools/test-network.sh do not hang.
    (Hangs shouldn't happen, if they do, it's a separate bug.)
---
 README                   |  5 +++++
 lib/chutney/TorNet.py    | 21 ++++++++++++++++++++-
 tools/test-network.sh    |  9 +++++++++
 torrc_templates/common.i |  4 ++++
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/README b/README
index 0c98440..ac6e1bd 100644
--- a/README
+++ b/README
@@ -57,6 +57,7 @@ Warning Options:
   --only-warnings    CHUTNEY_WARNINGS_ONLY=true
 
 Expert Options:
+  --controlling-pid  CHUTNEY_CONTROLLING_PID
   --coverage         USE_COVERAGE_BINARY=true
   --net-dir          CHUTNEY_DATA_DIR
   --dry-run          NETWORK_DRY_RUN=true
@@ -125,6 +126,10 @@ Waiting for the network:
   after verifying, then exits (default: immediately). If CHUTNEY_STOP_TIME is
   negative, the script leaves the network running, and exits after verifying.
 
+  If none of these options are negative, test-network.sh tells the tor
+  processes to exit after it exits, using CHUTNEY_CONTROLLING_PID. To disable
+  this functionality, set CHUTNEY_CONTROLLING_PID to 1 or less.
+
 Changing the network address:
 
    Chutney defaults to binding to localhost. To change the IPv4 bind address,
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
index 5032c2b..9ccf4a5 100644
--- a/lib/chutney/TorNet.py
+++ b/lib/chutney/TorNet.py
@@ -752,6 +752,10 @@ DEFAULTS = {
     'bootstrap_time': int(os.environ.get('CHUTNEY_BOOTSTRAP_TIME',
                                          os.environ.get('BOOTSTRAP_TIME',
                                                         60))),
+    # the PID of the controlling script (for __OwningControllerProcess)
+    'controlling_pid': (int(os.environ.get('CHUTNEY_CONTROLLING_PID', 0))
+                        if 'CHUTNEY_CONTROLLING_PID' in os.environ
+                        else None),
 }
 
 
@@ -770,7 +774,7 @@ class TorEnviron(chutney.Templating.Environ):
           torrc_template_path: path to chutney torrc_templates directory
           hs_hostname: the hostname of the key generated by a hidden service
           owning_controller_process: the __OwningControllerProcess torrc line,
-             or an empty string if tor should continue after the script exits
+             disabled if tor should continue after the script exits
 
        Environment fields used:
           nodenum: chutney's internal node number for the node
@@ -848,6 +852,21 @@ class TorEnviron(chutney.Templating.Environ):
                       (my['nick'], e.errno, e.strerror, hs_hostname_file))
         return my['hs-hostname']
 
+    def _get_owning_controller_process(self, my):
+        cpid = my['controlling_pid']
+        if cpid is None:
+            cpid = 0
+        ocp_line = ('__OwningControllerProcess %d' % (cpid))
+        # if we want to leave the network running, or controlling_pid is 1
+        # (or invalid)
+        if (os.environ.get('CHUTNEY_START_TIME', 0) < 0 or
+            os.environ.get('CHUTNEY_BOOTSTRAP_TIME', 0) < 0 or
+            os.environ.get('CHUTNEY_STOP_TIME', 0) < 0 or
+            cpid <= 1):
+            return '#' + ocp_line
+        else:
+            return ocp_line
+
 
 class Network(object):
 
diff --git a/tools/test-network.sh b/tools/test-network.sh
index 12855bc..0107ec7 100755
--- a/tools/test-network.sh
+++ b/tools/test-network.sh
@@ -9,6 +9,9 @@ myname=$(basename "$0")
 export CHUTNEY_WARNINGS_IGNORE_EXPECTED=${CHUTNEY_WARNINGS_IGNORE_EXPECTED:-true}
 export CHUTNEY_WARNINGS_SUMMARY=${CHUTNEY_WARNINGS_SUMMARY:-true}
 
+# default to exiting when this script exits
+export CHUTNEY_CONTROLLING_PID=${CHUTNEY_CONTROLLING_PID:-$$}
+
 # what we say when we fail
 UPDATE_YOUR_CHUTNEY="Please update your chutney using 'git pull'."
 
@@ -60,6 +63,12 @@ do
       export CHUTNEY_STOP_TIME="$2"
       shift
     ;;
+    # If all of the CHUTNEY_*_TIME options are positive, chutney will ask tor
+    # to exit when this PID exits. Set to 1 or lower to disable.
+    --controlling-pid)
+      export CHUTNEY_CONTROLLING_PID="$2"
+      shift
+    ;;
     # Environmental variables used by chutney verify performance tests
     # Send this many bytes per client connection (10 KBytes)
     --data|--data-bytes|--data-byte|--bytes|--byte)
diff --git a/torrc_templates/common.i b/torrc_templates/common.i
index 39c76f8..5213823 100644
--- a/torrc_templates/common.i
+++ b/torrc_templates/common.i
@@ -45,6 +45,10 @@ ControlPort $controlport
 ControlSocket ${dir}/control
 CookieAuthentication 1
 PidFile ${dir}/pid
+# Ask all child tor processes to exit when chutney's test-network.sh exits
+# (if the CHUTNEY_*_TIME options leave the network running, this option is
+# disabled)
+${owning_controller_process}
 
 Log notice file ${dir}/notice.log
 Log info file ${dir}/info.log





More information about the tor-commits mailing list