From owner-freebsd-hackers@FreeBSD.ORG Sat Jun 11 00:48:56 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ED132106567C for ; Sat, 11 Jun 2011 00:48:55 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-vx0-f182.google.com (mail-vx0-f182.google.com [209.85.220.182]) by mx1.freebsd.org (Postfix) with ESMTP id 9F97E8FC08 for ; Sat, 11 Jun 2011 00:48:55 +0000 (UTC) Received: by vxc34 with SMTP id 34so3734649vxc.13 for ; Fri, 10 Jun 2011 17:48:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=DIOS8swN077c6n/yR0JJKHhnDgcgUoUJYuXpTGUfIUs=; b=OwYhBKK7gCsAWv2AvMfU0yFMhfZD6d0lb9LtDB8bAzOyqSnh1381eheleoUxqJkyT3 wgvYVgWcjBIzfJKcgivFwyKLnHSAdhcQGUe0oKgki2mD15cVSIr7hu+ugIBz+3CnEz0E 3EeYg/BBqBfUwemOWZ1UKmYaAzVYsQMaenr3o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=UaaOMQ3MrsbFIGjCCq6LatbzowbwyxFTeo/9Hl2WkHyssI89lBwULqo7ojICrw0al/ vmE4NfXFzNuaqQyXr0liOP7Uk2+5UZ/D7rx6CVQbRE2SyButDYT9Ebq/L7yzeDsdQrIE gZ+Y0rz1dJumcHoXZn9++N7lgWPzQtYS/7/+Q= MIME-Version: 1.0 Received: by 10.220.213.195 with SMTP id gx3mr1073489vcb.23.1307753334662; Fri, 10 Jun 2011 17:48:54 -0700 (PDT) Received: by 10.220.189.202 with HTTP; Fri, 10 Jun 2011 17:48:54 -0700 (PDT) In-Reply-To: References: Date: Fri, 10 Jun 2011 17:48:54 -0700 Message-ID: From: Garrett Cooper To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: sysctl_handle_int questions X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jun 2011 00:48:56 -0000 On Fri, Jun 10, 2011 at 5:46 PM, Garrett Cooper 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