ENOMEM when calling sysctl_handle_int from custom handler
Ryan Stone
rysto32 at gmail.com
Tue Dec 18 19:14:04 UTC 2018
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);
}
More information about the freebsd-hackers
mailing list