aboutsummaryrefslogtreecommitdiff
path: root/executor/pty_unix.go
blob: 2df23e3d83fc032600242adb0b4132fdae85de02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//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())
}