Skip to content

Commit

Permalink
#863 job-control: rewrite working on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorg committed Sep 13, 2024
1 parent fd2e0e8 commit b268545
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const Name = "murex"
const (
Major = 6
Minor = 3
Revision = 4104
Revision = 4123
Branch = "develop"
BuildDate = "2024-09-13 22:00:01"
BuildDate = "2024-09-13 23:21:21"
)

// Copyright is the copyright owner string
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func main() {
runCommandString(fCommand)

case fExecute:
executeAs(flag.Args())
//executeAs(flag.Args())
runCommandString(argvToCmdLineStr(flag.Args()))

case len(fSource) > 0:
runSource(fSource[0])
Expand Down Expand Up @@ -118,7 +119,7 @@ func runCommandString(commandString string) {
}
}

func executeAs(argv []string) {
/*func executeAs(argv []string) {
lang.InitEnv()
// default config
Expand Down Expand Up @@ -153,7 +154,7 @@ func executeAs(argv []string) {
}
lang.Exit(lang.ShellProcess.ExitNum)
}
}*/

func runSource(filename string) {
lang.InitEnv()
Expand Down
68 changes: 53 additions & 15 deletions shell/signal_handler/sigfns/sigfns_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/lmorg/murex/lang/state"
"github.com/lmorg/murex/lang/types"
"github.com/lmorg/murex/utils/humannumbers"
"golang.org/x/sys/unix"
)

func Sigtstp(_ bool) {
Expand Down Expand Up @@ -52,20 +53,47 @@ func Sigchld(interactive bool) {
}

p := lang.ForegroundProc.Get()
if p.Id == lang.ShellProcess.Id {
/*if p.Id == lang.ShellProcess.Id {
// Child already exited so we can ignore this signal
return
}*/

pid := p.SystemProcess.Pid()
if pid == -1 {
// Not a system process
return
}

var (
status syscall.WaitStatus
pid = p.SystemProcess.Pid()
)
SigchldDarwin(p, pid)
/*if runtime.GOOS == "linux" {
SigchldLinux(p, pid)
return
}
if pid == -1 {
SigchildBsd(p, pid)*/
}

func SigchldLinux(p *lang.Process, pid int) {
var status syscall.WaitStatus

wpid, err := syscall.Wait4(pid, &status, syscall.WNOHANG|syscall.WUNTRACED, nil)
if err != nil {
debug.Logf("!!! error in syscall.Wait4(pid: %d, &status, syscall.WNOHANG|syscall.WUNTRACED, nil):\n!!! %v",
pid, err)
}

if wpid == 0 {
return
}

if status.Stopped() {
returnFromSigtstp(p)
}
}

func SigchldDarwin(p *lang.Process, pid int) {
var status syscall.WaitStatus

wpid, err := syscall.Wait4(pid, &status, syscall.WNOHANG|syscall.WUNTRACED, nil)
if err != nil {
debug.Logf("!!! error in syscall.Wait4(pid: %d, &status, syscall.WNOHANG|syscall.WUNTRACED, nil):\n!!! %v",
Expand All @@ -78,18 +106,30 @@ func Sigchld(interactive bool) {

switch {
case status.Stopped():
//returnFromSigtstp(p)
case status.Continued():
returnFromSigtstp(p)
case status.Signaled():
//panic("sig")
case status.CoreDump():
//panic("dump")
case status.Exited():
//panic("exit")
default:
//panic("foobar")
}
}

/*if p.SystemProcess.State() == nil {
sid, err := unix.Getsid(p.SystemProcess.Pid())
func SigchildBsd(p *lang.Process, pid int) {
if p.SystemProcess.State() == nil {
sid, err := unix.Getsid(pid)
if err != nil {
debug.Logf("!!! Sigchld()->unix.Getsid(p.SystemProcess.Pid: %d) failed: %s", p.SystemProcess.Pid(), err.Error())
debug.Logf("!!! Sigchld()->unix.Getsid(p.SystemProcess.Pid: %d) failed: %s", pid, err.Error())
return
}

debug.Logf("!!! unix.Getsid(p.SystemProcess.Pid: %d) == %d", p.SystemProcess.Pid(), sid)
if sid != p.SystemProcess.Pid() {
debug.Logf("!!! unix.Getsid(p.SystemProcess.Pid: %d) == %d", pid, sid)
if sid != pid {
return
}

Expand All @@ -100,14 +140,12 @@ func Sigchld(interactive bool) {
return
}

if err = p.SystemProcess.Signal(syscall.Signal(0)); err != nil {
returnFromSigtstp(p)
}
returnFromSigtstp(p)

return
}

if p.SystemProcess.State().Sys().(syscall.WaitStatus).Exited() {
/*if p.SystemProcess.State().Sys().(syscall.WaitStatus).Exited() {
return // TODO: eventually we should have a clean up of old PIDs
}*/
}
Expand Down
2 changes: 1 addition & 1 deletion version.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b268545

Please sign in to comment.