mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 01:53:42 +08:00 
			
		
		
		
	vendor: github.com/containerd/console 8f6c4e4
full diff: https://github.com/containerd/console/compare/v1.0.3...8f6c4e4faef5a326d2cd907097d04c0239ee5e2f Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										14
									
								
								vendor/github.com/containerd/console/.golangci.yml
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								vendor/github.com/containerd/console/.golangci.yml
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,16 +1,16 @@
 | 
			
		||||
linters:
 | 
			
		||||
  enable:
 | 
			
		||||
    - structcheck
 | 
			
		||||
    - varcheck
 | 
			
		||||
    - staticcheck
 | 
			
		||||
    - unconvert
 | 
			
		||||
    - gofmt
 | 
			
		||||
    - goimports
 | 
			
		||||
    - golint
 | 
			
		||||
    - ineffassign
 | 
			
		||||
    - vet
 | 
			
		||||
    - unused
 | 
			
		||||
    - misspell
 | 
			
		||||
    - revive
 | 
			
		||||
    - staticcheck
 | 
			
		||||
    - structcheck
 | 
			
		||||
    - unconvert
 | 
			
		||||
    - unused
 | 
			
		||||
    - varcheck
 | 
			
		||||
    - vet
 | 
			
		||||
  disable:
 | 
			
		||||
    - errcheck
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								vendor/github.com/containerd/console/README.md
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								vendor/github.com/containerd/console/README.md
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -22,8 +22,8 @@ current.Resize(ws)
 | 
			
		||||
 | 
			
		||||
console is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE).
 | 
			
		||||
