github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/eval/process_unix.go (about)

     1  // +build !windows,!plan9
     2  
     3  package eval
     4  
     5  import (
     6  	"os"
     7  	"os/signal"
     8  	"syscall"
     9  
    10  	"src.elv.sh/pkg/sys"
    11  )
    12  
    13  // Process control functions in Unix.
    14  
    15  func putSelfInFg() error {
    16  	if !sys.IsATTY(os.Stdin) {
    17  		return nil
    18  	}
    19  	// If Elvish is in the background, the tcsetpgrp call below will either fail
    20  	// (if the process is in an orphaned process group) or stop the process.
    21  	// Ignoring TTOU fixes that.
    22  	signal.Ignore(syscall.SIGTTOU)
    23  	defer signal.Reset(syscall.SIGTTOU)
    24  	return sys.Tcsetpgrp(0, syscall.Getpgrp())
    25  }
    26  
    27  func makeSysProcAttr(bg bool) *syscall.SysProcAttr {
    28  	return &syscall.SysProcAttr{Setpgid: bg}
    29  }