github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/drivers/shared/executor/pty_unix.go (about)

     1  // +build darwin dragonfly freebsd linux netbsd openbsd solaris
     2  
     3  package executor
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  	"os"
     9  	"strings"
    10  	"syscall"
    11  
    12  	"github.com/kr/pty"
    13  	"golang.org/x/sys/unix"
    14  )
    15  
    16  func sessionCmdAttr(tty *os.File) *syscall.SysProcAttr {
    17  	return &syscall.SysProcAttr{
    18  		Setsid:  true,
    19  		Setctty: true,
    20  	}
    21  }
    22  
    23  func setTTYSize(w io.Writer, height, width int32) error {
    24  	f, ok := w.(*os.File)
    25  	if !ok {
    26  		return fmt.Errorf("attempted to resize a non-tty session")
    27  	}
    28  
    29  	return pty.Setsize(f, &pty.Winsize{
    30  		Rows: uint16(height),
    31  		Cols: uint16(width),
    32  	})
    33  
    34  }
    35  
    36  func isUnixEIOErr(err error) bool {
    37  	if err == nil {
    38  		return false
    39  	}
    40  
    41  	return strings.Contains(err.Error(), unix.EIO.Error())
    42  }