fix: golangci lint with max -> maxConn

pull/1693/head
shirou 7 months ago
parent edff3add94
commit 5f158096be

@ -12,8 +12,9 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v4/internal/common"
) )
// PartitionsWithContext returns disk partition. // PartitionsWithContext returns disk partition.

@ -74,8 +74,8 @@ func TestIOCounters_concurrency_on_darwin_cgo(t *testing.T) {
t.Skip("darwin only") t.Skip("darwin only")
} }
var wg sync.WaitGroup var wg sync.WaitGroup
const max = 1000 const maxCount = 1000
for i := 1; i < max; i++ { for i := 1; i < maxCount; i++ {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()

@ -5,6 +5,8 @@ package mem
import ( import (
"context" "context"
"github.com/shirou/gopsutil/v4/internal/common"
) )
func VirtualMemory() (*VirtualMemoryStat, error) { func VirtualMemory() (*VirtualMemoryStat, error) {
@ -14,3 +16,7 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
func SwapMemory() (*SwapMemoryStat, error) { func SwapMemory() (*SwapMemoryStat, error) {
return SwapMemoryWithContext(context.Background()) return SwapMemoryWithContext(context.Background())
} }
func SwapDevices() ([]*SwapDevice, error) {
return nil, common.ErrNotImplementedError
}

@ -286,11 +286,11 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
return ret, nil return ret, nil
} }
func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { func ConnectionsMax(kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsMaxWithContext(context.Background(), kind, max) return ConnectionsMaxWithContext(context.Background(), kind, maxConn)
} }
func ConnectionsMaxWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }
@ -305,8 +305,8 @@ func ConnectionsWithoutUidsWithContext(ctx context.Context, kind string) ([]Conn
return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0) return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0)
} }
func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, max) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, maxConn)
} }
func ConnectionsPidWithoutUids(kind string, pid int32) ([]ConnectionStat, error) { func ConnectionsPidWithoutUids(kind string, pid int32) ([]ConnectionStat, error) {
@ -317,14 +317,14 @@ func ConnectionsPidWithoutUidsWithContext(ctx context.Context, kind string, pid
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, 0) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, 0)
} }
func ConnectionsPidMaxWithoutUids(kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUids(kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, max) return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, maxConn)
} }
func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, max) return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, maxConn)
} }
func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }

@ -49,11 +49,11 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }
func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { func ConnectionsMax(kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsMaxWithContext(context.Background(), kind, max) return ConnectionsMaxWithContext(context.Background(), kind, maxConn)
} }
func ConnectionsMaxWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }
@ -68,8 +68,8 @@ func ConnectionsWithoutUidsWithContext(ctx context.Context, kind string) ([]Conn
return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0) return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0)
} }
func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, max) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, maxConn)
} }
func ConnectionsPidWithoutUids(kind string, pid int32) ([]ConnectionStat, error) { func ConnectionsPidWithoutUids(kind string, pid int32) ([]ConnectionStat, error) {
@ -80,14 +80,14 @@ func ConnectionsPidWithoutUidsWithContext(ctx context.Context, kind string, pid
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, 0) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, 0)
} }
func ConnectionsPidMaxWithoutUids(kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUids(kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, max) return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, maxConn)
} }
func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, max) return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, maxConn)
} }
func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }

