mirror of
https://github.com/containers/podman.git
synced 2025-11-14 18:19:20 +08:00
Bump github.com/containers/psgo from 1.4.0 to 1.5.0
Bumps [github.com/containers/psgo](https://github.com/containers/psgo) from 1.4.0 to 1.5.0. - [Release notes](https://github.com/containers/psgo/releases) - [Commits](https://github.com/containers/psgo/compare/v1.4.0...v1.5.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
committed by
Daniel J Walsh
parent
0d2b5532c4
commit
d6d8106601
21
vendor/github.com/containers/psgo/internal/proc/stat.go
generated
vendored
21
vendor/github.com/containers/psgo/internal/proc/stat.go
generated
vendored
@@ -15,6 +15,7 @@
|
||||
package proc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
@@ -112,21 +113,31 @@ type Stat struct {
|
||||
}
|
||||
|
||||
// readStat is used for mocking in unit tests.
|
||||
var readStat = func(path string) ([]string, error) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
var readStat = func(path string) (string, error) {
|
||||
rawData, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return strings.Fields(string(data)), nil
|
||||
return string(rawData), nil
|
||||
}
|
||||
|
||||
// ParseStat parses the /proc/$pid/stat file and returns a Stat.
|
||||
func ParseStat(pid string) (*Stat, error) {
|
||||
fields, err := readStat(fmt.Sprintf("/proc/%s/stat", pid))
|
||||
data, err := readStat(fmt.Sprintf("/proc/%s/stat", pid))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
firstParen := strings.IndexByte(data, '(')
|
||||
lastParen := strings.LastIndexByte(data, ')')
|
||||
if firstParen == -1 || lastParen == -1 {
|
||||
return nil, errors.New("invalid format in stat")
|
||||
}
|
||||
pidstr := data[0 : firstParen-1]
|
||||
comm := data[firstParen+1 : lastParen]
|
||||
rest := strings.Fields(data[lastParen+1:])
|
||||
fields := append([]string{pidstr, comm}, rest...)
|
||||
|
||||
fieldAt := func(i int) string {
|
||||
return fields[i-1]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user