Replace core killing script with a one-liner

This commit is contained in:
Valeriy Manzhos 2026-04-09 17:43:19 +03:00
parent bcef55a6bb
commit d5267d0b69
No known key found for this signature in database
GPG key ID: 6547CFC8E2EC3D90
2 changed files with 13 additions and 16 deletions

View file

@ -68,19 +68,19 @@ public class CoreAdminManager
try
{
var shellFileName = Utils.IsMacOS() ? Global.KillAsSudoOSXShellFileName : Global.KillAsSudoLinuxShellFileName;
var shFilePath = await FileUtils.CreateLinuxShellFile("kill_as_sudo.sh", EmbedUtils.GetEmbedText(shellFileName), true);
if (shFilePath.Contains(' '))
if (Utils.IsLinux())
{
shFilePath = shFilePath.AppendQuotes();
var procService = new ProcessService(
fileName: "/usr/bin/sudo",
arguments: "-u#785 /usr/bin/pkill --uid 785 --exact sing-box",
workingDirectory: Utils.GetBinConfigPath(),
displayLog: true,
redirectInput: false,
environmentVars: null,
updateFunc: null
);
await procService.StartAsync(AppManager.Instance.LinuxSudoPwd);
}
var arg = new List<string>() { "-c", $"sudo -S {shFilePath} {_linuxSudoPid}" };
var result = await Cli.Wrap(Global.LinuxBash)
.WithArguments(arg)
.WithStandardInputPipe(PipeSource.FromString(AppManager.Instance.LinuxSudoPwd))
.ExecuteBufferedAsync();
await UpdateFunc(false, result.StandardOutput.ToString());
}
catch (Exception ex)
{

View file

@ -150,11 +150,8 @@ public class CoreManager
{
try
{
if (_linuxSudo)
{
await CoreAdminManager.Instance.KillProcessAsLinuxSudo();
_linuxSudo = false;
}
await CoreAdminManager.Instance.KillProcessAsLinuxSudo();
_linuxSudo = false;
if (_processService != null)
{