Skip to content

Commit

Permalink
cleanup some unused fields
Browse files Browse the repository at this point in the history
  • Loading branch information
photostorm committed Oct 26, 2022
1 parent 82ad622 commit 0a71ca4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
12 changes: 5 additions & 7 deletions cmd_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ 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")

func (c *windowExecCmd) close() error {
c.attrList.Delete()
_ = c.conPty.Close()
_ = c.tty.Close()

return nil
}

Expand Down
8 changes: 0 additions & 8 deletions pty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 6 additions & 10 deletions run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ 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
}

defer func() {
// unlike unix command exec, do not close tty unless error happened
if err != nil {
_ = tty.Close()
_ = pty.Close()
}
}()
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 0a71ca4

Please sign in to comment.