As a containerd sub-project, you will find the:
 | 
			
		||||
 * [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md),
 | 
			
		||||
 * [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS),
 | 
			
		||||
 * and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md)
 | 
			
		||||
 * [Project governance](https://github.com/containerd/project/blob/main/GOVERNANCE.md),
 | 
			
		||||
 * [Maintainers](https://github.com/containerd/project/blob/main/MAINTAINERS),
 | 
			
		||||
 * and [Contributing guidelines](https://github.com/containerd/project/blob/main/CONTRIBUTING.md)
 | 
			
		||||
 | 
			
		||||
information in our [`containerd/project`](https://github.com/containerd/project) repository.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								vendor/github.com/containerd/console/console.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/containerd/console/console.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -22,7 +22,10 @@ import (
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var ErrNotAConsole = errors.New("provided file is not a console")
 | 
			
		||||
var (
 | 
			
		||||
	ErrNotAConsole    = errors.New("provided file is not a console")
 | 
			
		||||
	ErrNotImplemented = errors.New("not implemented")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type File interface {
 | 
			
		||||
	io.ReadWriteCloser
 | 
			
		||||
@@ -45,7 +48,7 @@ type Console interface {
 | 
			
		||||
	SetRaw() error
 | 
			
		||||
	// DisableEcho disables echo on the console
 | 
			
		||||
	DisableEcho() error
 | 
			
		||||
	// Reset restores the console to its orignal state
 | 
			
		||||
	// Reset restores the console to its original state
 | 
			
		||||
	Reset() error
 | 
			
		||||
	// Size returns the window size of the console
 | 
			
		||||
	Size() (WinSize, error)
 | 
			
		||||
@@ -78,7 +81,7 @@ func Current() (c Console) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ConsoleFromFile returns a console using the provided file
 | 
			
		||||
// nolint:golint
 | 
			
		||||
// nolint:revive
 | 
			
		||||
func ConsoleFromFile(f File) (Console, error) {
 | 
			
		||||
	if err := checkConsole(f); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								vendor/github.com/containerd/console/console_linux.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/containerd/console/console_linux.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
//go:build linux
 | 
			
		||||
// +build linux
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								vendor/github.com/containerd/console/console_other.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								vendor/github.com/containerd/console/console_other.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
//go:build !darwin && !freebsd && !linux && !netbsd && !openbsd && !solaris && !windows && !zos
 | 
			
		||||
// +build !darwin,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows,!zos
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package console
 | 
			
		||||
 | 
			
		||||
// NewPty creates a new pty pair
 | 
			
		||||
// The master is returned as the first console and a string
 | 
			
		||||
// with the path to the pty slave is returned as the second
 | 
			
		||||
func NewPty() (Console, string, error) {
 | 
			
		||||
	return nil, "", ErrNotImplemented
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// checkConsole checks if the provided file is a console
 | 
			
		||||
func checkConsole(f File) error {
 | 
			
		||||
	return ErrNotAConsole
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMaster(f File) (Console, error) {
 | 
			
		||||
	return nil, ErrNotImplemented
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								vendor/github.com/containerd/console/console_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								vendor/github.com/containerd/console/console_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,5 @@
 | 
			
		||||
// +build darwin freebsd linux netbsd openbsd solaris
 | 
			
		||||
//go:build darwin || freebsd || linux || netbsd || openbsd || zos
 | 
			
		||||
// +build darwin freebsd linux netbsd openbsd zos
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										25
									
								
								vendor/github.com/containerd/console/console_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										25
									
								
								vendor/github.com/containerd/console/console_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -24,12 +24,13 @@ import (
 | 
			
		||||
	"golang.org/x/sys/windows"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	vtInputSupported  bool
 | 
			
		||||
	ErrNotImplemented = errors.New("not implemented")
 | 
			
		||||
)
 | 
			
		||||
var vtInputSupported bool
 | 
			
		||||
 | 
			
		||||
func (m *master) initStdios() {
 | 
			
		||||
	// Note: We discard console mode warnings, because in/out can be redirected.
 | 
			
		||||
	//
 | 
			
		||||
	// TODO: Investigate opening CONOUT$/CONIN$ to handle this correctly
 | 
			
		||||
 | 
			
		||||
	m.in = windows.Handle(os.Stdin.Fd())
 | 
			
		||||
	if err := windows.GetConsoleMode(m.in, &m.inMode); err == nil {
 | 
			
		||||
		// Validate that windows.ENABLE_VIRTUAL_TERMINAL_INPUT is supported, but do not set it.
 | 
			
		||||
@@ -39,8 +40,6 @@ func (m *master) initStdios() {
 | 
			
		||||
		// Unconditionally set the console mode back even on failure because SetConsoleMode
 | 
			
		||||
		// remembers invalid bits on input handles.
 | 
			
		||||
		windows.SetConsoleMode(m.in, m.inMode)
 | 
			
		||||
	} else {
 | 
			
		||||
		fmt.Printf("failed to get console mode for stdin: %v\n", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	m.out = windows.Handle(os.Stdout.Fd())
 | 
			
		||||
@@ -50,8 +49,6 @@ func (m *master) initStdios() {
 | 
			
		||||
		} else {
 | 
			
		||||
			windows.SetConsoleMode(m.out, m.outMode)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		fmt.Printf("failed to get console mode for stdout: %v\n", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	m.err = windows.Handle(os.Stderr.Fd())
 | 
			
		||||
@@ -61,8 +58,6 @@ func (m *master) initStdios() {
 | 
			
		||||
		} else {
 | 
			
		||||
			windows.SetConsoleMode(m.err, m.errMode)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		fmt.Printf("failed to get console mode for stderr: %v\n", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -94,6 +89,8 @@ func (m *master) SetRaw() error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Reset() error {
 | 
			
		||||
	var errs []error
 | 
			
		||||
 | 
			
		||||
	for _, s := range []struct {
 | 
			
		||||
		fd   windows.Handle
 | 
			
		||||
		mode uint32
 | 
			
		||||
@@ -103,10 +100,16 @@ func (m *master) Reset() error {
 | 
			
		||||
		{m.err, m.errMode},
 | 
			
		||||
	} {
 | 
			
		||||
		if err := windows.SetConsoleMode(s.fd, s.mode); err != nil {
 | 
			
		||||
			return fmt.Errorf("unable to restore console mode: %w", err)
 | 
			
		||||
			// we can't just abort on the first error, otherwise we might leave
 | 
			
		||||
			// the console in an unexpected state.
 | 
			
		||||
			errs = append(errs, fmt.Errorf("unable to restore console mode: %w", err))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(errs) > 0 {
 | 
			
		||||
		return errs[0]
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										163
									
								
								vendor/github.com/containerd/console/console_zos.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										163
									
								
								vendor/github.com/containerd/console/console_zos.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,163 +0,0 @@
 | 
			
		||||
// +build zos
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package console
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NewPty creates a new pty pair
 | 
			
		||||
// The master is returned as the first console and a string
 | 
			
		||||
// with the path to the pty slave is returned as the second
 | 
			
		||||
func NewPty() (Console, string, error) {
 | 
			
		||||
	var f File
 | 
			
		||||
	var err error
 | 
			
		||||
	var slave string
 | 
			
		||||
	for i := 0;; i++ {
 | 
			
		||||
		ptyp := fmt.Sprintf("/dev/ptyp%04d", i)
 | 
			
		||||
		f, err = os.OpenFile(ptyp, os.O_RDWR, 0600)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			slave = fmt.Sprintf("/dev/ttyp%04d", i)
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
		if os.IsNotExist(err) {
 | 
			
		||||
			return nil, "", err
 | 
			
		||||
		}
 | 
			
		||||
		// else probably Resource Busy
 | 
			
		||||
	}
 | 
			
		||||
	m, err := newMaster(f)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, "", err
 | 
			
		||||
	}
 | 
			
		||||
	return m, slave, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type master struct {
 | 
			
		||||
	f        File
 | 
			
		||||
	original *unix.Termios
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Read(b []byte) (int, error) {
 | 
			
		||||
	return m.f.Read(b)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Write(b []byte) (int, error) {
 | 
			
		||||
	return m.f.Write(b)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Close() error {
 | 
			
		||||
	return m.f.Close()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Resize(ws WinSize) error {
 | 
			
		||||
	return tcswinsz(m.f.Fd(), ws)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) ResizeFrom(c Console) error {
 | 
			
		||||
	ws, err := c.Size()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return m.Resize(ws)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Reset() error {
 | 
			
		||||
	if m.original == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return tcset(m.f.Fd(), m.original)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) getCurrent() (unix.Termios, error) {
 | 
			
		||||
	var termios unix.Termios
 | 
			
		||||
	if err := tcget(m.f.Fd(), &termios); err != nil {
 | 
			
		||||
		return unix.Termios{}, err
 | 
			
		||||
	}
 | 
			
		||||
	return termios, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) SetRaw() error {
 | 
			
		||||
	rawState, err := m.getCurrent()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	rawState = cfmakeraw(rawState)
 | 
			
		||||
	rawState.Oflag = rawState.Oflag | unix.OPOST
 | 
			
		||||
	return tcset(m.f.Fd(), &rawState)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) DisableEcho() error {
 | 
			
		||||
	rawState, err := m.getCurrent()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	rawState.Lflag = rawState.Lflag &^ unix.ECHO
 | 
			
		||||
	return tcset(m.f.Fd(), &rawState)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Size() (WinSize, error) {
 | 
			
		||||
	return tcgwinsz(m.f.Fd())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Fd() uintptr {
 | 
			
		||||
	return m.f.Fd()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *master) Name() string {
 | 
			
		||||
	return m.f.Name()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// checkConsole checks if the provided file is a console
 | 
			
		||||
func checkConsole(f File) error {
 | 
			
		||||
	var termios unix.Termios
 | 
			
		||||
	if tcget(f.Fd(), &termios) != nil {
 | 
			
		||||
		return ErrNotAConsole
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMaster(f File) (Console, error) {
 | 
			
		||||
	m := &master{
 | 
			
		||||
		f: f,
 | 
			
		||||
	}
 | 
			
		||||
	t, err := m.getCurrent()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	m.original = &t
 | 
			
		||||
	return m, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ClearONLCR sets the necessary tty_ioctl(4)s to ensure that a pty pair
 | 
			
		||||
// created by us acts normally. In particular, a not-very-well-known default of
 | 
			
		||||
// Linux unix98 ptys is that they have +onlcr by default. While this isn't a
 | 
			
		||||
// problem for terminal emulators, because we relay data from the terminal we
 | 
			
		||||
// also relay that funky line discipline.
 | 
			
		||||
func ClearONLCR(fd uintptr) error {
 | 
			
		||||
	return setONLCR(fd, false)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetONLCR sets the necessary tty_ioctl(4)s to ensure that a pty pair
 | 
			
		||||
// created by us acts as intended for a terminal emulator.
 | 
			
		||||
func SetONLCR(fd uintptr) error {
 | 
			
		||||
	return setONLCR(fd, true)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								vendor/github.com/containerd/console/pty_freebsd_cgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/containerd/console/pty_freebsd_cgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
//go:build freebsd && cgo
 | 
			
		||||
// +build freebsd,cgo
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								vendor/github.com/containerd/console/pty_freebsd_nocgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/containerd/console/pty_freebsd_nocgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
//go:build freebsd && !cgo
 | 
			
		||||
// +build freebsd,!cgo
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								vendor/github.com/containerd/console/pty_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								vendor/github.com/containerd/console/pty_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,5 @@
 | 
			
		||||
// +build darwin linux netbsd openbsd solaris
 | 
			
		||||
//go:build darwin || linux || netbsd || openbsd
 | 
			
		||||
// +build darwin linux netbsd openbsd
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										43
									
								
								vendor/github.com/containerd/console/pty_zos.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								vendor/github.com/containerd/console/pty_zos.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
//go:build zos
 | 
			
		||||
// +build zos
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package console
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// openpt allocates a new pseudo-terminal by opening the first available /dev/ptypXX device
 | 
			
		||||
func openpt() (*os.File, error) {
 | 
			
		||||
	var f *os.File
 | 
			
		||||
	var err error
 | 
			
		||||
	for i := 0; ; i++ {
 | 
			
		||||
		ptyp := fmt.Sprintf("/dev/ptyp%04d", i)
 | 
			
		||||
		f, err = os.OpenFile(ptyp, os.O_RDWR, 0600)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
		if os.IsNotExist(err) {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		// else probably Resource Busy
 | 
			
		||||
	}
 | 
			
		||||
	return f, nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								vendor/github.com/containerd/console/tc_freebsd_cgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/containerd/console/tc_freebsd_cgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
//go:build freebsd && cgo
 | 
			
		||||
// +build freebsd,cgo
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								vendor/github.com/containerd/console/tc_freebsd_nocgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/containerd/console/tc_freebsd_nocgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
//go:build freebsd && !cgo
 | 
			
		||||
// +build freebsd,!cgo
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								vendor/github.com/containerd/console/tc_openbsd_cgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/containerd/console/tc_openbsd_cgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
//go:build openbsd && cgo
 | 
			
		||||
// +build openbsd,cgo
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								vendor/github.com/containerd/console/tc_openbsd_nocgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/containerd/console/tc_openbsd_nocgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
//go:build openbsd && !cgo
 | 
			
		||||
// +build openbsd,!cgo
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										51
									
								
								vendor/github.com/containerd/console/tc_solaris_cgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										51
									
								
								vendor/github.com/containerd/console/tc_solaris_cgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,51 +0,0 @@
 | 
			
		||||
// +build solaris,cgo
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package console
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
//#include <stdlib.h>
 | 
			
		||||
import "C"
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	cmdTcGet = unix.TCGETS
 | 
			
		||||
	cmdTcSet = unix.TCSETS
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ptsname retrieves the name of the first available pts for the given master.
 | 
			
		||||
func ptsname(f *os.File) (string, error) {
 | 
			
		||||
	ptspath, err := C.ptsname(C.int(f.Fd()))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
	return C.GoString(ptspath), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
 | 
			
		||||
// unlockpt should be called before opening the slave side of a pty.
 | 
			
		||||
func unlockpt(f *os.File) error {
 | 
			
		||||
	if _, err := C.grantpt(C.int(f.Fd())); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										47
									
								
								vendor/github.com/containerd/console/tc_solaris_nocgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										47
									
								
								vendor/github.com/containerd/console/tc_solaris_nocgo.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,47 +0,0 @@
 | 
			
		||||
// +build solaris,!cgo
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Implementing the functions below requires cgo support.  Non-cgo stubs
 | 
			
		||||
// versions are defined below to enable cross-compilation of source code
 | 
			
		||||
// that depends on these functions, but the resultant cross-compiled
 | 
			
		||||
// binaries cannot actually be used.  If the stub function(s) below are
 | 
			
		||||
// actually invoked they will display an error message and cause the
 | 
			
		||||
// calling process to exit.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
package console
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	cmdTcGet = unix.TCGETS
 | 
			
		||||
	cmdTcSet = unix.TCSETS
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func ptsname(f *os.File) (string, error) {
 | 
			
		||||
	panic("ptsname() support requires cgo.")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func unlockpt(f *os.File) error {
 | 
			
		||||
	panic("unlockpt() support requires cgo.")
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								vendor/github.com/containerd/console/tc_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								vendor/github.com/containerd/console/tc_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,5 @@
 | 
			
		||||
// +build darwin freebsd linux netbsd openbsd solaris zos
 | 
			
		||||
//go:build darwin || freebsd || linux || netbsd || openbsd || zos
 | 
			
		||||
// +build darwin freebsd linux netbsd openbsd zos
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
@@ -83,7 +84,7 @@ func cfmakeraw(t unix.Termios) unix.Termios {
 | 
			
		||||
	t.Oflag &^= unix.OPOST
 | 
			
		||||
	t.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
 | 
			
		||||
	t.Cflag &^= (unix.CSIZE | unix.PARENB)
 | 
			
		||||
	t.Cflag &^= unix.CS8
 | 
			
		||||
	t.Cflag |= unix.CS8
 | 
			
		||||
	t.Cc[unix.VMIN] = 1
 | 
			
		||||
	t.Cc[unix.VTIME] = 0
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								vendor/github.com/containerd/console/tc_zos.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								vendor/github.com/containerd/console/tc_zos.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -17,6 +17,9 @@
 | 
			
		||||
package console
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -24,3 +27,13 @@ const (
 | 
			
		||||
	cmdTcGet = unix.TCGETS
 | 
			
		||||
	cmdTcSet = unix.TCSETS
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// unlockpt is a no-op on zos.
 | 
			
		||||
func unlockpt(_ *os.File) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ptsname retrieves the name of the first available pts for the given master.
 | 
			
		||||
func ptsname(f *os.File) (string, error) {
 | 
			
		||||
	return "/dev/ttyp" + strings.TrimPrefix(f.Name(), "/dev/ptyp"), nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user