@@ -18,9 +18,7 @@ import (
1818 "io/ioutil"
1919 "log"
2020 "os"
21- "os/exec"
2221 "strings"
23- "syscall"
2422 "time"
2523)
2624
@@ -31,14 +29,7 @@ type localFunctionServer struct {
3129
3230func (l * localFunctionServer ) Start () (func (), error ) {
3331 args := strings .Fields (l .cmd )
34- cmd := exec .Command (args [0 ], args [1 :]... )
35-
36- // Set a process group ID so that later we can kill child processes too. As an
37- // example, if the command is `go run main.go`, Go will build a binary in a
38- // temp dir and then execute it. If we simply cmd.Process.Kill() the exec.Command
39- // then the running binary will not be killed. Only if we make a group and then
40- // kill the group will child processes be killed.
41- cmd .SysProcAttr = & syscall.SysProcAttr {Setpgid : true }
32+ cmd := newCmd (args )
4233
4334 stdout , err := os .Create (stdoutFile )
4435 if err != nil {
@@ -64,19 +55,8 @@ func (l *localFunctionServer) Start() (func(), error) {
6455 stdout .Close ()
6556 stderr .Close ()
6657
67- pgid , err := syscall .Getpgid (cmd .Process .Pid )
68- if err != nil {
69- log .Printf ("Failed to get pgid: %v" , err )
70-
71- // Kill just the parent process since we failed to get the process group ID.
72- if err := cmd .Process .Kill (); err != nil {
73- log .Fatalf ("Failed to kill process: %v" , err )
74- }
75- } else {
76- // Kill the whole process group.
77- if err := syscall .Kill (- pgid , syscall .SIGKILL ); err != nil {
78- log .Fatalf ("Failed to kill process group: %v" , err )
79- }
58+ if err := stopCmd (cmd ); err != nil {
59+ log .Fatalf ("Failed to shut down framework server: %v" , err )
8060 }
8161
8262 log .Printf ("Framework server shut down. Wrote logs to %v and %v." , stdoutFile , stderrFile )
0 commit comments