Skip to content

Improve error handling for sysctl calls under darwin #46

Open
@fearful-symmetry

Description

@fearful-symmetry

This is in specific reference to the KERN_PROCARGS2 sysctl call that's made in this function:

func getProcArgs(pid int, filter func(string) bool) ([]string, string, mapstr.M, error) {

That sysctl call is a little finicky, and will return a generic EINVAL error for three main cases:

  • It doesn't have permission
  • It's called against a zombie process
  • The PID no longer exists.

The error handling should better distinguish between these three cases. The logic will probably need to look something like this:

if EINVAL{
    if not pidExists(pid) {
        return "PID does not exist"
    }
    if our_UID() != root or our_UID() != pid.UID {
        return "permission denied"
    }
    return "process is a zombie, skipping"
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions