Use a trap on 'ERR' to catch any error. Doing so introduces no side effects
as long as we don't use 'set -E' and do a 'trap - ERR' before returning
to restore what we had there before calling the function (if anything).

This avoids reporting '[DONE]' in spite of actions were done partly only.

Usecase:
Some splash system hides the console messages, but is able to detect '[FAIL]'
by overriding stat_fail().
---
 functions |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/functions b/functions
index fdf30fd..a3c3c5e 100644
--- a/functions
+++ b/functions
@@ -419,6 +419,8 @@ mount_all() {
 
 remove_leftover() {
        stat_busy "Removing Leftover Files"
+               local error=0
+               trap 'error=1' ERR
                rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.[^.]* 
/tmp/..?* /var/run/daemons
                [[ ! -L /var/lock ]] && rm -rf /var/lock/*
                if [[ ! -L /var/run && -d /var/run ]]; then
@@ -428,7 +430,9 @@ remove_leftover() {
                install -Tm 0664 -o root -g utmp <(:) /var/run/utmp
                # Keep {x,k,g}dm happy with xorg
                mkdir -m 1777 /tmp/.{X11,ICE}-unix
-       stat_done
+               trap - ERR
+       (( error )) && stat_fail || stat_done
+       return $error
 }
 
 bootlogd_stop() {
-- 
1.7.1

Reply via email to