From owner-freebsd-current@FreeBSD.ORG Wed May 23 17:21:26 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 BF3C916A469 for ; Wed, 23 May 2007 17:21:26 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from mail2.fluidhosting.com (mx24.fluidhosting.com [204.14.89.7]) by mx1.freebsd.org (Postfix) with SMTP id 78A8813C48C for ; Wed, 23 May 2007 17:21:26 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: (qmail 12464 invoked by uid 399); 23 May 2007 17:21:25 -0000 Received: from localhost (HELO ?192.168.0.4?) (dougb@dougbarton.us@127.0.0.1) by localhost with SMTP; 23 May 2007 17:21:25 -0000 X-Originating-IP: 127.0.0.1 Date: Wed, 23 May 2007 10:21:23 -0700 (PDT) From: Doug Barton To: freebsd-current@FreeBSD.ORG, "Ralf S. Engelschall" In-Reply-To: <200705230911.l4N9Bssl015397@lurza.secnetix.de> Message-ID: <20070523101529.K46653@ync.qbhto.arg> References: <200705230911.l4N9Bssl015397@lurza.secnetix.de> Organization: http://www.FreeBSD.org/ X-OpenPGP-Key-ID: 0xD5B2F0FB X-message-flag: Outlook -- Not just for spreading viruses anymore! MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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 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 17:21:26 -0000 On Wed, 23 May 2007, Oliver Fromme wrote: > 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 ;-) Those (and any similar) should go away. Thanks for catching this. > 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. > > 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.) Using 'echo > file' will work just as well, and avoid the cost of invoking ln. > 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). Sorry, but "more difficult to read" is a spurious argument. Braces are part of shell scripting, get used to it. :) > Is there some > style guideline that requires it? Just wondering ... Not explicitly, but a lot of the stuff we imported from NetBSD had braces that weren't strictly necessary, and that style has been perpetuated. Personally I tend to include braces more often than they are actually needed since it helps insure against those times when they ARE needed and I forget to add them. :) Doug -- This .signature sanitized for your protection