Date: Wed, 23 May 2007 11:11:54 +0200 (CEST) From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-current@FreeBSD.ORG, "Ralf S. Engelschall" <rse@FreeBSD.ORG> Subject: Re: etc/rc.d/{var,tmp} and sub-shell usage?! Message-ID: <200705230911.l4N9Bssl015397@lurza.secnetix.de> In-Reply-To: <20070523081749.GA18197@engelschall.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200705230911.l4N9Bssl015397>