Browse Source

Specify additional environment variables for nodes

Each node now has a 'add_environ_vars' argument which allows you
to specify environment variables to add to tor's environment.
Steven Engler 2 years ago
parent
commit
d799e06ea9
1 changed files with 11 additions and 3 deletions
  1. 11 3
      lib/chutney/TorNet.py

+ 11 - 3
lib/chutney/TorNet.py

@@ -211,13 +211,17 @@ def run_tor(cmdline, exit_on_missing=True):
             raise
     return stdouterr
 
-def launch_process(cmdline, tor_name="tor", stdin=None, exit_on_missing=True):
+def launch_process(cmdline, tor_name="tor", stdin=None, exit_on_missing=True, add_environ_vars=None):
     """Launch the command line cmdline, which must start with the path or
        name of a binary. Use tor_name as the canonical name of the binary.
        Pass stdin to the Popen constructor.
 
        Returns the Popen object for the launched process.
     """
+    custom_environ = os.environ.copy()
+    if add_environ_vars is not None:
+        custom_environ.update(add_environ_vars)
+
     if tor_name == "tor" and not debug_flag:
         cmdline.append("--quiet")
     elif tor_name == "tor-gencert" and debug_flag:
@@ -228,7 +232,8 @@ def launch_process(cmdline, tor_name="tor", stdin=None, exit_on_missing=True):
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT,
                              universal_newlines=True,
-                             bufsize=-1)
+                             bufsize=-1,
+                             env=custom_environ)
     except OSError as e:
         # only catch file not found error
         if e.errno == errno.ENOENT:
@@ -894,11 +899,13 @@ class LocalNodeController(NodeController):
             cmdline.extend(self._env['valgrind_settings'])
             cmdline.append('--log-file={}'.format(self._env['valgrind_log']))
         #
+        add_environ_vars = self._env['add_environ_vars']
+        #
         cmdline.extend([
             tor_path,
             "-f", torrc,
             ])
-        p = launch_process(cmdline)
+        p = launch_process(cmdline, add_environ_vars=add_environ_vars)
         if self.waitOnLaunch():
             # this requires that RunAsDaemon is set
             (stdouterr, empty_stderr) = p.communicate()
@@ -1092,6 +1099,7 @@ DEFAULTS = {
     'measureme_log_dir': '${dir}',
     'nick_base': 'test',
     'valgrind_settings': None,
+    'add_environ_vars': None,
 }