process_unix.go 645 B

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