diff options
Diffstat (limited to 'vendor/github.com/google/gops')
4 files changed, 61 insertions, 12 deletions
diff --git a/vendor/github.com/google/gops/agent/agent.go b/vendor/github.com/google/gops/agent/agent.go index 24c0b896..bb2bbf09 100644 --- a/vendor/github.com/google/gops/agent/agent.go +++ b/vendor/github.com/google/gops/agent/agent.go @@ -20,12 +20,13 @@ import ( "runtime/pprof" "runtime/trace" "strconv" + "strings" "sync" + "syscall" "time" "github.com/google/gops/internal" "github.com/google/gops/signal" - "github.com/kardianos/osext" ) const defaultAddr = "127.0.0.1:0" @@ -116,18 +117,21 @@ func listen() { for { fd, err := listener.Accept() if err != nil { - fmt.Fprintf(os.Stderr, "gops: %v", err) + // No great way to check for this, see https://golang.org/issues/4373. + if !strings.Contains(err.Error(), "use of closed network connection") { + fmt.Fprintf(os.Stderr, "gops: %v\n", err) + } if netErr, ok := err.(net.Error); ok && !netErr.Temporary() { break } continue } if _, err := fd.Read(buf); err != nil { - fmt.Fprintf(os.Stderr, "gops: %v", err) + fmt.Fprintf(os.Stderr, "gops: %v\n", err) continue } if err := handle(fd, buf); err != nil { - fmt.Fprintf(os.Stderr, "gops: %v", err) + fmt.Fprintf(os.Stderr, "gops: %v\n", err) continue } fd.Close() @@ -136,12 +140,16 @@ func listen() { func gracefulShutdown() { c := make(chan os.Signal, 1) - gosignal.Notify(c, os.Interrupt) + gosignal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) go func() { // cleanup the socket on shutdown. - <-c + sig := <-c Close() - os.Exit(1) + ret := 1 + if sig == syscall.SIGTERM { + ret = 0 + } + os.Exit(ret) }() } @@ -220,7 +228,7 @@ func handle(conn io.ReadWriter, msg []byte) error { case signal.Version: fmt.Fprintf(conn, "%v\n", runtime.Version()) case signal.HeapProfile: - pprof.WriteHeapProfile(conn) + return pprof.WriteHeapProfile(conn) case signal.CPUProfile: if err := pprof.StartCPUProfile(conn); err != nil { return err @@ -233,7 +241,7 @@ func handle(conn io.ReadWriter, msg []byte) error { fmt.Fprintf(conn, "GOMAXPROCS: %v\n", runtime.GOMAXPROCS(0)) fmt.Fprintf(conn, "num CPU: %v\n", runtime.NumCPU()) case signal.BinaryDump: - path, err := osext.Executable() + path, err := os.Executable() if err != nil { return err } @@ -246,7 +254,9 @@ func handle(conn io.ReadWriter, msg []byte) error { _, err = bufio.NewReader(f).WriteTo(conn) return err case signal.Trace: - trace.Start(conn) + if err := trace.Start(conn); err != nil { + return err + } time.Sleep(5 * time.Second) trace.Stop() case signal.SetGCPercent: diff --git a/vendor/github.com/google/gops/internal/internal.go b/vendor/github.com/google/gops/internal/internal.go index 80eac63f..ec63f918 100644 --- a/vendor/github.com/google/gops/internal/internal.go +++ b/vendor/github.com/google/gops/internal/internal.go @@ -6,12 +6,12 @@ package internal import ( "errors" - "fmt" "io/ioutil" "os" "os/user" "path/filepath" "runtime" + "strconv" "strings" ) @@ -22,9 +22,18 @@ func ConfigDir() (string, error) { return configDir, nil } + if osUserConfigDir := getOSUserConfigDir(); osUserConfigDir != "" { + return filepath.Join(osUserConfigDir, "gops"), nil + } + if runtime.GOOS == "windows" { return filepath.Join(os.Getenv("APPDATA"), "gops"), nil } + + if xdgConfigDir := os.Getenv("XDG_CONFIG_HOME"); xdgConfigDir != "" { + return filepath.Join(xdgConfigDir, "gops"), nil + } + homeDir := guessUnixHomeDir() if homeDir == "" { return "", errors.New("unable to get current user home directory: os/user lookup failed; $HOME is empty") @@ -45,7 +54,7 @@ func PIDFile(pid int) (string, error) { if err != nil { return "", err } - return fmt.Sprintf("%s/%d", gopsdir, pid), nil + return filepath.Join(gopsdir, strconv.Itoa(pid)), nil } func GetPort(pid int) (string, error) { diff --git a/vendor/github.com/google/gops/internal/internal_go1_13.go b/vendor/github.com/google/gops/internal/internal_go1_13.go new file mode 100644 index 00000000..6e823138 --- /dev/null +++ b/vendor/github.com/google/gops/internal/internal_go1_13.go @@ -0,0 +1,19 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.13 + +package internal + +import ( + "os" +) + +func getOSUserConfigDir() string { + configDir, err := os.UserConfigDir() + if err != nil { + return "" + } + return configDir +} diff --git a/vendor/github.com/google/gops/internal/internal_lt_go1_13.go b/vendor/github.com/google/gops/internal/internal_lt_go1_13.go new file mode 100644 index 00000000..8506cf5f --- /dev/null +++ b/vendor/github.com/google/gops/internal/internal_lt_go1_13.go @@ -0,0 +1,11 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !go1.13 + +package internal + +func getOSUserConfigDir() string { + return "" +} |