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