diff options
Diffstat (limited to 'vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go')
| -rw-r--r-- | vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go b/vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go index 33abc10..5afafd8 100644 --- a/vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go +++ b/vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "encoding/binary" + "errors" "fmt" "path/filepath" "runtime" @@ -32,11 +33,11 @@ const ( KernProcPathname = 12 // path to executable ) -type _Ctype_struct___0 struct { +type _Ctype_struct___0 struct { //nolint:revive //FIXME Pad uint64 } -func pidsWithContext(ctx context.Context) ([]int32, error) { +func pidsWithContext(_ context.Context) ([]int32, error) { var ret []int32 kprocs, err := unix.SysctlKinfoProcSlice("kern.proc.all") @@ -51,7 +52,7 @@ func pidsWithContext(ctx context.Context) ([]int32, error) { return ret, nil } -func (p *Process) PpidWithContext(ctx context.Context) (int32, error) { +func (p *Process) PpidWithContext(_ context.Context) (int32, error) { k, err := p.getKProc() if err != nil { return 0, err @@ -84,7 +85,7 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { return name, nil } -func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) { +func (p *Process) createTimeWithContext(_ context.Context) (int64, error) { k, err := p.getKProc() if err != nil { return 0, err @@ -112,7 +113,7 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) { return strings.IndexByte(string(out), '+') != -1, nil } -func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) { +func (p *Process) UidsWithContext(_ context.Context) ([]uint32, error) { k, err := p.getKProc() if err != nil { return nil, err @@ -124,7 +125,7 @@ func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) { return []uint32{userEffectiveUID}, nil } -func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) { +func (p *Process) GidsWithContext(_ context.Context) ([]uint32, error) { k, err := p.getKProc() if err != nil { return nil, err @@ -136,7 +137,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) { return gids, nil } -func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) { +func (p *Process) GroupsWithContext(_ context.Context) ([]uint32, error) { return nil, common.ErrNotImplementedError // k, err := p.getKProc() // if err != nil { @@ -151,7 +152,7 @@ func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) { // return groups, nil } -func (p *Process) TerminalWithContext(ctx context.Context) (string, error) { +func (p *Process) TerminalWithContext(_ context.Context) (string, error) { return "", common.ErrNotImplementedError /* k, err := p.getKProc() @@ -169,7 +170,7 @@ func (p *Process) TerminalWithContext(ctx context.Context) (string, error) { */ } -func (p *Process) NiceWithContext(ctx context.Context) (int32, error) { +func (p *Process) NiceWithContext(_ context.Context) (int32, error) { k, err := p.getKProc() if err != nil { return 0, err @@ -177,7 +178,7 @@ func (p *Process) NiceWithContext(ctx context.Context) (int32, error) { return int32(k.Proc.P_nice), nil } -func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) { +func (p *Process) IOCountersWithContext(_ context.Context) (*IOCountersStat, error) { return nil, common.ErrNotImplementedError } @@ -239,11 +240,12 @@ func (p *Process) getKProc() (*unix.KinfoProc, error) { // If passed arg pid is 0, get information from all process. func callPsWithContext(ctx context.Context, arg string, pid int32, threadOption bool, nameOption bool) ([][]string, error) { var cmd []string - if pid == 0 { // will get from all processes. + switch { + case pid == 0: // will get from all processes. cmd = []string{"-ax", "-o", arg} - } else if threadOption { + case threadOption: cmd = []string{"-x", "-o", arg, "-M", "-p", strconv.Itoa(int(pid))} - } else { + default: cmd = []string{"-x", "-o", arg, "-p", strconv.Itoa(int(pid))} } if nameOption { @@ -303,7 +305,7 @@ func getTimeScaleToNanoSeconds() float64 { return float64(timeBaseInfo.Numer) / float64(timeBaseInfo.Denom) } -func (p *Process) ExeWithContext(ctx context.Context) (string, error) { +func (p *Process) ExeWithContext(_ context.Context) (string, error) { lib, err := registerFuncs() if err != nil { return "", err @@ -332,7 +334,7 @@ type vnodePathInfo struct { // EUID can access. Otherwise "operation not permitted" will be returned as the // error. // Note: This might also work for other *BSD OSs. -func (p *Process) CwdWithContext(ctx context.Context) (string, error) { +func (p *Process) CwdWithContext(_ context.Context) (string, error) { lib, err := registerFuncs() if err != nil { return "", err @@ -348,7 +350,7 @@ func (p *Process) CwdWithContext(ctx context.Context) (string, error) { ret := procPidInfo(p.Pid, common.PROC_PIDVNODEPATHINFO, 0, uintptr(unsafe.Pointer(&vpi)), vpiSize) errno, _ := lib.Dlsym("errno") err = *(**unix.Errno)(unsafe.Pointer(&errno)) - if err == unix.EPERM { + if errors.Is(err, unix.EPERM) { return "", ErrorNotPermitted } @@ -373,11 +375,11 @@ func procArgs(pid int32) ([]byte, int, error) { return procargs, int(binary.LittleEndian.Uint32(nargs)), nil } -func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) { - return p.cmdlineSliceWithContext(ctx, true) +func (p *Process) CmdlineSliceWithContext(_ context.Context) ([]string, error) { + return p.cmdlineSlice() } -func (p *Process) cmdlineSliceWithContext(ctx context.Context, fallback bool) ([]string, error) { +func (p *Process) cmdlineSlice() ([]string, error) { pargs, nargs, err := procArgs(p.Pid) if err != nil { return nil, err @@ -393,7 +395,7 @@ func (p *Process) cmdlineSliceWithContext(ctx context.Context, fallback bool) ([ // are the arguments. Everything else in the slice is then the environment // of the process. for _, arg := range args[1:] { - argStr = string(arg[:]) + argStr = string(arg) if len(argStr) > 0 { if nargs > 0 { argSlice = append(argSlice, argStr) @@ -408,8 +410,8 @@ func (p *Process) cmdlineSliceWithContext(ctx context.Context, fallback bool) ([ } // cmdNameWithContext returns the command name (including spaces) without any arguments -func (p *Process) cmdNameWithContext(ctx context.Context) (string, error) { - r, err := p.cmdlineSliceWithContext(ctx, false) +func (p *Process) cmdNameWithContext(_ context.Context) (string, error) { + r, err := p.cmdlineSlice() if err != nil { return "", err } @@ -429,7 +431,7 @@ func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) { return strings.Join(r, " "), err } -func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) { +func (p *Process) NumThreadsWithContext(_ context.Context) (int32, error) { lib, err := registerFuncs() if err != nil { return 0, err @@ -442,7 +444,7 @@ func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) { return int32(ti.Threadnum), nil } -func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) { +func (p *Process) TimesWithContext(_ context.Context) (*cpu.TimesStat, error) { lib, err := registerFuncs() if err != nil { return nil, err @@ -461,7 +463,7 @@ func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) return ret, nil } -func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) { +func (p *Process) MemoryInfoWithContext(_ context.Context) (*MemoryInfoStat, error) { lib, err := registerFuncs() if err != nil { return nil, err |
