open-nomad/drivers/shared/executor/pty_unix.go
Seth Hoenig f2a71fd0d9 deps: pty has new home
github.com/kr/pty was moved to github.com/creack/pty

Swap this dependency so we can upgrade to the latest version
and no longer need a replace directive.
2022-01-19 12:33:05 -06:00

44 lines
775 B
Go

//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package executor
import (
"fmt"
"io"
"os"
"strings"
"syscall"
"github.com/creack/pty"
"golang.org/x/sys/unix"
)
func sessionCmdAttr(tty *os.File) *syscall.SysProcAttr {
return &syscall.SysProcAttr{
Setsid: true,
Setctty: true,
}
}
func setTTYSize(w io.Writer, height, width int32) error {
f, ok := w.(*os.File)
if !ok {
return fmt.Errorf("attempted to resize a non-tty session")
}
return pty.Setsize(f, &pty.Winsize{
Rows: uint16(height),
Cols: uint16(width),
})
}
func isUnixEIOErr(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), unix.EIO.Error())
}