Re: etc/rc.d/{var,tmp} and sub-shell usage?!

From: Doug Barton <dougb_at_FreeBSD.org>
Date: Wed, 23 May 2007 10:21:23 -0700 (PDT)
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
Received on Wed May 23 2007 - 15:21:26 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:10 UTC