github.com/hernad/nomad@v1.6.112/drivers/shared/executor/pty_unix.go (about)

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