[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1372: The TorService::finished() signal was connected to a slot th (trunk/src/control)



Author: edmanm
Date: 2006-10-22 19:56:51 -0400 (Sun, 22 Oct 2006)
New Revision: 1372

Modified:
   trunk/src/control/torcontrol.cpp
   trunk/src/control/torservice.cpp
   trunk/src/control/torservice.h
Log:
The TorService::finished() signal was connected to a slot that did not exist,
since it didn't really expose the same signal prototypes as TorProcess (which I
think is what was intended). So, make the TorService::finished() signal look the
same as the TorProcess::finished() signal by emitting the exit code and
status, too.


Modified: trunk/src/control/torcontrol.cpp
===================================================================
--- trunk/src/control/torcontrol.cpp	2006-10-22 07:19:36 UTC (rev 1371)
+++ trunk/src/control/torcontrol.cpp	2006-10-22 23:56:51 UTC (rev 1372)
@@ -57,8 +57,8 @@
   _torService = new TorService(this);
   QObject::connect(_torService, SIGNAL(started()),
                    this, SLOT(onStarted()), Qt::QueuedConnection);
-  QObject::connect(_torService, SIGNAL(finished()),
-                   this, SLOT(onStopped()));
+  QObject::connect(_torService, SIGNAL(finished(int, QProcess::ExitStatus)),
+                   this, SLOT(onStopped(int, QProcess::ExitStatus)));
   QObject::connect(_torService, SIGNAL(startFailed(QString)),
                    this, SLOT(onStartFailed(QString)), 
                    Qt::QueuedConnection);

Modified: trunk/src/control/torservice.cpp
===================================================================
--- trunk/src/control/torservice.cpp	2006-10-22 07:19:36 UTC (rev 1371)
+++ trunk/src/control/torservice.cpp	2006-10-22 23:56:51 UTC (rev 1372)
@@ -27,6 +27,11 @@
 
 #include "torservice.h"
 
+/** Returned by TorService::exitCode() when we are unable to determine the
+ * actual exit code of the service (unless, of course, Tor returns -999999). */
+#define UNKNOWN_EXIT_CODE     -999999
+
+
 /** Returns true if services are supported. */
 bool
 TorService::isSupported()
@@ -163,10 +168,47 @@
     }
   }
 
-  if (!isRunning()) emit finished();
+  if (!isRunning()) {
+    /* Emit the signal that we stopped and the service's exit code and status. */
+    emit finished(exitCode(), exitStatus());
+  }
 #endif
 }
 
+/** Returns the exit code of the last Tor service that finished. */
+int
+TorService::exitCode()
+{
+  int exitCode = UNKNOWN_EXIT_CODE;
+#if defined(Q_OS_WIN32)
+  if (isSupported() && _manager && _service) {
+    SERVICE_STATUS s;
+
+    if (QueryServiceStatus(_service, &s)) {
+      /* Services return one exit code, but it could be in one of two
+       * variables. Fun. */
+      exitCode = (int)(s.dwWin32ExitCode == ERROR_SERVICE_SPECIFIC_ERROR
+                                              ? s.dwServiceSpecificExitCode
+                                              : s.dwWin32ExitCode);
+    }
+  }
+#endif
+  return exitCode;
+}
+
+/** Returns the exit status of the last Tor service that finished. */
+QProcess::ExitStatus
+TorService::exitStatus()
+{
+  /* NT services don't really have an equivalent to QProcess::CrashExit, so 
+   * this just returns QProcess::NormalExit. Tor _could_ set
+   * dwServiceSpecificExitCode to some magic value when it starts and then
+   * set it to the real exit code when Tor exits. Then we would know if the
+   * service crashed when dwServiceSpecificExitCode is still the magic value.
+   * However, I don't care and it doesn't really matter anyway. */
+  return QProcess::NormalExit;
+}
+
 /** Installs the Tor service. */
 bool
 TorService::install(const QString &torPath, const QString &torrc,

Modified: trunk/src/control/torservice.h
===================================================================
--- trunk/src/control/torservice.h	2006-10-22 07:19:36 UTC (rev 1371)
+++ trunk/src/control/torservice.h	2006-10-22 23:56:51 UTC (rev 1372)
@@ -29,6 +29,7 @@
 #define _TORSERVICE_H
 
 #include <QObject>
+#include <QProcess>
 
 #if defined(Q_OS_WIN32)
   #include <windows.h>
@@ -65,6 +66,10 @@
   void start();
   /** Stops the Tor service. Emits finished on success. */
   void stop();
+  /** Returns the exit code of the last Tor service that finished. */
+  int exitCode();
+  /** Returns the exit status of the last Tor service that finished. */
+  QProcess::ExitStatus exitStatus();
   /** Installs the Tor service. */
   bool install(const QString &torPath, const QString &torrc,
                quint16 controlPort);
@@ -75,7 +80,7 @@
   /** Called when the service gets started. */
   void started();
   /** Called when the service gets stopped. */
-  void finished();
+  void finished(int exitCode, QProcess::ExitStatus);
   /** Called when there is an error in starting the service. */
   void startFailed(QString error);