mirror of
https://github.com/google/gops.git
synced 2024-11-24 08:22:25 +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:
parent
3d102a4755
commit
53ee352cc8
@ -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)
|
18
goprocess/goprocess_1.18.go
Normal file
18
goprocess/goprocess_1.18.go
Normal 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
|
||||
}
|
18
goprocess/goprocess_lt1.18.go
Normal file
18
goprocess/goprocess_lt1.18.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user