Commit 9a8902c7 authored by zeroleak's avatar zeroleak
Browse files

detect runtime errors on tor executable

parent 0b15c8f4
......@@ -88,9 +88,11 @@ public class JavaTorClient {
return file;
}
public JavaTorClient(CliConfig cliConfig) throws Exception {
public JavaTorClient(CliConfig cliConfig) {
this.cliConfig = cliConfig;
}
public void setup() throws Exception {
Optional<File> torExecutable = computeTorExecutable();
boolean useExecutableFromZip = !torExecutable.isPresent();
......
......@@ -10,6 +10,7 @@ import com.msopentech.thali.toronionproxy.FileUtilities;
import com.msopentech.thali.toronionproxy.OsData;
import com.msopentech.thali.toronionproxy.TorConfig;
import com.msopentech.thali.toronionproxy.TorInstaller;
import com.samourai.whirlpool.cli.utils.CliUtils;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
......@@ -69,6 +70,13 @@ public final class WhirlpoolTorInstaller extends TorInstaller {
torParent.exists() ? torParent : this.config.getTorExecutableFile(),
this.getAssetOrResourceByName(getPathToTorExecutable() + "tor.zip"));
FileUtilities.setPerms(this.config.getTorExecutableFile());
// detect runtime errors on tor executable (ie "error while loading shared libraries...")
try {
CliUtils.exec(this.config.getTorExecutableFile().getAbsolutePath() + " --help");
} catch (Exception e) {
throw new IOException("Tor executable error: " + e.getMessage());
}
}
public void updateTorConfigCustom(String content) throws IOException, TimeoutException {
......
......@@ -97,7 +97,6 @@ public class Application implements ApplicationRunner {
if (log.isDebugEnabled()) {
log.debug("Run... " + Arrays.toString(applicationArguments.getSourceArgs()));
}
if (log.isDebugEnabled()) {
log.debug("[cli/debug] debug=" + debug + ", debugClient=" + debugClient);
log.debug("[cli/protocolVersion] " + WhirlpoolProtocol.PROTOCOL_VERSION);
......@@ -105,6 +104,9 @@ public class Application implements ApplicationRunner {
}
try {
// setup Tor etc...
cliService.setup();
if (env.acceptsProfiles(CliUtils.SPRING_PROFILE_TESTING)) {
log.info("Running unit test...");
return;
......
......@@ -51,11 +51,10 @@ public class CliService {
this.walletAggregateService = walletAggregateService;
this.cliTorClientService = cliTorClientService;
this.cliStatusOrchestrator = null;
setup();
init();
}
private void setup() {
private void init() {
// properties were set on CliConfig => override CliConfig with cli args
appArgs.override(cliConfig);
......@@ -67,6 +66,11 @@ public class CliService {
}
}
public void setup() throws Exception {
// setup Tor
cliTorClientService.setup();
}
private File computeDirLockFile() throws NotifiableException {
String path = "whirlpool-cli.lock";
return CliUtils.computeFile(path);
......
......@@ -23,6 +23,13 @@ public class CliTorClientService {
this.cliConfig = cliConfig;
}
public void setup() throws Exception {
Optional<JavaTorClient> torClient = getTorClient();
if (torClient.isPresent()) {
torClient.get().setup();
}
}
public void connect() {
Optional<JavaTorClient> torClient = getTorClient();
if (torClient.isPresent()) {
......
......@@ -216,7 +216,9 @@ public class CliUtils {
int exit = proc.waitFor();
if (exit != 0) {
throw new RuntimeException("exec [" + cmd + "] returned error code: " + exit);
String output = StringUtils.join(lines, "\n");
throw new RuntimeException(
"exec [" + cmd + "] returned error code: " + exit + "\nOutput:\n" + output);
}
} finally {
if (proc != null) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment