Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling for sysctl calls under darwin #46

Open
fearful-symmetry opened this issue Jul 26, 2022 · 0 comments
Open

Improve error handling for sysctl calls under darwin #46

fearful-symmetry opened this issue Jul 26, 2022 · 0 comments
Assignees
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@fearful-symmetry
Copy link
Contributor

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"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

No branches or pull requests

1 participant