Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Jun 2011 17:48:54 -0700
From:      Garrett Cooper <yanegomi@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: sysctl_handle_int questions
Message-ID:  <BANLkTim6ZkinDgnoQz3d_=qah4GYm5O=Pg@mail.gmail.com>
In-Reply-To: <BANLkTin%2B%2BJs=Jzv_wWUiMghkO1FRGPx%2BJA@mail.gmail.com>
References:  <BANLkTin%2B%2BJs=Jzv_wWUiMghkO1FRGPx%2BJA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jun 10, 2011 at 5:46 PM, Garrett Cooper <yanegomi@gmail.com> wrote:
> =A0 =A0Looking at sysctl_handle_int in a 7.2-ish tree...
>
> 1. What is the purpose of arg2? In all cases in /sys minus a few, arg2
> appears to be zeroed out:
>
> $ grep -Ir 'sysctl_handle_int.*[^0], req)' . 2>/dev/null
> ./amd64/amd64/pmap.c: =A0 error =3D sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./amd64/amd64/pmap.c: =A0 error =3D sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./dev/acpi_support/acpi_aiboost.c: =A0 =A0 =A0error =3D
> sysctl_handle_int(oidp, &val, 0 , req);
> ./dev/acpi_support/acpi_aiboost.c: =A0 =A0 =A0error =3D
> sysctl_handle_int(oidp, &val, 0 , req);
> ./dev/acpi_support/acpi_aiboost.c: =A0 =A0 =A0error =3D
> sysctl_handle_int(oidp, &val, 0 , req);
> ./dev/cxgb/cxgb_sge.c: =A0 =A0 =A0 =A0err =3D sysctl_handle_int(oidp,
> &coalesce_usecs, arg2, req);
> ./dev/mxge/if_mxge.c: =A0 =A0 =A0 =A0err =3D sysctl_handle_int(oidp,
> &intr_coal_delay, arg2, req);
> ./dev/mxge/if_mxge.c: =A0 =A0 =A0 =A0err =3D sysctl_handle_int(oidp, &ena=
bled, arg2, req);
> ./dev/mxge/if_mxge.c: =A0 err =3D sysctl_handle_int(oidp, &lro_cnt, arg2,=
 req);
> ./dev/mxge/if_mxge.c: =A0 =A0 =A0 =A0err =3D sysctl_handle_int(oidp, arg1=
, arg2, req);
> ./dev/nxge/if_nxge.c: =A0 status =3D sysctl_handle_int(oidp, &request, ar=
g2, req);
> ./dev/random/randomdev_soft.c: =A0return sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./kern/subr_prf.c: =A0 =A0 =A0error =3D sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./netinet/in_pcb.c: =A0 =A0 error =3D sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./netinet/sctp_sysctl.c: =A0 =A0 =A0 =A0error =3D sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./netinet/sctp_sysctl.c: =A0 =A0 =A0 =A0error =3D sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
>
> 2. Is there a proper way to restore the value in a SYSCTL_PROC handler
> instead of saving a value to a local, passing in newp via a global
> value, and restoring if sysctl_handle_int returned a nonzero value,
> e.g.
>
> old_global =3D global;
> error =3D sysctl_handle_int(oidp, &global, old_global, req);
> if (!error && req->newptr) {
> =A0 =A0/*
> =A0 =A0 * Do something fun with global.. maybe capture an error via `erro=
r' and
> =A0 =A0 * restore appropriately down below, but that's optional..
> =A0 =A0 */
> }
> if (error)
> =A0 =A0global =3D old_global;
>
> =A0 =A0I'm asking because I tried passing in a local variable instead of
> the global in the function, and that got printed out later on via
> sysctlbyname(3), and well... it didn't work out too well
> (sysctlbyname(3) was returning a random uninitialized value from the
> stack).

    Nevermind. I think I got it figured out now (my brain was just a
bit scrambled after staring at the screen for a bit).
Thanks,
-Garrett



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BANLkTim6ZkinDgnoQz3d_=qah4GYm5O=Pg>