mirror of https://github.com/2dust/v2rayN
Revert RunProcessAsLinuxSudo to raw Process
parent
be01e09eff
commit
a95413728d
|
@ -31,31 +31,48 @@ public class CoreAdminHandler
|
||||||
{
|
{
|
||||||
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
|
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
|
||||||
var shFilePath = await CreateLinuxShellFile(cmdLine, "run_as_sudo.sh");
|
var shFilePath = await CreateLinuxShellFile(cmdLine, "run_as_sudo.sh");
|
||||||
Process? process = null;
|
|
||||||
|
|
||||||
var cmdTask = Cli.Wrap(shFilePath)
|
Process process = new()
|
||||||
.WithWorkingDirectory(Utils.GetBinConfigPath())
|
{
|
||||||
.WithStandardInputPipe(PipeSource.FromString(AppHandler.Instance.LinuxSudoPwd))
|
StartInfo = new()
|
||||||
.WithStandardOutputPipe(PipeTarget.ToDelegate(
|
{
|
||||||
s =>
|
FileName = shFilePath,
|
||||||
{
|
WorkingDirectory = Utils.GetBinConfigPath(),
|
||||||
if (!string.IsNullOrEmpty(s))
|
UseShellExecute = false,
|
||||||
UpdateFunc(false, s + Environment.NewLine);
|
CreateNoWindow = true,
|
||||||
}))
|
RedirectStandardInput = true,
|
||||||
.WithStandardErrorPipe(PipeTarget.ToDelegate(
|
RedirectStandardOutput = true,
|
||||||
s =>
|
RedirectStandardError = true
|
||||||
{
|
}
|
||||||
if (!string.IsNullOrEmpty(s))
|
};
|
||||||
UpdateFunc(false, s + Environment.NewLine);
|
|
||||||
}))
|
|
||||||
.WithValidation(CommandResultValidation.None)
|
|
||||||
.ExecuteAsync();
|
|
||||||
|
|
||||||
_linuxSudoPid = cmdTask.ProcessId;
|
process.OutputDataReceived += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.Data.IsNotEmpty())
|
||||||
|
{
|
||||||
|
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
process.ErrorDataReceived += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.Data.IsNotEmpty())
|
||||||
|
{
|
||||||
|
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Start();
|
||||||
|
|
||||||
|
process.StandardInput.WriteLine(AppHandler.Instance.LinuxSudoPwd);
|
||||||
|
process.StandardInput.Close();
|
||||||
|
process.BeginOutputReadLine();
|
||||||
|
process.BeginErrorReadLine();
|
||||||
|
|
||||||
|
_linuxSudoPid = process.Id;
|
||||||
|
|
||||||
try
|
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)
|
if (process.HasExited)
|
||||||
throw new InvalidOperationException("Process ended too early, likely due to an incorrect sudo password.");
|
throw new InvalidOperationException("Process ended too early, likely due to an incorrect sudo password.");
|
||||||
|
|
Loading…
Reference in New Issue