@ -238,14 +238,14 @@ func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
} }
stats := make([]FilterStat, 0, 1) stats := make([]FilterStat, 0, 1)
max, err := common.ReadInts(maxfile) maxConn, err := common.ReadInts(maxfile)
if err != nil { if err != nil {
return nil, err return nil, err
} }
payload := FilterStat{ payload := FilterStat{
ConnTrackCount: count[0], ConnTrackCount: count[0],
ConnTrackMax: max[0], ConnTrackMax: maxConn[0],
} }
stats = append(stats, payload) stats = append(stats, payload)
@ -396,12 +396,12 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
// Return a list of network connections opened returning at most `max` // Return a list of network connections opened returning at most `max`
// connections for each running process. // connections for each running process.
func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { func ConnectionsMax(kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsMaxWithContext(context.Background(), kind, max) return ConnectionsMaxWithContext(context.Background(), kind, maxConn)
} }
func ConnectionsMaxWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithContext(ctx, kind, 0, max) return ConnectionsPidMaxWithContext(ctx, kind, 0, maxConn)
} }
// Return a list of network connections opened, omitting `Uids`. // Return a list of network connections opened, omitting `Uids`.
@ -415,8 +415,8 @@ func ConnectionsWithoutUidsWithContext(ctx context.Context, kind string) ([]Conn
return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0) return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0)
} }
func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, max) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, maxConn)
} }
// Return a list of network connections opened by a process. // Return a list of network connections opened by a process.
@ -437,23 +437,23 @@ func ConnectionsPidWithoutUidsWithContext(ctx context.Context, kind string, pid
} }
// Return up to `max` network connections opened by a process. // Return up to `max` network connections opened by a process.
func ConnectionsPidMax(kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMax(kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithContext(context.Background(), kind, pid, max) return ConnectionsPidMaxWithContext(context.Background(), kind, pid, maxConn)
} }
func ConnectionsPidMaxWithoutUids(kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUids(kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, max) return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, maxConn)
} }
func ConnectionsPidMaxWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, max, false) return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, maxConn, false)
} }
func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, max, true) return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, maxConn, true)
} }
func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int, skipUids bool) ([]ConnectionStat, error) { func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int, skipUids bool) ([]ConnectionStat, error) {
tmap, ok := netConnectionKindMap[kind] tmap, ok := netConnectionKindMap[kind]
if !ok { if !ok {
return nil, fmt.Errorf("invalid kind, %s", kind) return nil, fmt.Errorf("invalid kind, %s", kind)
@ -462,9 +462,9 @@ func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, p
var err error var err error
var inodes map[string][]inodeMap var inodes map[string][]inodeMap
if pid == 0 { if pid == 0 {
inodes, err = getProcInodesAllWithContext(ctx, root, max) inodes, err = getProcInodesAllWithContext(ctx, root, maxConn)
} else { } else {
inodes, err = getProcInodes(root, pid, max) inodes, err = getProcInodes(root, pid, maxConn)
if len(inodes) == 0 { if len(inodes) == 0 {
// no connection for the pid // no connection for the pid
return []ConnectionStat{}, nil return []ConnectionStat{}, nil
@ -543,7 +543,7 @@ func statsFromInodesWithContext(ctx context.Context, root string, pid int32, tma
} }
// getProcInodes returns fd of the pid. // getProcInodes returns fd of the pid.
func getProcInodes(root string, pid int32, max int) (map[string][]inodeMap, error) { func getProcInodes(root string, pid int32, maxConn int) (map[string][]inodeMap, error) {
ret := make(map[string][]inodeMap) ret := make(map[string][]inodeMap)
dir := fmt.Sprintf("%s/%d/fd", root, pid) dir := fmt.Sprintf("%s/%d/fd", root, pid)
@ -552,7 +552,7 @@ func getProcInodes(root string, pid int32, max int) (map[string][]inodeMap, erro
return ret, err return ret, err
} }
defer f.Close() defer f.Close()
dirEntries, err := f.ReadDir(max) dirEntries, err := f.ReadDir(maxConn)
if err != nil { if err != nil {
return ret, err return ret, err
} }
@ -668,11 +668,11 @@ func (p *process) fillFromStatus(ctx context.Context) error {
return nil return nil
} }
func getProcInodesAll(root string, max int) (map[string][]inodeMap, error) { func getProcInodesAll(root string, maxConn int) (map[string][]inodeMap, error) {
return getProcInodesAllWithContext(context.Background(), root, max) return getProcInodesAllWithContext(context.Background(), root, maxConn)
} }
func getProcInodesAllWithContext(ctx context.Context, root string, max int) (map[string][]inodeMap, error) { func getProcInodesAllWithContext(ctx context.Context, root string, maxConn int) (map[string][]inodeMap, error) {
pids, err := PidsWithContext(ctx) pids, err := PidsWithContext(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -680,7 +680,7 @@ func getProcInodesAllWithContext(ctx context.Context, root string, max int) (map
ret := make(map[string][]inodeMap) ret := make(map[string][]inodeMap)
for _, pid := range pids { for _, pid := range pids {
t, err := getProcInodes(root, pid, max) t, err := getProcInodes(root, pid, maxConn)
if err != nil { if err != nil {
// skip if permission error or no longer exists // skip if permission error or no longer exists
if os.IsPermission(err) || os.IsNotExist(err) || errors.Is(err, io.EOF) { if os.IsPermission(err) || os.IsNotExist(err) || errors.Is(err, io.EOF) {

@ -113,8 +113,8 @@ func TestConnectionsMax(t *testing.T) {
t.Skip("Skip CI") t.Skip("Skip CI")
} }
max := 10 maxConn := 10
v, err := ConnectionsMax("tcp", max) v, err := ConnectionsMax("tcp", maxConn)
assert.Nil(t, err) assert.Nil(t, err)
assert.NotEmpty(t, v) assert.NotEmpty(t, v)
@ -125,7 +125,7 @@ func TestConnectionsMax(t *testing.T) {
} }
} }
for _, c := range cxByPid { for _, c := range cxByPid {
assert.True(t, c <= max) assert.True(t, c <= maxConn)
} }
} }

@ -25,11 +25,11 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
// Return a list of network connections opened returning at most `max` // Return a list of network connections opened returning at most `max`
// connections for each running process. // connections for each running process.
func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { func ConnectionsMax(kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsMaxWithContext(context.Background(), kind, max) return ConnectionsMaxWithContext(context.Background(), kind, maxConn)
} }
func ConnectionsMaxWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }
@ -180,11 +180,11 @@ func parseNetAddr(line string) (laddr Addr, raddr Addr, err error) {
} }
// Return up to `max` network connections opened by a process. // Return up to `max` network connections opened by a process.
func ConnectionsPidMax(kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMax(kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithContext(context.Background(), kind, pid, max) return ConnectionsPidMaxWithContext(context.Background(), kind, pid, maxConn)
} }
func ConnectionsPidMaxWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }
@ -199,8 +199,8 @@ func ConnectionsWithoutUidsWithContext(ctx context.Context, kind string) ([]Conn
return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0) return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0)
} }
func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, max) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, maxConn)
} }
func ConnectionsPidWithoutUids(kind string, pid int32) ([]ConnectionStat, error) { func ConnectionsPidWithoutUids(kind string, pid int32) ([]ConnectionStat, error) {
@ -211,14 +211,14 @@ func ConnectionsPidWithoutUidsWithContext(ctx context.Context, kind string, pid
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, 0) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, 0)
} }
func ConnectionsPidMaxWithoutUids(kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUids(kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, max) return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, maxConn)
} }
func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, max) return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, maxConn)
} }
func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }

