Bläddra i källkod

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 6 år sedan
förälder
incheckning
d799e06ea9
1 ändrade filer med 11 tillägg och 3 borttagningar
  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
             raise
     return stdouterr
     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
     """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.
        name of a binary. Use tor_name as the canonical name of the binary.
        Pass stdin to the Popen constructor.
        Pass stdin to the Popen constructor.
 
 
        Returns the Popen object for the launched process.
        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:
     if tor_name == "tor" and not debug_flag:
         cmdline.append("--quiet")
         cmdline.append("--quiet")
     elif tor_name == "tor-gencert" and debug_flag:
     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,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT,
                              stderr=subprocess.STDOUT,
                              universal_newlines=True,
                              universal_newlines=True,
-                             bufsize=-1)
+                             bufsize=-1,
+                             env=custom_environ)
     except OSError as e:
     except OSError as e:
         # only catch file not found error
         # only catch file not found error
         if e.errno == errno.ENOENT:
         if e.errno == errno.ENOENT:
@@ -894,11 +899,13 @@ class LocalNodeController(NodeController):
             cmdline.extend(self._env['valgrind_settings'])
             cmdline.extend(self._env['valgrind_settings'])
             cmdline.append('--log-file={}'.format(self._env['valgrind_log']))
             cmdline.append('--log-file={}'.format(self._env['valgrind_log']))
         #
         #
+        add_environ_vars = self._env['add_environ_vars']
+        #
         cmdline.extend([
         cmdline.extend([
             tor_path,
             tor_path,
             "-f", torrc,
             "-f", torrc,
             ])
             ])
-        p = launch_process(cmdline)
+        p = launch_process(cmdline, add_environ_vars=add_environ_vars)
         if self.waitOnLaunch():
         if self.waitOnLaunch():
             # this requires that RunAsDaemon is set
             # this requires that RunAsDaemon is set
             (stdouterr, empty_stderr) = p.communicate()
             (stdouterr, empty_stderr) = p.communicate()
@@ -1092,6 +1099,7 @@ DEFAULTS = {
     'measureme_log_dir': '${dir}',
     'measureme_log_dir': '${dir}',
     'nick_base': 'test',
     'nick_base': 'test',
     'valgrind_settings': None,
     'valgrind_settings': None,
+    'add_environ_vars': None,
 }
 }