github.com/undoio/delve@v1.9.0/pkg/proc/native/proc_unix.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package native
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"os/exec"
    10  
    11  	isatty "github.com/mattn/go-isatty"
    12  )
    13  
    14  func attachProcessToTTY(process *exec.Cmd, tty string) (*os.File, error) {
    15  	f, err := os.OpenFile(tty, os.O_RDWR, 0)
    16  	if err != nil {
    17  		return nil, err
    18  	}
    19  	if !isatty.IsTerminal(f.Fd()) {
    20  		f.Close()
    21  		return nil, fmt.Errorf("%s is not a terminal", f.Name())
    22  	}
    23  	process.Stdin = f
    24  	process.Stdout = f
    25  	process.Stderr = f
    26  	process.SysProcAttr.Setpgid = false
    27  	process.SysProcAttr.Setsid = true
    28  	process.SysProcAttr.Setctty = true
    29  
    30  	return f, nil
    31  }