[or-cvs] r11435: improved error message when trying to start nodes with an in (puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl)
kloesing at seul.org
kloesing at seul.org
Wed Sep 12 17:58:35 UTC 2007
Author: kloesing
Date: 2007-09-12 13:58:35 -0400 (Wed, 12 Sep 2007)
New Revision: 11435
Modified:
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/DirectoryNodeImpl.java
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/RouterNodeImpl.java
Log:
improved error message when trying to start nodes with an incorrect configuration
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/DirectoryNodeImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/DirectoryNodeImpl.java 2007-09-12 17:33:23 UTC (rev 11434)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/DirectoryNodeImpl.java 2007-09-12 17:58:35 UTC (rev 11435)
@@ -150,4 +150,30 @@
// log exiting
this.logger.exiting(this.getClass().getName(), "writeApprovedRouters");
}
+
+ public synchronized String determineFingerprint()
+ throws TorProcessException {
+
+ // log entering
+ this.logger.entering(this.getClass().getName(), "determineFingerprint");
+
+ // check if the fingerprint has not been determined before
+ if (this.fingerprint == null) {
+
+ // create an empty approved-routers file to make Tor happy
+ try {
+ new File(this.workingDir.getAbsolutePath() + File.separator
+ + "approved-routers").createNewFile();
+ } catch (IOException e) {
+ TorProcessException ex = new TorProcessException(
+ "Could not write empty approved-routers file!", e);
+ this.logger.throwing(this.getClass().getName(),
+ "determineFingerprint", ex);
+ throw ex;
+ }
+ }
+
+ // invoke overwritten method
+ return super.determineFingerprint();
+ }
}
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java 2007-09-12 17:33:23 UTC (rev 11434)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java 2007-09-12 17:58:35 UTC (rev 11435)
@@ -595,6 +595,69 @@
this.logger.exiting(this.getClass().getName(), "shutdown");
}
+ /**
+ * Helper thread that waits for a given time for a given process to
+ * potentially terminate in order to find out if there are problems. If
+ * either the process terminates cleanly within this timeout, or does not
+ * terminate, the exit value will be 0; otherwise it will contain the exit
+ * code of the terminated process. This functionality is added, because it
+ * is not provided by Process.
+ */
+ private class ProcessWaiter extends Thread {
+
+ /** The process to wait for. */
+ private Process process;
+
+ /** Did we finish waiting? */
+ private boolean finishedWaiting;
+
+ /** The exit value or 0 if the process is still running. */
+ private int exitValue;
+
+ /**
+ * Creates a new <code>ProcessWaiter</code> for process
+ * <code>process</code>, but does not start it, yet.
+ *
+ * @param process
+ * The process to wait for.
+ */
+ ProcessWaiter(Process process) {
+ this.process = process;
+ }
+
+ @Override
+ public void run() {
+ try {
+ this.exitValue = process.waitFor();
+ synchronized (this) {
+ notifyAll();
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+
+ /**
+ * Causes the current thread to wait until the process has terminated or
+ * the <code>timeoutInMillis</code> has expired. This method returns
+ * immediately if the subprocess has already terminated.
+ *
+ * @param timeoutInMillis
+ * The maximum time to wait for the process to terminate.
+ * @return The exit value of the terminated process or 0 if the process
+ * is still running.
+ */
+ public synchronized int waitFor(long timeoutInMillis) {
+ if (!finishedWaiting) {
+ try {
+ wait(timeoutInMillis);
+ } catch (InterruptedException e) {
+ }
+ }
+ this.interrupt();
+ return this.exitValue;
+ }
+ }
+
public synchronized boolean startNode(long maximumTimeToWaitInMillis)
throws TorProcessException {
@@ -683,6 +746,24 @@
"Started shutdown hook that will destroy the Tor process on "
+ "JVM exit!");
+ // wait to see if the process is started or exited immediately; wait for
+ // one second to be sure that Tor terminates if there is an error,
+ // especially if the computer is very busy and many nodes are created
+ ProcessWaiter waiter = new ProcessWaiter(this.torProcess);
+ waiter.start();
+ int exitValue = waiter.waitFor(1000);
+ if (exitValue != 0) {
+ // Tor did not manage to start correctly
+ this.logger.log(Level.WARNING, "Could not start Tor process! Tor "
+ + "exited with exit value " + exitValue
+ + "! Please go check the config options in "
+ + this.configFile + " manually!");
+
+ // log exiting
+ this.logger.exiting(this.getClass().getName(), "startNode", false);
+ return false;
+ }
+
// wait for Tor to open the control port
this.logger.log(Level.FINER,
"Waiting for Tor to open its control port...");
@@ -702,13 +783,6 @@
"Tor has successfully opened its control port and told us "
+ "about that!");
- // be sure that Tor is ready, especially if computer is very busy and
- // many nodes are created
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e2) {
- }
-
// connect to the controller
this.logger.log(Level.FINER, "Connecting to control port...");
try {
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/RouterNodeImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/RouterNodeImpl.java 2007-09-12 17:33:23 UTC (rev 11434)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/RouterNodeImpl.java 2007-09-12 17:58:35 UTC (rev 11435)
@@ -251,16 +251,28 @@
outputThread.setDaemon(true);
outputThread.start();
- // wait for process to terminate
- // TODO should limit waiting to a certain time?!
+ // wait for process to terminate (should be quite fast)
+ int exitValue = 0;
try {
- tmpProcess.waitFor();
+ exitValue = tmpProcess.waitFor();
} catch (InterruptedException e) {
// TODO how to handle?
this.logger.log(Level.WARNING,
"Temporary Tor process was interrupted!", e);
}
+ if (exitValue != 0) {
+ TorProcessException ex = new TorProcessException(
+ "Could not start Tor process temporarily with "
+ + "--list-fingerprint option! Tor exited with "
+ + "exit value " + exitValue
+ + "! Please go check the config options in "
+ + this.tempConfigFile + " manually!");
+ this.logger.throwing(this.getClass().getName(),
+ "determineFingerprint", ex);
+ throw ex;
+ }
+
// read fingerprint from file
this.readFingerprintFromFile();
More information about the tor-commits
mailing list