@ -279,11 +279,11 @@ func getNetStatWithKind(kindType netConnectionKindType) ([]ConnectionStat, error
// Return a list of network connections opened returning at most `max` // Return a list of network connections opened returning at most `max`
// connections for each running process. // connections for each running process.
func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { func ConnectionsMax(kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsMaxWithContext(context.Background(), kind, max) return ConnectionsMaxWithContext(context.Background(), kind, maxConn)
} }
func ConnectionsMaxWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }
@ -298,8 +298,8 @@ func ConnectionsWithoutUidsWithContext(ctx context.Context, kind string) ([]Conn
return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0) return ConnectionsMaxWithoutUidsWithContext(ctx, kind, 0)
} }
func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, max int) ([]ConnectionStat, error) { func ConnectionsMaxWithoutUidsWithContext(ctx context.Context, kind string, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, max) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, 0, maxConn)
} }
func ConnectionsPidWithoutUids(kind string, pid int32) ([]ConnectionStat, error) { func ConnectionsPidWithoutUids(kind string, pid int32) ([]ConnectionStat, error) {
@ -310,15 +310,15 @@ func ConnectionsPidWithoutUidsWithContext(ctx context.Context, kind string, pid
return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, 0) return ConnectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, 0)
} }
func ConnectionsPidMaxWithoutUids(kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUids(kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, max) return ConnectionsPidMaxWithoutUidsWithContext(context.Background(), kind, pid, maxConn)
} }
func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func ConnectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, max) return connectionsPidMaxWithoutUidsWithContext(ctx, kind, pid, maxConn)
} }
func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, max int) ([]ConnectionStat, error) { func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, pid int32, maxConn int) ([]ConnectionStat, error) {
return []ConnectionStat{}, common.ErrNotImplementedError return []ConnectionStat{}, common.ErrNotImplementedError
} }

