[tor-commits] [arm/master] fix: prevent startup if can't connect to tor

atagar at torproject.org atagar at torproject.org
Fri Aug 26 17:29:43 UTC 2011


commit d977dc8d965abf0cb8ebae527222cb48b8ca3cdb
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Aug 26 08:23:56 2011 -0700

    fix: prevent startup if can't connect to tor
    
    We've had a couple people confused because tor is running without a control
    port but when they start arm it provides the wizard, saying that tor's shut
    down. Making detached startup contingent on not having an active tor process to
    avoid this.
---
 src/starter.py       |    8 ++++++--
 src/util/torTools.py |   14 ++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/starter.py b/src/starter.py
index ff2f4a8..a2617f7 100644
--- a/src/starter.py
+++ b/src/starter.py
@@ -386,8 +386,12 @@ if __name__ == '__main__':
     msg = STANDARD_CFG_NOT_FOUND_MSG % configPath
     util.log.log(util.log.NOTICE, msg)
   
-  # when launching a prompt it doens't make sense to be without a tor instance
-  if launchPrompt:
+  # prevent arm from starting without a tor instance if...
+  # - we're launching a prompt
+  # - tor is running (otherwise it would be kinda confusing, "tor is running
+  #   but why does arm say that it's shut down?")
+  
+  if launchPrompt or util.torTools.isTorRunning():
     config.set("features.allowDetachedStartup", "false")
   
   # revises defaults to match user's configuration
diff --git a/src/util/torTools.py b/src/util/torTools.py
index 39cb176..5c1b1ad 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -345,6 +345,20 @@ def isVersion(myVersion, minVersion):
     
     return True # versions match (should have been caught above...)
 
+def isTorRunning():
+  """
+  Simple check for if a tor process is running. If this can't be determined
+  then this returns False.
+  """
+  
+  # suggestions welcome for making this more reliable
+  commandResults = sysTools.call("ps co command")
+  if commandResults:
+    for cmd in commandResults:
+      if cmd.strip() == "tor": return True
+  
+  return False
+
 def getConn():
   """
   Singleton constructor for a Controller. Be aware that this starts as being





More information about the tor-commits mailing list