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

goprocess: use debug/buildinfo on Go 1.18 and newer

Use package debug/buildinfo [1] introduced in Go 1.18 [2] when possible.
This should avoid previous issues with rsc.io/goversion where Go
processes were no longer listed.

[1] https://pkg.go.dev/debug/buildinfo
[2] https://go.dev/doc/go1.18#debug/buildinfo

For #102
For #159
For #160
This commit is contained in:
Tobias Klauser 2022-05-04 22:41:16 +02:00 committed by Tobias Klauser
parent 3d102a4755
commit 53ee352cc8
4 changed files with 37 additions and 5 deletions

View File

@ -9,8 +9,6 @@ import (
"os"
"sync"
goversion "rsc.io/goversion/version"
"github.com/google/gops/internal"
ps "github.com/keybase/go-ps"
)
@ -119,13 +117,11 @@ func isGo(pr ps.Process) (path, version string, agent, ok bool, err error) {
if err != nil {
return
}
var versionInfo goversion.Version
versionInfo, err = goversion.ReadExe(path)
version, err = goVersion(path)
if err != nil {
return
}
ok = true
version = versionInfo.Release
pidfile, err := internal.PIDFile(pr.Pid())
if err == nil {
_, err := os.Stat(pidfile)

View File

@ -0,0 +1,18 @@
// Copyright 2022 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.
//go:build go1.18
// +build go1.18
package goprocess
import "debug/buildinfo"
func goVersion(path string) (string, error) {
info, err := buildinfo.ReadFile(path)
if err != nil {
return "", err
}
return info.GoVersion, nil
}

View File

@ -0,0 +1,18 @@
// Copyright 2022 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.
//go:build !go1.18
// +build !go1.18
package goprocess
import goversion "rsc.io/goversion/version"
func goVersion(path string) (string, error) {
versionInfo, err := goversion.ReadExe(path)
if err != nil {
return "", err
}
return versionInfo.Release, nil
}