From owner-freebsd-rc@FreeBSD.ORG Mon May 9 00:57:10 2011 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8B0ED106564A for ; Mon, 9 May 2011 00:57:10 +0000 (UTC) (envelope-from Devin.Teske@fisglobal.com) Received: from mx1.fisglobal.com (mx1.fisglobal.com [199.200.24.190]) by mx1.freebsd.org (Postfix) with ESMTP id 501558FC14 for ; Mon, 9 May 2011 00:57:10 +0000 (UTC) Received: from sbhfislrext02.fnfis.com ([192.168.249.140]) by SCSFISLTC01 (8.14.3/8.14.3) with ESMTP id p490v8l5011473; Sun, 8 May 2011 19:57:08 -0500 Received: from SBHFISLTCGW04.FNFIS.COM (Not Verified[10.132.248.123]) by sbhfislrext02.fnfis.com with MailMarshal (v6, 5, 4, 7535) id ; Sun, 08 May 2011 19:57:17 -0500 Received: from SBHFISLTCGW04.FNFIS.COM ([10.132.248.123]) by SBHFISLTCGW04.FNFIS.COM with Microsoft SMTPSVC(6.0.3790.4675); Sun, 8 May 2011 19:57:08 -0500 Received: from [10.0.0.102] ([10.132.254.136]) by SBHFISLTCGW04.FNFIS.COM over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sun, 8 May 2011 19:57:07 -0500 Mime-Version: 1.0 (Apple Message framework v1084) From: Devin Teske In-Reply-To: <20110509002349.GI3527@DataIX.net> Date: Sun, 8 May 2011 17:57:05 -0700 Message-Id: <2E9FCA3F-79B7-4FE8-883E-EA1D45EECE56@vicor.com> References: <20110508191336.GC3527@DataIX.net> <5474DF9C-500A-4B51-948F-F56A66051476@vicor.com> <20110508215432.GG3527@DataIX.net> <20110509002349.GI3527@DataIX.net> To: Jason Hellenthal X-Mailer: Apple Mail (2.1084) X-OriginalArrivalTime: 09 May 2011 00:57:08.0021 (UTC) FILETIME=[05573E50:01CC0DE4] Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Garrett Cooper , freebsd-rc@freebsd.org Subject: Re: [RFC][Change-Request] Create usefulness in rc.subr etc/rc.conf.d/*.conf namespace. X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2011 00:57:10 -0000 On May 8, 2011, at 5:23 PM, Jason Hellenthal wrote: >=20 > Devin, >=20 > On Sun, May 08, 2011 at 03:52:06PM -0700, Devin Teske wrote: >>=20 >> I second Jilles all-builtin solution using `for' globbing (no forking ex= ternal processes or sub-shells). >>=20 >> Slight modification for brevity: >>=20 >> for _modular_conf in /etc/rc.conf.d/*.conf; do >> [ -f "$_modular_conf" -a -x "$_modular_conf" ] || continue >> debug "Sourcing $_modular_conf" >> . "$_modular_conf" >> done >>=20 >> Though I still think it ought to be: >>=20 >> for _modular_conf in /etc/rc.conf.d/*.conf; do >> [ -f "$_modular_conf" ] || continue >> debug "Sourcing $_modular_conf" >> . "$_modular_conf" >> done >>=20 >=20 > Keeping with the examples of the rest of the style of rc.subr and plenty= =20 > of other shell scripts here. This would be a distortion of the=20 > functionality that the original loop is doing and should be avoided. >=20 I've picked up this tid-bit over the years: 1. Since a conditional block causes all code within to be indented... 2. if you have a condition which can cause a continuance within a looping b= ock... 3. utilizing said conditional early-on can prevent unnecessary indentation = in the following lines. It's kind of moot for such a small example, but if you get to nesting 300+ = lines at multiple levels of nesting then it's worth re-evaluating the use o= f "early continuances". Here's the basic idea... for item in list; do : condition to continue : what the loop does done opposed to: for item in list; do if : condition to not continue; then : what the loop does fi done How about this half-and-half approach (actual code): for _modular_conf in /etc/rc.conf.d/*.conf; do if [ ! -f "$_modular_conf" ]; then continue fi debug "Sourcing $_modular_conf" . "$_modular_conf" done Of course, one's interpretation of the above syntax is conditional on memor= izing that "!" is pronounced "not" (just as my previous syntax hinges on me= morizing that "||" is pronounced "or"/"else" -- allowing either syntax to b= e read/interpreted with ease). Just thought I'd share my experiences. Not everyone develops the same style= (9) for every language. --=20 Devin _____________ The information contained in this message is proprietary and/or confidentia= l. If you are not the intended recipient, please: (i) delete the message an= d all copies; (ii) do not disclose, distribute or use the message in any ma= nner; and (iii) notify the sender immediately. In addition, please be aware= that any message addressed to our domain is subject to archiving and revie= w by persons other than the intended recipient. Thank you. _____________