mirror of
https://github.com/wahyd4/forego.git
synced 2026-08-09 05:07:05 +10:00
This makes it so that the same goroutine responsible for starting processes shuts them down. This is a stepping stone to a larger refactor whose goal is to eliminate race conditions.
35 lines
653 B
Go
35 lines
653 B
Go
package main
|
|
|
|
// +build windows
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
func (p *Process) Start() {
|
|
command := []string{"cmd", "/C", p.Command}
|
|
p.cmd = exec.Command(command[0], command[1:]...)
|
|
p.cmd.Dir = p.Root
|
|
p.cmd.Env = p.envAsArray()
|
|
p.cmd.Stdin = p.Stdin
|
|
p.cmd.Stdout = p.Stdout
|
|
p.cmd.Stderr = p.Stderr
|
|
p.cmd.Start()
|
|
}
|
|
|
|
func (p *Process) Signal(signal syscall.Signal) {
|
|
group, _ := os.FindProcess(-1 * p.cmd.Process.Pid)
|
|
group.Signal(signal)
|
|
}
|
|
|
|
func ShutdownProcesses(of *OutletFactory) {
|
|
for name, ps := range processes {
|
|
of.SystemOutput(fmt.Sprintf("terminating %s", name))
|
|
ps.cmd.Process.Signal(os.Kill)
|
|
}
|
|
os.Exit(1)
|
|
}
|