Skip to content

Commit

Permalink
Change redundant conpty.ConPTY struct name (#1259)
Browse files Browse the repository at this point in the history
This change renames the ConPTY struct in the conpty package to
Pty.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
  • Loading branch information
dcantah committed Dec 30, 2021
1 parent 58caeed commit 3f2848a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions internal/conpty/conpty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -49,15 +49,15 @@ 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)
}
if err := ptyIn.Close(); err != nil {
return nil, fmt.Errorf("failed to close pseudo console handle: %w", err)
}

return &ConPTY{
return &Pty{
hpc: hpc,
inPipe: inPipeOurs,
outPipe: outPipeOurs,
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -123,25 +123,25 @@ 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
}
return c.inPipe.Write(buf)
}

// 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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/exec/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/jobcontainers/jobcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/jobcontainers/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 3f2848a

Please sign in to comment.