Skip to content

Commit

Permalink
goprocess: use debug/buildinfo on Go 1.18 and newer
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tklauser committed May 4, 2022
1 parent 4e16ac7 commit 209baaa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
6 changes: 1 addition & 5 deletions goprocess/gp.go → goprocess/goprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"os"
"sync"

goversion "rsc.io/goversion/version"

"github.com/google/gops/internal"
ps "github.com/keybase/go-ps"
)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions goprocess/goprocess_1.18.go
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions goprocess/goprocess_lt1.18.go
Original file line number Diff line number Diff line change
@@ -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
}
File renamed without changes.

0 comments on commit 209baaa

Please sign in to comment.