build: split os syscall

feat/muzan
Evan Chen 2021-11-15 09:59:10 +08:00
parent f039033077
commit 556f673b3e
3 changed files with 38 additions and 13 deletions

View File

@ -77,7 +77,7 @@ func (oni *Oni) Start() error {
} }
var err error var err error
cmd := exec.Command(oni.Cmd, oni.Args...) cmd := exec.Command(oni.Cmd, oni.Args...)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} setgpid(cmd)
cmd.Env = oni.Envs cmd.Env = oni.Envs
cmd.Dir = oni.Dir cmd.Dir = oni.Dir
var out io.Writer var out io.Writer
@ -111,18 +111,6 @@ func (oni *Oni) Stop() error {
return oni.cmd.Process.Signal(syscall.SIGTERM) return oni.cmd.Process.Signal(syscall.SIGTERM)
} }
func (oni *Oni) Kill() error {
if oni.cmd == nil {
return nil
}
pgid, err := syscall.Getpgid(oni.cmd.Process.Pid)
if err == nil {
return syscall.Kill(-pgid, 15) // note the minus sign
}
return oni.cmd.Process.Kill()
// return oni.cmd.Process.Kill()
}
func (oni *Oni) end(v interface{}) { func (oni *Oni) end(v interface{}) {
if v == nil { if v == nil {
oni.StateChange(ENDED) oni.StateChange(ENDED)

24
muzanctl.go Normal file
View File

@ -0,0 +1,24 @@
//go:build !windows
// +build !windows
package configui
import (
"os/exec"
"syscall"
)
func setgpid(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}
func (oni *Oni) Kill() error {
if oni.cmd == nil {
return nil
}
pgid, err := syscall.Getpgid(oni.cmd.Process.Pid)
if err == nil {
return syscall.Kill(-pgid, 15) // note the minus sign
}
return oni.cmd.Process.Kill()
}

13
muzanctrl_windows.go Normal file
View File

@ -0,0 +1,13 @@
package configui
import "os/exec"
func setgpid(cmd *exec.Cmd) {
}
func (oni *Oni) Kill() error {
if oni.cmd == nil {
return nil
}
return oni.cmd.Process.Kill()
}