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

next in thread | previous in thread | raw e-mail | index | archive | help
Ryan Stone <rysto32@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
worked.

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m236quiomk.fsf>