commit e22a753058a2b9c61301c62e2d2123ccea046f29 Author: Damian Johnson atagar@torproject.org Date: Fri Dec 21 08:02:10 2012 -0800
Sanity testing the that the tor command points to tor
Adding some basic sanity tests to launch_tor() so that we provide a better error message if our tor command is wrong. This is to address the following, which was admittedly really confusing error output...
https://lists.torproject.org/pipermail/tor-dev/2012-December/004296.html
Caught thanks to Simon. --- run_tests.py | 5 ----- stem/process.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/run_tests.py b/run_tests.py index d57765b..129c479 100755 --- a/run_tests.py +++ b/run_tests.py @@ -248,11 +248,6 @@ def load_user_configuration(test_config): print "'%s' isn't a logging runlevel, use one of the following instead:" % log_config print " TRACE, DEBUG, INFO, NOTICE, WARN, ERROR" sys.exit(1) - - tor_config = CONFIG["argument.tor"] - if CONFIG["argument.integ"] and not os.path.exists(tor_config) and not stem.util.system.is_available(tor_config): - print "Unable to start tor, '%s' does not exists." % tor_config - sys.exit(1)
def _clean_orphaned_pyc(): test.output.print_noline(" checking for orphaned .pyc files... ", *test.runner.STATUS_ATTR) diff --git a/stem/process.py b/stem/process.py index aaa36ac..a27c68e 100644 --- a/stem/process.py +++ b/stem/process.py @@ -64,6 +64,18 @@ def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_perce if stem.util.system.is_windows(): timeout = None
+ # sanity check that we got a tor binary + + if os.path.sep in tor_cmd: + # got a path (either relative or absolute), check what it leads to + + if os.path.isdir(tor_cmd): + raise OSError("'%s' is a directory, not the tor executable" % tor_cmd) + elif not os.path.isfile(tor_cmd): + raise OSError("'%s' doesn't exist" % tor_cmd) + elif not stem.util.system.is_available(tor_cmd): + raise OSError("'%s' isn't available on your system. Maybe it's not in your PATH?" % tor_cmd) + # double check that we have a torrc to work with if not torrc_path in (None, NO_TORRC) and not os.path.exists(torrc_path): raise OSError("torrc doesn't exist (%s)" % torrc_path)