From owner-freebsd-current@FreeBSD.ORG Wed May 23 09:12:02 2007 Return-Path: X-Original-To: freebsd-current@FreeBSD.ORG Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2614516A41F for ; Wed, 23 May 2007 09:12:02 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8]) by mx1.freebsd.org (Postfix) with ESMTP id 9837A13C468 for ; Wed, 23 May 2007 09:12:01 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (uhktgb@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id l4N9BsD3015398; Wed, 23 May 2007 11:12:00 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.4/8.13.1/Submit) id l4N9Bssl015397; Wed, 23 May 2007 11:11:54 +0200 (CEST) (envelope-from olli) Date: Wed, 23 May 2007 11:11:54 +0200 (CEST) Message-Id: <200705230911.l4N9Bssl015397@lurza.secnetix.de> From: Oliver Fromme To: freebsd-current@FreeBSD.ORG, "Ralf S. Engelschall" In-Reply-To: <20070523081749.GA18197@engelschall.com> X-Newsgroups: list.freebsd-current User-Agent: tin/1.8.2-20060425 ("Shillay") (UNIX) (FreeBSD/4.11-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Wed, 23 May 2007 11:12:00 +0200 (CEST) X-Mailman-Approved-At: Wed, 23 May 2007 11:48:15 +0000 Cc: Subject: Re: etc/rc.d/{var,tmp} and sub-shell usage?! X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-current@FreeBSD.ORG, "Ralf S. Engelschall" List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 May 2007 09:12:02 -0000 Ralf S. Engelschall wrote: > I've just stumbled over a confusing sub-shell usage in our > src/etc/rc.d/{var,tmp} scripts where I'm sure the sub-shells are totally > unnecessary and useless. I also do not see any difference under run-time > except that the sub-shell usage is slower, of course ;-) > > Nevertheless, I'm a little bit curious whether someone else sees _ANY_ > reason to keep those sub-shell constructs? If nobody has any objections > I would just cleanup these two scripts by removing the sub-shell > constructs... > [...] > [Nn][Oo]) > ;; > *) > - if (/bin/mkdir -p /tmp/.diskless 2> /dev/null); then > + if /bin/mkdir -p /tmp/.diskless 2> /dev/null; then > rmdir /tmp/.diskless > else > if [ -h /tmp ]; then Additionally, I think it's not a good idea to use "mkdir -p" to check if a directory is writable. If the directory already exists (for whatever reason), "mkdir -p" succeeds even if the file system is not writable. Normally you would use touch(1), but the problem is that touch is in /usr, so it might not be available in single-user mode (which is probably the reason why the original author used mkdir in the first place). The best solution is probably to use /bin/ln, and include the PID in the name to reduce the risk of accidental file name collisions. (Note that this code is running before the system is multi-user, so writing to /tmp as root doesn't introduce a security issue here, as far as I can tell.) test_file=/tmp/.diskless.$$ if /bin/ln -sf foo $test_file 2>/dev/null; then rm $test_file else [...] fi Well ... Thinking about it, there's a good chance that the PID is always the same during the boot sequence of scripts (some low number anyway), so maybe something like $(/bin/date +%s) should be used in the name of the test file instead od the PID. But maybe that's just overkill. Best regards Oliver PS: I also noticed that there's really a lot of redundant (i.e. superfluous) use of braces "${}" for variable expansion in the scripts, which makes them more difficult to read (IMHO). Is there some style guideline that requires it? Just wondering ... -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd One Unix to rule them all, One Resolver to find them, One IP to bring them all and in the zone to bind them.