From bf1c601cb5e80a4b5145dca33f16773d58362966 Mon Sep 17 00:00:00 2001 From: maximilionus Date: Wed, 23 Jul 2025 05:56:54 +0300 Subject: [PATCH] Throw a proper exception on Unix elevation fail --- v2rayN/ServiceLib/Handler/CoreAdminHandler.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs b/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs index 85830fa1..ee197b64 100644 --- a/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs @@ -29,6 +29,7 @@ public class CoreAdminHandler public async Task 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()