Date: Wed, 23 May 2007 10:21:23 -0700 (PDT)
From: Doug Barton <dougb@FreeBSD.org>
To: freebsd-current@FreeBSD.ORG, "Ralf S. Engelschall" <rse@FreeBSD.ORG>
Subject: Re: etc/rc.d/{var,tmp} and sub-shell usage?!
Message-ID: <20070523101529.K46653@ync.qbhto.arg>
In-Reply-To: <200705230911.l4N9Bssl015397@lurza.secnetix.de>
References: <200705230911.l4N9Bssl015397@lurza.secnetix.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070523101529.K46653>
