Throw a proper exception on Unix elevation fail

pull/7639/head
maximilionus 2025-07-23 05:56:54 +03:00
parent 7d6018638e
commit bf1c601cb5
1 changed files with 10 additions and 4 deletions

View File

@ -29,6 +29,7 @@ public class CoreAdminHandler
public async Task<Process?> RunProcessAsLinuxSudo(string fileName, CoreInfo coreInfo, string configPath)
{
Process process = null;
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
var shFilePath = await CreateLinuxShellFile(cmdLine, "run_as_sudo.sh");
@ -50,13 +51,18 @@ public class CoreAdminHandler
.WithValidation(CommandResultValidation.None)
.ExecuteAsync();
Task.Delay(100)
if (cmdTask.ProcessId is null)
throw new Exception(ResUI.FailedToRunCore);
_linuxSudoPid = cmdTask.ProcessId;
process = Process.GetProcessById(_linuxSudoPid);
return Process.GetProcessById(_linuxSudoPid);
await Task.Delay(5000); // Sudo exit on wrong password takes 2-4 sec.
if (process.HasExited || process is null)
{
_linuxSudoPid = -1;
throw new Exception(ResUI.FailedToRunCore);
}
return process;
}
public async Task KillProcessAsLinuxSudo()