sysctl_handle_int questions
Garrett Cooper
yanegomi at gmail.com
Sat Jun 11 00:48:56 UTC 2011
On Fri, Jun 10, 2011 at 5:46 PM, Garrett Cooper <yanegomi at gmail.com> wrote:
> Looking 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: error = sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./amd64/amd64/pmap.c: error = sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./dev/acpi_support/acpi_aiboost.c: error =
> sysctl_handle_int(oidp, &val, 0 , req);
> ./dev/acpi_support/acpi_aiboost.c: error =
> sysctl_handle_int(oidp, &val, 0 , req);
> ./dev/acpi_support/acpi_aiboost.c: error =
> sysctl_handle_int(oidp, &val, 0 , req);
> ./dev/cxgb/cxgb_sge.c: err = sysctl_handle_int(oidp,
> &coalesce_usecs, arg2, req);
> ./dev/mxge/if_mxge.c: err = sysctl_handle_int(oidp,
> &intr_coal_delay, arg2, req);
> ./dev/mxge/if_mxge.c: err = sysctl_handle_int(oidp, &enabled, arg2, req);
> ./dev/mxge/if_mxge.c: err = sysctl_handle_int(oidp, &lro_cnt, arg2, req);
> ./dev/mxge/if_mxge.c: err = sysctl_handle_int(oidp, arg1, arg2, req);
> ./dev/nxge/if_nxge.c: status = sysctl_handle_int(oidp, &request, arg2, req);
> ./dev/random/randomdev_soft.c: return sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./kern/subr_prf.c: error = sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./netinet/in_pcb.c: error = sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./netinet/sctp_sysctl.c: error = sysctl_handle_int(oidp,
> oidp->oid_arg1, oidp->oid_arg2, req);
> ./netinet/sctp_sysctl.c: error = 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 = global;
> error = sysctl_handle_int(oidp, &global, old_global, req);
> if (!error && req->newptr) {
> /*
> * Do something fun with global.. maybe capture an error via `error' and
> * restore appropriately down below, but that's optional..
> */
> }
> if (error)
> global = old_global;
>
> I'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
More information about the freebsd-hackers
mailing list