From 0b7d728b04315d5e46d04636aa36886a656d10dd Mon Sep 17 00:00:00 2001 From: maximilionus Date: Thu, 24 Jul 2025 17:12:27 +0300 Subject: [PATCH] Improve CoreAdminHandler null obj init --- v2rayN/ServiceLib/Handler/CoreAdminHandler.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs b/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs index 1c4c441e..7215beb1 100644 --- a/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs @@ -29,9 +29,9 @@ 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"); + Process? process = null; var cmdTask = Cli.Wrap(shFilePath) .WithWorkingDirectory(Utils.GetBinConfigPath()) @@ -51,13 +51,12 @@ public class CoreAdminHandler .WithValidation(CommandResultValidation.None) .ExecuteAsync(); - _linuxSudoPid = cmdTask.ProcessId; try { process = Process.GetProcessById(_linuxSudoPid); - await Task.Delay(5000); // Sudo exit on wrong password takes 2-4 sec. + await Task.Delay(5000); // Sudo exit on wrong password takes 2-4 sec. if (process.HasExited) throw new InvalidOperationException("Process exited too soon, likely improper sudo password."); }