[PATCH 19/48] Simplify daemon-killing loops in rc.single.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Parsing the output of ls is Bad, especially when globbing works just as well
and does not get confused by odd characters in filenames.

bash has arithemetic for loops. Use them instead of while loops for iterating
over arrays.
---
 rc.single |   29 ++++++++++++-----------------
 1 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/rc.single b/rc.single
index aa58b4c..aa27be0 100755
--- a/rc.single
+++ b/rc.single
@@ -9,23 +9,18 @@
 run_hook single_start
 
 if [[ $PREVLEVEL != N ]]; then
-
-	# Find daemons NOT in the DAEMONS array. Shut these down first
-	if [[ -d /var/run/daemons ]]; then
-		for daemon in $(/bin/ls -1t /var/run/daemons); do
-		  if ! in_array $daemon ${DAEMONS[@]}; then
-				stop_daemon $daemon
-		  fi
-		done
-	fi
-	# Shutdown daemons in reverse order
-	let i=${#DAEMONS[@]}-1
-	while ((i >= 0)); do
-		if [[ ${DAEMONS[$i]:0:1} != '!' ]]; then
-			ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
-		fi
-		let i=i-1
-	done
+    # Find daemons NOT in the DAEMONS array. Shut these down first
+    for daemon in /var/run/daemons/*; do
+        [[ -f $daemon ]] || continue
+        daemon=${daemon##*/}
+	in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon"
+    done
+	
+    # Shutdown daemons in reverse order
+    for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do
+	[[ ${DAEMONS[$i]:0:1} = '!' ]] && continue
+	ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
+    done
 
 	# Terminate all processes
 	stat_busy "Sending SIGTERM To Processes"
-- 
1.7.1



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux