From owner-freebsd-rc@FreeBSD.ORG Sun May 8 22:11:31 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 7BCA0106566C for ; Sun, 8 May 2011 22:11:31 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 1BC4A8FC0A for ; Sun, 8 May 2011 22:11:31 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id C8A22359324; Mon, 9 May 2011 00:11:29 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id B397117400; Mon, 9 May 2011 00:11:29 +0200 (CEST) Date: Mon, 9 May 2011 00:11:29 +0200 From: Jilles Tjoelker To: Garrett Cooper Message-ID: <20110508221129.GA89657@stack.nl> References: <20110508191336.GC3527@DataIX.net> <20110508202636.GF3527@DataIX.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Jason Hellenthal , 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 22:11:31 -0000 On Sun, May 08, 2011 at 02:19:17PM -0700, Garrett Cooper wrote: > >> Doing: > >> find /etc/rc.conf.d/ -type f -name '*.conf' -mindepth 1 -maxdepth 1 -perm +111 | while read _modular_conf; do > >> debug "Sourcing $_modular_conf" > >> . "$_modular_conf" > >> done > >> might 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. > >> Also, I don't know if depending on a .conf file to be executable is necessarily the best course of action. > > Yeah I see what you are getting at there and I came across thinking the > > 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 + for _modular_conf in /etc/rc.conf.d/*.conf; do + if [ -f "$_modular_conf" -a -x "$_modular_conf" ]; then + debug "Sourcing $_modular_conf" + . $_modular_conf + fi + done with a small change - . $_modular_conf + . "$_modular_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. 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. 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. -- Jilles Tjoelker