2021-10-01 13:59:55 +00:00
|
|
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
2019-04-28 21:30:10 +00:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
|
|
|
|
|
|
package executor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
|
2022-01-13 18:22:49 +00:00
|
|
|
"github.com/creack/pty"
|
2019-04-28 21:30:10 +00:00
|
|
|
"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())
|
|
|
|
}
|