Do not ask to kill process we spawned

This commit is contained in:
Derek Parker 2015-07-07 09:04:03 -05:00
parent 05517c62c1
commit c1e7f8c45a
4 changed files with 27 additions and 6 deletions

@ -69,4 +69,7 @@ type Client interface {
// Returns stacktrace
Stacktrace(goroutineId, depth int) ([]api.Location, error)
// Returns whether we attached to a running process or not
AttachedToExistingProcess() bool
}

@ -205,6 +205,12 @@ func (c *RPCClient) Stacktrace(goroutineId, depth int) ([]api.Location, error) {
return locations, err
}
func (c *RPCClient) AttachedToExistingProcess() bool {
var answer bool
c.call("AttachedToRunningProcess", nil, &answer)
return answer
}
func (c *RPCClient) url(path string) string {
return fmt.Sprintf("http://%s%s", c.addr, path)
}

@ -302,3 +302,10 @@ func (s *RPCServer) ListGoroutines(arg interface{}, goroutines *[]*api.Goroutine
*goroutines = gs
return nil
}
func (c *RPCServer) AttachedToExistingProcess(arg interface{}, answer *bool) error {
if c.config.AttachPid != 0 {
*answer = true
}
return nil
}

@ -132,13 +132,18 @@ func handleExit(client service.Client, t *Term) (error, int) {
}
}
answer, err := t.line.Prompt("Would you like to kill the process? [Y/n] ")
if err != nil {
return io.EOF, 2
}
answer = strings.ToLower(strings.TrimSpace(answer))
var kill bool
if client.AttachedToExistingProcess() {
answer, err := t.line.Prompt("Would you like to kill the process? [Y/n] ")
if err != nil {
return io.EOF, 2
}
answer = strings.ToLower(strings.TrimSpace(answer))
kill := (answer != "n" && answer != "no")
kill = (answer != "n" && answer != "no")
} else {
kill = true
}
err = client.Detach(kill)
if err != nil {
return err, 1