diff --git a/internal/conpty/conpty.go b/internal/conpty/conpty.go index 114b44ad11..179c74389d 100644 --- a/internal/conpty/conpty.go +++ b/internal/conpty/conpty.go @@ -16,8 +16,8 @@ var ( errNotInitialized = errors.New("pseudo console hasn't been initialized") ) -// ConPTY is a wrapper around a Windows PseudoConsole handle. Create a new instance by calling `Create()`. -type ConPTY struct { +// Pty is a wrapper around a Windows PseudoConsole handle. Create a new instance by calling `Create()`. +type Pty struct { // handleLock guards hpc handleLock sync.RWMutex // hpc is the pseudo console handle @@ -27,8 +27,8 @@ type ConPTY struct { outPipe *os.File } -// Create returns a new `ConPTY` object. This object is not ready for IO until `UpdateProcThreadAttribute` is called and a process has been started. -func Create(width, height int16, flags uint32) (*ConPTY, error) { +// Create returns a new `Pty` object. This object is not ready for IO until `UpdateProcThreadAttribute` is called and a process has been started. +func Create(width, height int16, flags uint32) (*Pty, error) { // First we need to make both ends of the conpty's pipes, two to get passed into a process to use as input/output, and two for us to keep to // make use of this data. ptyIn, inPipeOurs, err := os.Pipe() @@ -49,7 +49,7 @@ func Create(width, height int16, flags uint32) (*ConPTY, error) { } // The pty's end of its pipes can be closed here without worry. They're duped into the conhost - // that will be launched and will be released on a call to ClosePseudoConsole() (Close() on the ConPTY object). + // that will be launched and will be released on a call to ClosePseudoConsole() (Close() on the Pty object). if err := ptyOut.Close(); err != nil { return nil, fmt.Errorf("failed to close pseudo console handle: %w", err) } @@ -57,7 +57,7 @@ func Create(width, height int16, flags uint32) (*ConPTY, error) { return nil, fmt.Errorf("failed to close pseudo console handle: %w", err) } - return &ConPTY{ + return &Pty{ hpc: hpc, inPipe: inPipeOurs, outPipe: outPipeOurs, @@ -66,7 +66,7 @@ func Create(width, height int16, flags uint32) (*ConPTY, error) { // UpdateProcThreadAttribute updates the passed in attribute list to contain the entry necessary for use with // CreateProcess. -func (c *ConPTY) UpdateProcThreadAttribute(attrList *windows.ProcThreadAttributeListContainer) error { +func (c *Pty) UpdateProcThreadAttribute(attrList *windows.ProcThreadAttributeListContainer) error { c.handleLock.RLock() defer c.handleLock.RUnlock() @@ -86,7 +86,7 @@ func (c *ConPTY) UpdateProcThreadAttribute(attrList *windows.ProcThreadAttribute } // Resize resizes the internal buffers of the pseudo console to the passed in size -func (c *ConPTY) Resize(width, height int16) error { +func (c *Pty) Resize(width, height int16) error { c.handleLock.RLock() defer c.handleLock.RUnlock() @@ -102,7 +102,7 @@ func (c *ConPTY) Resize(width, height int16) error { } // Close closes the pseudo-terminal and cleans up all attached resources -func (c *ConPTY) Close() error { +func (c *Pty) Close() error { c.handleLock.Lock() defer c.handleLock.Unlock() @@ -123,17 +123,17 @@ func (c *ConPTY) Close() error { } // OutPipe returns the output pipe of the pseudo console. -func (c *ConPTY) OutPipe() *os.File { +func (c *Pty) OutPipe() *os.File { return c.outPipe } // InPipe returns the input pipe of the pseudo console. -func (c *ConPTY) InPipe() *os.File { +func (c *Pty) InPipe() *os.File { return c.inPipe } // Write writes the contents of `buf` to the pseudo console. Returns the number of bytes written and an error if there is one. -func (c *ConPTY) Write(buf []byte) (int, error) { +func (c *Pty) Write(buf []byte) (int, error) { if c.inPipe == nil { return 0, errNotInitialized } @@ -141,7 +141,7 @@ func (c *ConPTY) Write(buf []byte) (int, error) { } // Read reads from the pseudo console into `buf`. Returns the number of bytes read and an error if there is one. -func (c *ConPTY) Read(buf []byte) (int, error) { +func (c *Pty) Read(buf []byte) (int, error) { if c.outPipe == nil { return 0, errNotInitialized } diff --git a/internal/exec/options.go b/internal/exec/options.go index 1811f65a91..0039125f66 100644 --- a/internal/exec/options.go +++ b/internal/exec/options.go @@ -14,7 +14,7 @@ type execConfig struct { stdout, stderr, stdin bool job *jobobject.JobObject - cpty *conpty.ConPTY + cpty *conpty.Pty token windows.Token processFlags uint32 } @@ -55,7 +55,7 @@ func WithJobObject(job *jobobject.JobObject) ExecOpts { } // WithConPty will launch the created process with a pseudo console attached to the process. -func WithConPty(cpty *conpty.ConPTY) ExecOpts { +func WithConPty(cpty *conpty.Pty) ExecOpts { return func(e *execConfig) error { e.cpty = cpty return nil diff --git a/internal/jobcontainers/jobcontainer.go b/internal/jobcontainers/jobcontainer.go index b6cfa251a7..2b9343fb4a 100644 --- a/internal/jobcontainers/jobcontainer.go +++ b/internal/jobcontainers/jobcontainer.go @@ -245,7 +245,7 @@ func (c *JobContainer) CreateProcess(ctx context.Context, config interface{}) (_ return nil, errors.Wrap(err, "failed to set PATHEXT") } - var cpty *conpty.ConPTY + var cpty *conpty.Pty if conf.EmulateConsole { cpty, err = conpty.Create(80, 20, 0) if err != nil { diff --git a/internal/jobcontainers/process.go b/internal/jobcontainers/process.go index d91245947d..b38e226111 100644 --- a/internal/jobcontainers/process.go +++ b/internal/jobcontainers/process.go @@ -20,7 +20,7 @@ import ( // JobProcess represents a process run in a job object. type JobProcess struct { cmd *exec.Exec - cpty *conpty.ConPTY + cpty *conpty.Pty procLock sync.Mutex stdioLock sync.Mutex stdin io.WriteCloser @@ -41,7 +41,7 @@ var sigMap = map[string]int{ var _ cow.Process = &JobProcess{} -func newProcess(cmd *exec.Exec, cpty *conpty.ConPTY) *JobProcess { +func newProcess(cmd *exec.Exec, cpty *conpty.Pty) *JobProcess { return &JobProcess{ cmd: cmd, cpty: cpty,