From owner-freebsd-rc@FreeBSD.ORG Sun May 8 23:25:15 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 55D071065674 for ; Sun, 8 May 2011 23:25:15 +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 0D3918FC18 for ; Sun, 8 May 2011 23:25:14 +0000 (UTC) Received: by vxc34 with SMTP id 34so7048612vxc.13 for ; Sun, 08 May 2011 16:25:14 -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:cc:content-type :content-transfer-encoding; bh=Ybuaf+TStQmDwnzIItLToLrbTj8927XeluYGUjg2M2I=; b=r4ugD+uw+CUJ9kV5hgYbDozUlIDCOji+FxJQBVKUuUaiCeF4gv4/hXA2UiZRujeHa8 Xx6aYsgdEpt8O1Pmam6pLBicYFBu+Wv5JNo5HO5dN7UdE8sGW5s8B/eFEVR9AUStpTmq iSnANDw0s64rTuIHgSsVjL3RHMk7/pwNm/iFA= 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 :cc:content-type:content-transfer-encoding; b=P6Ge0gN6iRAlX4ubYs/iwh6mLlHAV1g+nJ4m2ZSZ55XMj4cyyBlkz+J0a54sATcOw1 j8ZOmttupS3EhpcVGYV8nmz5ULQSTJMS1lsj9peditbFcrZjI6yItkG7o5LbybUFhRO2 FpvgyjYLwP3Od87ugrytTMq8i+ePQwxgzzb8Q= MIME-Version: 1.0 Received: by 10.52.181.168 with SMTP id dx8mr2071867vdc.172.1304897114223; Sun, 08 May 2011 16:25:14 -0700 (PDT) Received: by 10.220.202.134 with HTTP; Sun, 8 May 2011 16:25:14 -0700 (PDT) In-Reply-To: <20110508221129.GA89657@stack.nl> References: <20110508191336.GC3527@DataIX.net> <20110508202636.GF3527@DataIX.net> <20110508221129.GA89657@stack.nl> Date: Sun, 8 May 2011 16:25:14 -0700 Message-ID: From: Garrett Cooper To: Jilles Tjoelker Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: 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: Sun, 08 May 2011 23:25:15 -0000 On Sun, May 8, 2011 at 3:11 PM, Jilles Tjoelker wrote: > On Sun, May 08, 2011 at 02:19:17PM -0700, Garrett Cooper wrote: >> >> =A0 =A0Doing: > >> >> find /etc/rc.conf.d/ -type f -name '*.conf' -mindepth 1 -maxdepth 1 -= perm +111 | while read _modular_conf; do >> >> =A0 =A0debug "Sourcing $_modular_conf" >> >> =A0 =A0. "$_modular_conf" >> >> done > >> >> =A0 =A0might be better. There's some more magic that could ultimately= be done to make this more secure/robust using "-print0" | xargs, but it's = up to you how you might want to go about solving that problem. >> >> =A0 =A0Also, I don't know if depending on a .conf file to be executab= le is necessarily the best course of action. > >> > Yeah I see what you are getting at there and I came across thinking th= e >> > same thing. Fortunately /etc/rc.conf.d/*.conf is only one level deep >> > without using find(1). > >> Yes, but the above method used avoids simple E2BIG problems. It just >> doesn't properly deal with filenames that break on IFS, etc though >> (that's part of where I was leading, but I said "security" instead. > > I would say the opposite. jhell's original loop > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 for _modular_conf in /etc/rc.conf.d/*.conf;= do > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if [ -f "$_modular_conf" -a= -x "$_modular_conf" ]; then > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 debug "Sour= cing $_modular_conf" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 . $_modular= _conf > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 done > > with a small change > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 . $_modular= _conf > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 . "$_modula= r_conf" > > does not have any E2BIG problems, and also no problems with special > characters. This is because the list of pathnames stays within sh; it is > not passed to another program. If there is no matching file, the loop > runs once for /etc/rc.conf.d/*.conf which does not exist and is > therefore not sourced. Hmmm... ok. Didn't realize that. As a bonus point -- is that an extension of our shell, or is this standard behavior in all shells? > Any 'while read...' loop will handle pathnames with newlines > incorrectly, and the simple ones also handle backslashes and certain > whitespace incorrectly. Also, the proposed pipeline does not even work > as the while loop is executed in a subshell, so the assignments in the > sourced files are lost. Ah drat... I forgot that our shell does subshells with pipelines. Thanks Jilles for the correction ><.. > This post is not an endorsement of jhell's idea. I am not really > convinced it is useful. For experimenting, the for command can be placed > in /etc/rc.conf. -Garrett