ENOMEM when calling sysctl_handle_int from custom handler

Austin Shafer amshafer64 at gmail.com
Tue Dec 18 20:10:01 UTC 2018

Ryan Stone <rysto32 at gmail.com> writes:

> You should not pass arg1 and arg2 to sysctl_handle_int().  You instead
> need to pass a pointer to a local value containing the value you want
> to return to the sysctl caller.  After sysctl_handle_int returns, if
> it returned 0 and req->newptr is non-NULL, then the integer value will
> contain the new value that was passed to you from userland.  You want
> something that looks like this:
> int
> my_sysctl_handler(SYSCTL_HANDLER_ARGS)
> {
>      int val, error;
>      val = 5; /* Or whatever value you want to return from userland. */
>      error = sysctl_handle_int(oidp, &val, 0, req);
>      if (error != 0 || req->newptr == NULL)
>         return (error);
>     /* val contains the value set by the caller, so do something
> interesting with it here. */
>     return (0);
> }

Hmm yup this seems to be problem. I had originally tried to just pass
the handler args directly through to sysctl_handle_int to make sure I
was creating the nodes correctly, since I knew sysctl_handle_int

Thanks again for all the help on these beginner questions!
       Austin Shafer

More information about the freebsd-hackers mailing list