Date: Thu, 02 Jun 2011 11:17:53 +0900 (JST) From: Hiroki Sato <hrs@FreeBSD.org> To: dougb@FreeBSD.org Cc: bz@FreeBSD.org, freebsd-rc@FreeBSD.org Subject: Re: afexists() Message-ID: <20110602.111753.392307987943310561.hrs@allbsd.org> In-Reply-To: <4DE6D3C8.1050503@FreeBSD.org> References: <4DE588B4.7090908@FreeBSD.org> <20110601.130434.820821962809263631.hrs@allbsd.org> <4DE6D3C8.1050503@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
----Security_Multipart0(Thu_Jun__2_11_17_53_2011_436)-- Content-Type: Multipart/Mixed; boundary="--Next_Part(Thu_Jun__2_11_17_53_2011_860)--" Content-Transfer-Encoding: 7bit ----Next_Part(Thu_Jun__2_11_17_53_2011_860)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Doug Barton <dougb@FreeBSD.org> wrote in <4DE6D3C8.1050503@FreeBSD.org>: do> On 05/31/2011 21:04, Hiroki Sato wrote: do> > I think it would be great if it is possible to create a wrapper do> > function for testing and caching. I expects testing kern.features.* do> > is likely added again to somewhere in rc.d scripts, and adding a long do> > lines of "[ -n ... ]&& return 0; if sysctl...; fi" each time do> > degrades readability. do> do> I think that's definitely an interesting idea, and I'd love to review do> patches that implement it. :) Unfortunately I don't have time to do so do> atm, and would prefer to focus on a specific case where a small do> optimization leads to a big gain. A patch is attached. -- Hiroki ----Next_Part(Thu_Jun__2_11_17_53_2011_860)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rc_kern_features_20110602-1.diff" Index: etc/rc.subr =================================================================== --- etc/rc.subr (revision 222591) +++ etc/rc.subr (working copy) @@ -1734,6 +1734,28 @@ fi +# check_kern_features mib +# Return existence of kern.features.* sysctl MIB as true or +# false. The result will be cached in $_rc_cache_kern_features_ +# namespace. "0" means the kern.features.X exists. + +check_kern_features() +{ + local _v + + [ -n "$1" ] || return 1; + _v=`eval echo "\\$_rc_cache_kern_features_$1"` + [ -n "$_v" ] && return "$_v"; + + if ${SYSCTL_N} kern.features.$1 > /dev/null 2>&1; then + eval _rc_cache_kern_features_$1=0 + return 0 + else + eval _rc_cache_kern_features_$1=1 + return 1 + fi +} + # _echoonce var msg mode # mode=0: Echo $msg if ${$var} is empty. # After doing echo, a string is set to ${$var}. Index: etc/network.subr =================================================================== --- etc/network.subr (revision 222591) +++ etc/network.subr (working copy) @@ -355,12 +355,9 @@ _af=$1 case ${_af} in - inet) - ${SYSCTL_N} kern.features.inet > /dev/null 2>&1 + inet|inet6) + check_kern_features ${_af} ;; - inet6) - ${SYSCTL_N} kern.features.inet6 > /dev/null 2>&1 - ;; ipx) ${SYSCTL_N} net.ipx > /dev/null 2>&1 ;; ----Next_Part(Thu_Jun__2_11_17_53_2011_860)---- ----Security_Multipart0(Thu_Jun__2_11_17_53_2011_436)-- Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEABECAAYFAk3m8tEACgkQTyzT2CeTzy3P6gCgzq+5/4qy/T/w/9mb4pjWg/nY RZAAoMdDDpUm5XPVq2vbWwPoprcuYtg3 =Q23V -----END PGP SIGNATURE----- ----Security_Multipart0(Thu_Jun__2_11_17_53_2011_436)----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110602.111753.392307987943310561.hrs>