2022-05-24 23:15:02 +00:00
|
|
|
// +build darwin linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2023-02-19 19:13:52 +00:00
|
|
|
rt "github.com/arnodel/golua/runtime"
|
2022-05-24 23:15:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (j *job) foreground() error {
|
|
|
|
if jobs.foreground {
|
|
|
|
return errors.New("(another) job already foregrounded")
|
|
|
|
}
|
|
|
|
|
|
|
|
pgid, _ := syscall.Getpgid(j.pid)
|
|
|
|
// tcsetpgrp
|
|
|
|
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, pgid)
|
|
|
|
proc, _ := os.FindProcess(j.pid)
|
|
|
|
proc.Wait()
|
|
|
|
|
|
|
|
hshPgid, _ := syscall.Getpgid(os.Getpid())
|
|
|
|
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, hshPgid)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *job) background() error {
|
|
|
|
proc := j.handle.Process
|
|
|
|
if proc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
proc.Signal(syscall.SIGCONT)
|
|
|
|
return nil
|
|
|
|
}
|
2023-02-19 19:13:52 +00:00
|
|
|
|
|
|
|
func (j *job) suspend() error {
|
|
|
|
proc := j.handle.Process
|
|
|
|
if proc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
proc.Signal(syscall.SIGSTOP)
|
|
|
|
hooks.Emit("job.suspend", rt.UserDataValue(j.ud))
|
|
|
|
return nil
|
|
|
|
}
|