Tom Gundersen, 2011-07-10 22:11:
On Sun, Jul 10, 2011 at 6:57 PM, Kurt J. Bosch
<[email protected]> wrote:
Rationale:
Instead of ignoring any errors of all commands but the last within a status
block it is much better to use trap to catch them and report 'FAIL'. One
might for example miss the utmp group which is needed to propperly install
/var/run/utmp.
This also makes the code a bit more simple and readable.
Note:
We enable this explicitely (by calling stat_err_trap) because most daemon
scriptlets don't work well with this by now. Moreover we don't use 'set -E'
to avoid breaking/complicating [custom/hook] functions.
I think this is too complicated for too little gain, especially if it
will not work everywhere and has to be enabled explicitly. We should
avoid being too clever I think. If we want to check for more exit
statuses we should add more " || stat_fail".
-t
OK here we go:
1st alternative
-----------------
functions:
stat_done() {
printf ...
STAT_ERR=0
}
stat_fail() {
printf ...
STAT_ERR=1
}
stat_done() {
(( STAT_ERR )) && return 0
printf ...
}
rc.sysinit:
stat_busy "Removing Leftover Files"
rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.[^.]*
/tmp/..?* /var/run/daemons || stat_fail
[[ ! -L /var/lock ]] && rm -rf /var/lock/* || stat_fail
if [[ ! -L /var/run && -d /var/run ]]; then
find /var/run/ \! -type d -delete || stat_fail
ln -s /run/daemons /var/run/daemons || stat_fail
fi
install -Tm 0664 -o root -g utmp <(:) /var/run/utmp || stat_fail
# Keep {x,k,g}dm happy with xorg
mkdir -m 1777 /tmp/.{X11,ICE}-unix || stat_fail
stat_done
2nd alternative
-----------------
rc.sysinit:
stat_busy "Removing Leftover Files"; e=0
rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.[^.]*
/tmp/..?* /var/run/daemons || e=1
[[ ! -L /var/lock ]] && rm -rf /var/lock/* || e=1
if [[ ! -L /var/run && -d /var/run ]]; then
find /var/run/ \! -type d -delete || e=1
ln -s /run/daemons /var/run/daemons || e=1
fi
install -Tm 0664 -o root -g utmp <(:) /var/run/utmp || e=1
# Keep {x,k,g}dm happy with xorg
mkdir -m 1777 /tmp/.{X11,ICE}-unix || e=1
(( e )) && stat_fail || stat_done
Both look very ugly and are even more complicated IMHO.
I admit this is not really urgent as long as no bug reports arise which
would suggest catching more errors.
--
Kurt