Apply CR recommendations
MODIFY
WalletWasabi/Extensions/ProcessExtensions.cs
WalletWasabi/Extensions/ProcessExtensions.cs
@@ -71,14 +71,5 @@ namespace System.Diagnostics
Logger.LogError(ex, nameof(ProcessExtensions));
}
}
-
- public static TaskAwaiter<int> GetAwaiter(this Process process)
- {
- var tcs = new TaskCompletionSource<int>();
- process.EnableRaisingEvents = true;
- process.Exited += (s, e) => tcs.TrySetResult(process.ExitCode);
- if (process.HasExited) tcs.TrySetResult(process.ExitCode);
- return tcs.Task.GetAwaiter();
- }
}
}

MODIFY
WalletWasabi/Helpers/EnvironmentHelpers.cs
WalletWasabi/Helpers/EnvironmentHelpers.cs
@@ -5,6 +5,7 @@ using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Logging;
@@ -160,11 +161,6 @@ namespace WalletWasabi.Helpers
return fileNameWithoutExtension;
}
- public static void ShellExec(string cmd, bool waitForExit = true)
- {
- ShellExecAsync(cmd, waitForExit).GetAwaiter().GetResult();
- }
-
/// <summary>
/// Executes a command with bash.
/// https://stackoverflow.com/a/47918132/2061103
@@ -187,7 +183,8 @@ namespace WalletWasabi.Helpers
);
if(waitForExit)
{
- var exitCode = await process;
+ await process.WaitForExitAsync(CancellationToken.None).ConfigureAwait(false);
+ var exitCode = process.ExitCode;
if (exitCode != 0)
{
Logger.LogError($"{nameof(ShellExecAsync)} command: {cmd} exited with exit code: {exitCode}, instead of 0.");

MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -130,7 +130,7 @@ namespace WalletWasabi.TorSocks5
else // Linux and OSX
{
string runTorCmd = $"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:={torDir}/Tor && export LD_LIBRARY_PATH && cd {torDir}/Tor && ./tor {torArguments}";
- EnvironmentHelpers.ShellExec(runTorCmd, false);
+ EnvironmentHelpers.ShellExecAsync(runTorCmd, false).GetAwaiter().GetResult();
Logger.LogInfo($"Started Tor process with shell command: {runTorCmd}.");
}
@@ -187,7 +187,7 @@ namespace WalletWasabi.TorSocks5
// Make sure there's sufficient permission.
string chmodTorDirCmd = $"chmod -R 750 {torDir}";
- EnvironmentHelpers.ShellExec(chmodTorDirCmd);
+ EnvironmentHelpers.ShellExecAsync(chmodTorDirCmd).GetAwaiter().GetResult();
Logger.LogInfo($"Shell command executed: {chmodTorDirCmd}.");
}
}

Apply CR recommendations