[arch-projects] [initscripts] [PATCH 11/13] functions: Deprecate in_array(), Add replacement is_in_array()

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


* in_array() strips '@' and therefore the name is missleading.
* For checking DAEMONS, ck_autostart() should be used.
---
 functions |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/functions b/functions
index 0c4c9b1..7054f60 100644
--- a/functions
+++ b/functions
@@ -165,10 +165,23 @@ status() {
 	return $ret
 }
 
-#  usage : in_array( $needle, $haystack )
+#  usage : is_in_array( $needle, $haystack )
 # return : 0 - found
 #          1 - not found
+# Note: For checking DAEMONS, ck_autostart() should be used!
+is_in_array() {
+	local needle=$1; shift
+	local item
+	for item; do
+		[[ $item = $needle ]] && return 0
+	done
+	return 1 # Not Found
+}
+
+# This is deprecated!
+# It strips '@' and therefore the name is missleading.
 in_array() {
+	echo "WARNING: Call to deprecated function in_array() from $0" >&2
 	local needle=$1; shift
 	local item
 	for item; do
@@ -275,7 +288,7 @@ kill_everything() {
 	for daemon in /run/daemons/*; do
 		[[ -f $daemon ]] || continue
 		daemon=${daemon##*/}
-		in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon"
+		ck_autostart "$daemon" && stop_daemon "$daemon"
 	done
 
 	# Shutdown daemons in reverse order
-- 
1.7.1



More information about the arch-projects mailing list