Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Dec 2018 14:13:50 -0500
From:      Ryan Stone <rysto32@gmail.com>
To:        Austin Shafer <amshafer64@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: ENOMEM when calling sysctl_handle_int from custom handler
Message-ID:  <CAFMmRNwyd6meO2LOfHLk8pg3y9x=RaE7hukw8cJAa0s%2BvgZTxg@mail.gmail.com>
In-Reply-To: <861s6fpyua.fsf@triplebuff.com>
References:  <861s6fpyua.fsf@triplebuff.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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);
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFMmRNwyd6meO2LOfHLk8pg3y9x=RaE7hukw8cJAa0s%2BvgZTxg>