cleanup some unused fields

This commit is contained in:
photostorm
2022-10-25 21:23:44 -04:00
parent 82ad6226c1
commit 0a71ca4f0f
3 changed files with 11 additions and 25 deletions

View File

@@ -28,12 +28,10 @@ import (
// A cmd cannot be reused after calling its Run, Output or CombinedOutput
// methods.
type windowExecCmd struct {
cmd *exec.Cmd
waitCalled bool
consoleHandle syscall.Handle
tty *WindowsTty
conPty *WindowsPty
attrList *windows.ProcThreadAttributeListContainer
cmd *exec.Cmd
waitCalled bool
conPty *WindowsPty
attrList *windows.ProcThreadAttributeListContainer
}
var errProcessNotStarted = errors.New("exec: process has not started yet")
@@ -41,7 +39,7 @@ var errProcessNotStarted = errors.New("exec: process has not started yet")
func (c *windowExecCmd) close() error {
c.attrList.Delete()
_ = c.conPty.Close()
_ = c.tty.Close()
return nil
}

View File

@@ -109,14 +109,6 @@ func (p *WindowsPty) WriteString(s string) (int, error) {
return p.w.WriteString(s)
}
func (p *WindowsPty) InputPipe() *os.File {
return p.w
}
func (p *WindowsPty) OutputPipe() *os.File {
return p.r
}
func (p *WindowsPty) UpdateProcThreadAttribute(attrList *windows.ProcThreadAttributeListContainer) error {
var err error

View File

@@ -33,8 +33,8 @@ func StartWithSize(c *exec.Cmd, sz *Winsize) (Pty, error) {
//
// This should generally not be needed. Used in some edge cases where it is needed to create a pty
// without a controlling terminal.
func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (_ Pty, err error) {
pty, tty, err := open()
func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (Pty, error) {
pty, _, err := open()
if err != nil {
return nil, err
}
@@ -42,7 +42,6 @@ func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (_ Pty
defer func() {
// unlike unix command exec, do not close tty unless error happened
if err != nil {
_ = tty.Close()
_ = pty.Close()
}
}()
@@ -60,16 +59,13 @@ func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (_ Pty
// do not use os/exec.Start since we need to append console handler to startup info
w := windowExecCmd{
cmd: c,
waitCalled: false,
consoleHandle: syscall.Handle(tty.Fd()),
tty: tty.(*WindowsTty),
conPty: pty.(*WindowsPty),
cmd: c,
waitCalled: false,
conPty: pty.(*WindowsPty),
}
err = w.Start()
if err != nil {
_ = tty.Close()
_ = pty.Close()
return nil, err
}
@@ -176,7 +172,7 @@ func (c *windowExecCmd) Start() error {
// Need EXTENDED_STARTUPINFO_PRESENT as we're making use of the attribute list field.
flags := sys.CreationFlags | uint32(windows.CREATE_UNICODE_ENVIRONMENT) | windows.EXTENDED_STARTUPINFO_PRESENT
c.attrList, err = windows.NewProcThreadAttributeList(3)
c.attrList, err = windows.NewProcThreadAttributeList(1)
if err != nil {
return fmt.Errorf("failed to initialize process thread attribute list: %w", err)
}