Skip to content

Commit

Permalink
Merge pull request #1424 from chernomor/master
Browse files Browse the repository at this point in the history
Groups in /proc/PID/status has type uint32.
  • Loading branch information
shirou committed Feb 17, 2024
2 parents 0295ae7 + ca2e505 commit 8b3601a
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Process struct {
numCtxSwitches *NumCtxSwitchesStat
uids []int32
gids []int32
groups []int32
groups []uint32
numThreads int32
memInfo *MemoryInfoStat
sigInfo *SignalInfoStat
Expand Down Expand Up @@ -369,7 +369,7 @@ func (p *Process) CPUPercentWithContext(ctx context.Context) (float64, error) {
}

// Groups returns all group IDs(include supplementary groups) of the process as a slice of the int
func (p *Process) Groups() ([]int32, error) {
func (p *Process) Groups() ([]uint32, error) {
return p.GroupsWithContext(context.Background())
}

Expand Down
2 changes: 1 addition & 1 deletion process/process_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
return gids, nil
}

func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError
// k, err := p.getKProc()
// if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion process/process_fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError
}

Expand Down
6 changes: 3 additions & 3 deletions process/process_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
return gids, nil
}

func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
k, err := p.getKProc()
if err != nil {
return nil, err
}

groups := make([]int32, k.Ngroups)
groups := make([]uint32, k.Ngroups)
for i := int16(0); i < k.Ngroups; i++ {
groups[i] = int32(k.Groups[i])
groups[i] = uint32(k.Groups[i])
}

return groups, nil
Expand Down
10 changes: 5 additions & 5 deletions process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
return p.gids, nil
}

func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
err := p.fillFromStatusWithContext(ctx)
if err != nil {
return []int32{}, err
return []uint32{}, err
}
return p.groups, nil
}
Expand Down Expand Up @@ -885,13 +885,13 @@ func (p *Process) fillFromStatusWithContext(ctx context.Context) error {
}
case "Groups":
groups := strings.Fields(value)
p.groups = make([]int32, 0, len(groups))
p.groups = make([]uint32, 0, len(groups))
for _, i := range groups {
v, err := strconv.ParseInt(i, 10, 32)
v, err := strconv.ParseUint(i, 10, 32)
if err != nil {
return err
}
p.groups = append(p.groups, int32(v))
p.groups = append(p.groups, uint32(v))
}
case "Threads":
v, err := strconv.ParseInt(value, 10, 32)
Expand Down
2 changes: 1 addition & 1 deletion process/process_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
return gids, nil
}

func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
k, err := p.getKProc()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion process/process_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError
}

Expand Down
2 changes: 1 addition & 1 deletion process/process_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError
}

Expand Down
2 changes: 1 addition & 1 deletion process/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
return nil, common.ErrNotImplementedError
}

func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError
}

Expand Down

0 comments on commit 8b3601a

Please sign in to comment.