process.Uids and process.Gids are now return uint32

pull/1628/head
shirou 1 year ago
parent aace5e9d8f
commit 85f5f3a8e2

@ -30,8 +30,8 @@ type Process struct {
parent int32 parent int32
parentMutex sync.RWMutex // for windows ppid cache parentMutex sync.RWMutex // for windows ppid cache
numCtxSwitches *NumCtxSwitchesStat numCtxSwitches *NumCtxSwitchesStat
uids []int32 uids []uint32
gids []int32 gids []uint32
groups []uint32 groups []uint32
numThreads int32 numThreads int32
memInfo *MemoryInfoStat memInfo *MemoryInfoStat
@ -434,12 +434,12 @@ func (p *Process) Foreground() (bool, error) {
} }
// Uids returns user ids of the process as a slice of the int // Uids returns user ids of the process as a slice of the int
func (p *Process) Uids() ([]int32, error) { func (p *Process) Uids() ([]uint32, error) {
return p.UidsWithContext(context.Background()) return p.UidsWithContext(context.Background())
} }
// Gids returns group ids of the process as a slice of the int // Gids returns group ids of the process as a slice of the int
func (p *Process) Gids() ([]int32, error) { func (p *Process) Gids() ([]uint32, error) {
return p.GidsWithContext(context.Background()) return p.GidsWithContext(context.Background())
} }

@ -117,26 +117,26 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
return strings.IndexByte(string(out), '+') != -1, nil return strings.IndexByte(string(out), '+') != -1, nil
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) {
k, err := p.getKProc() k, err := p.getKProc()
if err != nil { if err != nil {
return nil, err return nil, err
} }
// See: http://unix.superglobalmegacorp.com/Net2/newsrc/sys/ucred.h.html // See: http://unix.superglobalmegacorp.com/Net2/newsrc/sys/ucred.h.html
userEffectiveUID := int32(k.Eproc.Ucred.Uid) userEffectiveUID := uint32(k.Eproc.Ucred.Uid)
return []int32{userEffectiveUID}, nil return []uint32{userEffectiveUID}, nil
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) {
k, err := p.getKProc() k, err := p.getKProc()
if err != nil { if err != nil {
return nil, err return nil, err
} }
gids := make([]int32, 0, 3) gids := make([]uint32, 0, 3)
gids = append(gids, int32(k.Eproc.Pcred.P_rgid), int32(k.Eproc.Pcred.P_rgid), int32(k.Eproc.Pcred.P_svgid)) gids = append(gids, uint32(k.Eproc.Pcred.P_rgid), uint32(k.Eproc.Pcred.P_rgid), uint32(k.Eproc.Pcred.P_svgid))
return gids, nil return gids, nil
} }

@ -82,11 +82,11 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
return false, common.ErrNotImplementedError return false, common.ErrNotImplementedError
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

@ -157,27 +157,27 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
return strings.IndexByte(string(out), '+') != -1, nil return strings.IndexByte(string(out), '+') != -1, nil
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) {
k, err := p.getKProc() k, err := p.getKProc()
if err != nil { if err != nil {
return nil, err return nil, err
} }
uids := make([]int32, 0, 3) uids := make([]uint32, 0, 3)
uids = append(uids, int32(k.Ruid), int32(k.Uid), int32(k.Svuid)) uids = append(uids, uint32(k.Ruid), uint32(k.Uid), uint32(k.Svuid))
return uids, nil return uids, nil
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) {
k, err := p.getKProc() k, err := p.getKProc()
if err != nil { if err != nil {
return nil, err return nil, err
} }
gids := make([]int32, 0, 3) gids := make([]uint32, 0, 3)
gids = append(gids, int32(k.Rgid), int32(k.Ngroups), int32(k.Svgid)) gids = append(gids, uint32(k.Rgid), uint32(k.Ngroups), uint32(k.Svgid))
return gids, nil return gids, nil
} }

@ -148,18 +148,18 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
return pgid == tpgid, nil return pgid == tpgid, nil
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext(ctx)
if err != nil { if err != nil {
return []int32{}, err return []uint32{}, err
} }
return p.uids, nil return p.uids, nil
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext(ctx)
if err != nil { if err != nil {
return []int32{}, err return []uint32{}, err
} }
return p.gids, nil return p.gids, nil
} }
@ -866,22 +866,22 @@ func (p *Process) fillFromStatusWithContext(ctx context.Context) error {
} }
p.tgid = int32(pval) p.tgid = int32(pval)
case "Uid": case "Uid":
p.uids = make([]int32, 0, 4) p.uids = make([]uint32, 0, 4)
for _, i := range strings.Split(value, "\t") { for _, i := range strings.Split(value, "\t") {
v, err := strconv.ParseInt(i, 10, 32) v, err := strconv.ParseInt(i, 10, 32)
if err != nil { if err != nil {
return err return err
} }
p.uids = append(p.uids, int32(v)) p.uids = append(p.uids, uint32(v))
} }
case "Gid": case "Gid":
p.gids = make([]int32, 0, 4) p.gids = make([]uint32, 0, 4)
for _, i := range strings.Split(value, "\t") { for _, i := range strings.Split(value, "\t") {
v, err := strconv.ParseInt(i, 10, 32) v, err := strconv.ParseInt(i, 10, 32)
if err != nil { if err != nil {
return err return err
} }
p.gids = append(p.gids, int32(v)) p.gids = append(p.gids, uint32(v))
} }
case "Groups": case "Groups":
groups := strings.Fields(value) groups := strings.Fields(value)

@ -176,27 +176,27 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
return strings.IndexByte(string(out), '+') != -1, nil return strings.IndexByte(string(out), '+') != -1, nil
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) {
k, err := p.getKProc() k, err := p.getKProc()
if err != nil { if err != nil {
return nil, err return nil, err
} }
uids := make([]int32, 0, 3) uids := make([]uint32, 0, 3)
uids = append(uids, int32(k.Ruid), int32(k.Uid), int32(k.Svuid)) uids = append(uids, uint32(k.Ruid), uint32(k.Uid), uint32(k.Svuid))
return uids, nil return uids, nil
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) {
k, err := p.getKProc() k, err := p.getKProc()
if err != nil { if err != nil {
return nil, err return nil, err
} }
gids := make([]int32, 0, 3) gids := make([]uint32, 0, 3)
gids = append(gids, int32(k.Rgid), int32(k.Ngroups), int32(k.Svgid)) gids = append(gids, uint32(k.Rgid), uint32(k.Ngroups), uint32(k.Svgid))
return gids, nil return gids, nil
} }
@ -207,9 +207,9 @@ func (p *Process) GroupsWithContext(ctx context.Context) ([]uint32, error) {
return nil, err return nil, err
} }
groups := make([]int32, k.Ngroups) groups := make([]uint32, k.Ngroups)
for i := int16(0); i < k.Ngroups; i++ { for i := int16(0); i < k.Ngroups; i++ {
groups[i] = int32(k.Groups[i]) groups[i] = uint32(k.Groups[i])
} }
return groups, nil return groups, nil

@ -82,11 +82,11 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
return false, common.ErrNotImplementedError return false, common.ErrNotImplementedError
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

@ -96,11 +96,11 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
return false, common.ErrNotImplementedError return false, common.ErrNotImplementedError
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

@ -466,11 +466,11 @@ func (p *Process) UsernameWithContext(ctx context.Context) (string, error) {
return domain + "\\" + user, err return domain + "\\" + user, err
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]uint32, error) {
return nil, common.ErrNotImplementedError return nil, common.ErrNotImplementedError
} }

Loading…
Cancel
Save