[tor-commits] [arm/master] fix: uncaught exceptions when resuming borken conf

atagar at torproject.org atagar at torproject.org
Tue Jul 12 21:36:32 UTC 2011


commit 1c0c1f3029fbde3441c881930b292a0176d4e02d
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jul 9 23:19:34 2011 -0700

    fix: uncaught exceptions when resuming borken conf
    
    When selecting 'Use Last Configuration' in the wizard or 'Start Tor' from the
    menu when the last torrc was broken caused uncaught exceptions. It's actually
    better if the starter function did logging itself instead so passing on a
    success boolean instead.
---
 src/cli/controller.py |   23 +++++++++++++++++------
 src/cli/wizard.py     |   18 +++++++-----------
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/cli/controller.py b/src/cli/controller.py
index a04bf99..e30af3f 100644
--- a/src/cli/controller.py
+++ b/src/cli/controller.py
@@ -459,7 +459,8 @@ class TorManager:
   
   def startManagedInstance(self):
     """
-    Starts a managed instance of tor, raising an IOError if unsuccessful.
+    Starts a managed instance of tor, logging a warning if unsuccessful. This
+    returns True if successful and False otherwise.
     """
     
     torrcLoc = self.getTorrcPath()
@@ -472,16 +473,26 @@ class TorManager:
     while not torctlConn and time.time() - startTime < 5:
       try:
         torctlConn, authType, authValue = TorCtl.preauth_connect(controlPort = int(CONFIG["wizard.default"]["Control"]))
-      except IOError, exc: time.sleep(0.5)
+      except IOError: time.sleep(0.5)
     
     if not torctlConn:
-      raise IOError("try running \"tor -f %s\" for error output" % torrcLoc)
+      msg = "Unable to start tor, try running \"tor -f %s\" to see the error output" % torrcLoc
+      log.log(log.WARN, msg)
+      return False
     
     if authType == TorCtl.AUTH_TYPE.COOKIE:
-      torctlConn.authenticate(authValue)
-      torTools.getConn().init(torctlConn)
+      try:
+        torctlConn.authenticate(authValue)
+        torTools.getConn().init(torctlConn)
+        return True
+      except Exception, exc:
+        msg = "Unable to connect to Tor: %s" % exc
+        log.log(log.WARN, msg)
+        return False
     else:
-      raise IOError("unexpected authentication type '%s'" % authType)
+      msg = "Unable to connect to Tor, unexpected authentication type '%s'" % authType
+      log.log(log.WARN, msg)
+      return False
 
 def shutdownDaemons():
   """
diff --git a/src/cli/wizard.py b/src/cli/wizard.py
index 6d2e623..be7ac8a 100644
--- a/src/cli/wizard.py
+++ b/src/cli/wizard.py
@@ -294,17 +294,13 @@ def showWizard():
           torrcFile.write(generatedTorrc)
           torrcFile.close()
           
-          try:
-            conn = torTools.getConn()
-            
-            # If we're connected to a managed instance then just need to
-            # issue a sighup to pick up the new settings. Otherwise starts
-            # a new tor instance.
-            
-            if manager.isManaged(conn): conn.reset()
-            else: manager.startManagedInstance()
-          except IOError, exc:
-            log.log(log.WARN, "Unable to start tor, %s" % exc)
+          # If we're connected to a managed instance then just need to
+          # issue a sighup to pick up the new settings. Otherwise starts
+          # a new tor instance.
+          
+          conn = torTools.getConn()
+          if manager.isManaged(conn): conn.reset()
+          else: manager.startManagedInstance()
           
           break
         elif confirmationSelection == CANCEL: break





More information about the tor-commits mailing list