[tor-commits] [vidalia/master] Prevent hanging at start because of timing problem

chiiph at torproject.org chiiph at torproject.org
Sat Aug 13 03:11:29 UTC 2011


commit d98686dd808a4760fe302cbc883713effdcdb8ea
Author: Tomas Touceda <chiiph at torproject.org>
Date:   Fri Aug 12 20:44:11 2011 -0300

    Prevent hanging at start because of timing problem
    
    Tor takes a bit to create the port.conf file and Vidalia hangs without
    warning when it can't read it.
    The idea is to try 5 times waiting 1 second, or fail explaining the reason.
    5 seconds should be enough in most systems.
---
 src/vidalia/MainWindow.cpp |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index b1aff22..9ef9656 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -1142,8 +1142,20 @@ MainWindow::started()
   if(settings.autoControlPort()) {
     QString dataDirectory = settings.getDataDirectory();
     QFile file(QString("%1/port.conf").arg(expand_filename(dataDirectory)));
-    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+    int tries = 0, maxtries = 5;
+    while((!file.open(QIODevice::ReadOnly | QIODevice::Text)) and
+	  (tries++ < maxtries)) {
+      vWarn(QString("This is try number: %1.").arg(tries));
+      sleep(1);
+    }
+
+    if(tries >= maxtries) {
+      vWarn("Couldn't read port.conf file");
+      connectFailed(QString("Vidalia can't find out how to talk to Tor because it can't access this file: %1\n\nHere's the last error message:\n %2")
+		    .arg(file.fileName())
+		    .arg(file.errorString()));
       return;
+    }
 
     QTextStream in(&file);
     if(!in.atEnd()) {
@@ -1159,6 +1171,8 @@ MainWindow::started()
       _autoControlPort = addrPort.at(1).toInt();
       _torControl->connect(addr, _autoControlPort);
     }
+
+    file.close();
   } else {
     /* Try to connect to Tor's control port */
     if(settings.getControlMethod() == ControlMethod::Port) {





More information about the tor-commits mailing list