feat: attempt to implement fg builtin

fg-job
TorchedSammy 2022-05-24 17:24:08 -04:00
parent d65b574cb2
commit e6b1e260d8
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 21 additions and 0 deletions

20
exec.go
View File

@ -17,6 +17,7 @@ import (
"hilbish/util"
rt "github.com/arnodel/golua/runtime"
"golang.org/x/sys/unix"
"mvdan.cc/sh/v3/shell"
//"github.com/yuin/gopher-lua/parse"
"mvdan.cc/sh/v3/interp"
@ -273,6 +274,25 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
}
}
// sh interp has "fg" as unimplemented builtin, which panics
if args[0] == "fg" {
j := jobs.getLatest()
if j == nil || j.pid == 0 {
return interp.NewExitStatus(1)
}
pgid, _ := syscall.Getpgid(j.pid)
hshPgid, _ := syscall.Getpgid(os.Getpid())
// tcsetpgrp
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, pgid)
proc, _ := os.FindProcess(j.pid)
proc.Wait()
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, hshPgid)
return interp.NewExitStatus(0)
}
// If command is defined in Lua then run it
luacmdArgs := rt.NewTable()
for i, str := range args[1:] {

View File

@ -10,6 +10,7 @@ import (
func handleSignals() {
c := make(chan os.Signal)
signal.Ignore(syscall.SIGTTOU, syscall.SIGTTIN, syscall.SIGTSTP)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGWINCH, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGQUIT)
for s := range c {