1
0
mirror of https://github.com/google/gops.git synced 2024-11-19 20:31:58 +02:00

agent: don't close on interrupt by default (#49)

This commit is contained in:
JBD 2017-09-11 19:50:16 -07:00 committed by GitHub
parent d38055cdcb
commit 1a41b817e5
3 changed files with 12 additions and 12 deletions

View File

@ -43,10 +43,11 @@ type Options struct {
// Optional.
Addr string
// NoShutdownCleanup tells the agent not to automatically cleanup
// resources if the running process receives an interrupt.
// ShutdownCleanup automatically cleans up resources if the
// running process receives an interrupt. Otherwise, users
// can call Close before shutting down.
// Optional.
NoShutdownCleanup bool
ShutdownCleanup bool
}
// Listen starts the gops agent on a host process. Once agent started, users
@ -58,13 +59,10 @@ type Options struct {
// Note: The agent exposes an endpoint via a TCP connection that can be used by
// any program on the system. Review your security requirements before starting
// the agent.
func Listen(opts *Options) error {
func Listen(opts Options) error {
mu.Lock()
defer mu.Unlock()
if opts == nil {
opts = &Options{}
}
if portfile != "" {
return fmt.Errorf("gops: agent already listening at: %v", listener.Addr())
}
@ -77,7 +75,7 @@ func Listen(opts *Options) error {
if err != nil {
return err
}
if !opts.NoShutdownCleanup {
if opts.ShutdownCleanup {
gracefulShutdown()
}

View File

@ -10,7 +10,7 @@ import (
)
func TestListen(t *testing.T) {
err := Listen(nil)
err := Listen(Options{})
if err != nil {
t.Fatal(err)
}
@ -18,7 +18,7 @@ func TestListen(t *testing.T) {
}
func TestAgentClose(t *testing.T) {
err := Listen(nil)
err := Listen(Options{})
if err != nil {
t.Fatal(err)
}
@ -33,7 +33,7 @@ func TestAgentClose(t *testing.T) {
}
func TestAgentListenMultipleClose(t *testing.T) {
err := Listen(nil)
err := Listen(Options{})
if err != nil {
t.Fatal(err)
}

View File

@ -12,7 +12,9 @@ import (
)
func main() {
if err := agent.Listen(nil); err != nil {
if err := agent.Listen(agent.Options{
ShutdownCleanup: true, // automatically closes on os.Interrupt
}); err != nil {
log.Fatal(err)
}
time.Sleep(time.Hour)