diff --git a/service/client.go b/service/client.go index dae36038..89570a96 100644 --- a/service/client.go +++ b/service/client.go @@ -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 } diff --git a/service/rpc/client.go b/service/rpc/client.go index 8af0815b..46d1672b 100644 --- a/service/rpc/client.go +++ b/service/rpc/client.go @@ -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) } diff --git a/service/rpc/server.go b/service/rpc/server.go index 7f3ac445..6de45729 100644 --- a/service/rpc/server.go +++ b/service/rpc/server.go @@ -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 +} diff --git a/terminal/terminal.go b/terminal/terminal.go index a0ee2801..5130315b 100644 --- a/terminal/terminal.go +++ b/terminal/terminal.go @@ -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