Improve caffeinate script
MODIFY
WalletWasabi/Helpers/PowerSaving/BaseInhibitorTask.cs
WalletWasabi/Helpers/PowerSaving/BaseInhibitorTask.cs
@@ -65,7 +65,7 @@ public class BaseInhibitorTask : IPowerSavingInhibitorTask
// Process cannot stop on its own so we know it is actually running.
try
{
- Process.Kill();
+ Process.Kill(entireProcessTree: true);
Logger.LogTrace("Inhibit task was killed.");
}
catch (Exception ex)

MODIFY
WalletWasabi/Helpers/PowerSaving/MacOsInhibitorTask.cs
WalletWasabi/Helpers/PowerSaving/MacOsInhibitorTask.cs
@@ -16,8 +16,15 @@ public class MacOsInhibitorTask : BaseInhibitorTask
public static MacOsInhibitorTask Create(TimeSpan basePeriod, string reason)
{
- string command = $"caffeinate";
- string arguments = $"-i";
+ string innerCommand = $$"""
+ caffeinate -i &;
+ caffeinatePid=$!;
+ trap \"kill -9 $caffeinatePid\" 0 SIGINT SIGTERM;
+ wait {{Environment.ProcessId}};
+ """.ReplaceLineEndings(replacementText: " ");
+
+ string command = $"/bin/bash";
+ string arguments = $"-c \"{innerCommand}\"";
Logger.LogTrace($"Command to invoke: {command} {arguments}");
ProcessStartInfo startInfo = GetProcessStartInfo(command, arguments);

MODIFY
WalletWasabi/Microservices/ProcessAsync.cs
WalletWasabi/Microservices/ProcessAsync.cs
@@ -67,10 +67,10 @@ public class ProcessAsync : IDisposable
}
}
- /// <inheritdoc cref="Process.Kill()"/>
- public virtual void Kill()
+ /// <inheritdoc cref="Process.Kill(bool)"/>
+ public virtual void Kill(bool entireProcessTree = false)
{
- Process.Kill();
+ Process.Kill(entireProcessTree);
}
/// <summary>

Improve caffeinate script