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

next in thread | raw e-mail | index | archive | help
    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).
Thanks!
-Garrett



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BANLkTin%2B%2BJs=Jzv_wWUiMghkO1FRGPx%2BJA>