@ -547,8 +547,8 @@ func (p *Process) Connections() ([]net.ConnectionStat, error) {
} }
// ConnectionsMax returns a slice of net.ConnectionStat used by the process at most `max`. // ConnectionsMax returns a slice of net.ConnectionStat used by the process at most `max`.
func (p *Process) ConnectionsMax(max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMax(maxConn int) ([]net.ConnectionStat, error) {
return p.ConnectionsMaxWithContext(context.Background(), max) return p.ConnectionsMaxWithContext(context.Background(), maxConn)
} }
// MemoryMaps get memory maps from /proc/(pid)/smaps // MemoryMaps get memory maps from /proc/(pid)/smaps

@ -252,8 +252,8 @@ func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionS
return net.ConnectionsPidWithContext(ctx, "all", p.Pid) return net.ConnectionsPidWithContext(ctx, "all", p.Pid)
} }
func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, max) return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, maxConn)
} }
func ProcessesWithContext(ctx context.Context) ([]*Process, error) { func ProcessesWithContext(ctx context.Context) ([]*Process, error) {

@ -166,7 +166,7 @@ func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionS
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }
func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

@ -10,10 +10,11 @@ import (
"strconv" "strconv"
"strings" "strings"
"golang.org/x/sys/unix"
cpu "github.com/shirou/gopsutil/v4/cpu" cpu "github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/internal/common" "github.com/shirou/gopsutil/v4/internal/common"
net "github.com/shirou/gopsutil/v4/net" net "github.com/shirou/gopsutil/v4/net"
"golang.org/x/sys/unix"
) )
func pidsWithContext(ctx context.Context) ([]int32, error) { func pidsWithContext(ctx context.Context) ([]int32, error) {
@ -83,10 +84,7 @@ func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
return "", err return "", err
} }
ret := strings.FieldsFunc(string(buf), func(r rune) bool { ret := strings.FieldsFunc(string(buf), func(r rune) bool {
if r == '\u0000' { return r == '\u0000'
return true
}
return false
}) })
return strings.Join(ret, " "), nil return strings.Join(ret, " "), nil
@ -289,8 +287,8 @@ func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionS
return net.ConnectionsPidWithContext(ctx, "all", p.Pid) return net.ConnectionsPidWithContext(ctx, "all", p.Pid)
} }
func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, max) return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, maxConn)
} }
func ProcessesWithContext(ctx context.Context) ([]*Process, error) { func ProcessesWithContext(ctx context.Context) ([]*Process, error) {

@ -373,8 +373,8 @@ func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionS
return net.ConnectionsPidWithContext(ctx, "all", p.Pid) return net.ConnectionsPidWithContext(ctx, "all", p.Pid)
} }
func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, max) return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, maxConn)
} }
func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]MemoryMapsStat, error) { func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]MemoryMapsStat, error) {

@ -304,7 +304,7 @@ func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionS
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }
func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

@ -166,7 +166,7 @@ func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionS
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }
func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

@ -181,7 +181,7 @@ func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionS
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }
func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

@ -744,7 +744,7 @@ func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionS
return net.ConnectionsPidWithContext(ctx, "all", p.Pid) return net.ConnectionsPidWithContext(ctx, "all", p.Pid)
} }
func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

@ -16,3 +16,7 @@ const (
func VirtualizationWithContext(ctx context.Context) (string, string, error) { func VirtualizationWithContext(ctx context.Context) (string, string, error) {
return "", "", common.ErrNotImplementedError return "", "", common.ErrNotImplementedError
} }
func TemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
return []TemperatureStat{}, common.ErrNotImplementedError
}

Loading…
Cancel
Save