[arch-projects] [initscripts] [PATCH 09/13] functions: Sanitize status() behaviour to make it more intuitive

Kurt J. Bosch kjb-temp-2009 at alpenjodel.de
Sun Jul 3 16:31:11 EDT 2011


* Refactor to return the actual exit code (and get rid of simple if construct)

The exit code returned by the given command might be useful/expected, so don't discard but return it.

* Do not redirect stdout/stderr, but allow the caller to do it

status() did stdout/stderr redirection to /dev/null when calling the given command since the very beginning (commit fd8fde03).
This is not as flexible and intuitive as it could be. It is much better to let the caller do any redirections wanted.
---
 functions |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/functions b/functions
index 70b4bcf..0c4c9b1 100644
--- a/functions
+++ b/functions
@@ -153,15 +153,16 @@ stat_die() {
 	exit ${1:-1}
 }
 
+# Avoid stolen messages if status() is called with stdout redirection
+exec {RC_FUNCTIONS_STDOUT_FD}>&1
+
 status() {
-	stat_busy "$1"
+	stat_busy "$1" >&${RC_FUNCTIONS_STDOUT_FD}
 	shift
-	if "$@" &>/dev/null; then
-		stat_done
-		return 0
-	fi
-	stat_fail
-	return 1
+	"$@"
+	local $ret=$?
+	{ (( $ret == 0 )) && stat_done || stat_fail ;} >&${RC_FUNCTIONS_STDOUT_FD}
+	return $ret
 }
 
 #  usage : in_array( $needle, $haystack )
-- 
1.7.1



More information about the arch-projects mailing list