mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-11 23:40:28 -10:00
When falling back from a failed PTY start to a pipe execution, the command attributes are reset. Previously, resetExecCommandForPipeFallback set command.SysProcAttr = nil, which stripped custom settings like Windows CmdLine quoting. Update the fallback logic to restore the original SysProcAttr instance, and add TestStartExecProcessPTYFallbackPreservesSysProcAttr to cover.
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package tools
|
|
|
|
import (
|
|
"io"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
func startExecProcess(command *exec.Cmd, output *execOutputBuffer, ttyRequested bool) (io.WriteCloser, bool, func(), error) {
|
|
if ttyRequested {
|
|
origSysProcAttr := command.SysProcAttr
|
|
if stdin, cleanup, err := startPTYProcessFunc(command, output); err == nil {
|
|
return stdin, true, cleanup, nil
|
|
}
|
|
resetExecCommandForPipeFallback(command, origSysProcAttr)
|
|
}
|
|
return startPipeProcess(command, output)
|
|
}
|
|
|
|
var startPTYProcessFunc = startPTYProcess
|
|
|
|
func resetExecCommandForPipeFallback(command *exec.Cmd, origSysProcAttr *syscall.SysProcAttr) {
|
|
command.Stdin = nil
|
|
command.Stdout = nil
|
|
command.Stderr = nil
|
|
command.SysProcAttr = origSysProcAttr
|
|
command.Cancel = nil
|
|
command.WaitDelay = 0
|
|
}
|
|
|
|
func startPipeProcess(command *exec.Cmd, output *execOutputBuffer) (io.WriteCloser, bool, func(), error) {
|
|
stdin, err := command.StdinPipe()
|
|
if err != nil {
|
|
return nil, false, nil, err
|
|
}
|
|
command.Stdout = output
|
|
command.Stderr = output
|
|
hardenProcessLifetime(command)
|
|
if err := command.Start(); err != nil {
|
|
return nil, false, nil, err
|
|
}
|
|
return stdin, false, func() {}, nil
|
|
}
|