[arch-projects] [initscripts] [PATCH 7/7] functions: Catch and report all errors in remove_leftover()

Kurt J. Bosch kjb-temp-2009 at alpenjodel.de
Mon Jul 11 17:43:48 EDT 2011


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



More information about the arch-projects mailing list