Skip to content

Commit

Permalink
Don't daemonize Tor process
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Jul 30, 2023
1 parent 53bb78b commit a42ee89
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public Map<String, String> generate() {
torConfigMap.put("TestingMinExitFlagThreshold", "0");

torConfigMap.put("DataDirectory", thisTorNode.getDataDir().toAbsolutePath().toString());
torConfigMap.put("RunAsDaemon", "1");

torConfigMap.put("Nickname", thisTorNode.getNickname());
torConfigMap.put("ShutdownWaitLength", "2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public ClientTorrcGenerator(Path dataDirPath, int controlPort, String hashedCont

public Map<String, String> generate() {
torConfigMap.put("DataDirectory", dataDirPath.toAbsolutePath().toString());
torConfigMap.put("RunAsDaemon", "1");

torConfigMap.put("ControlPort", "127.0.0.1:" + controlPort);
torConfigMap.put("HashedControlPassword", hashedControlPassword);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.tor.process;

public class CouldNotWaitForTorShutdown extends RuntimeException {
public CouldNotWaitForTorShutdown(String message) {
super(message);
}

public CouldNotWaitForTorShutdown(Throwable cause) {
super(cause);
}
}
14 changes: 14 additions & 0 deletions network/tor/src/main/java/bisq/tor/process/NativeTorProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

@Slf4j
Expand Down Expand Up @@ -78,6 +79,19 @@ public void waitUntilControlPortReady() {
}
}

public void waitUntilExited() {
process.ifPresent(process -> {
try {
boolean isSuccess = process.waitFor(2, TimeUnit.MINUTES);
if (!isSuccess) {
throw new CouldNotWaitForTorShutdown("Tor still running after 2 minutes timeout.");
}
} catch (InterruptedException e) {
throw new CouldNotWaitForTorShutdown(e);
}
});
}

private Future<Path> createLogFileCreationWaiter() {
Path dataDir = torrcPath.getParent();
Path logFilePath = torrcPath.getParent().resolve("debug.log");
Expand Down

0 comments on commit a42ee89

Please sign in to comment.