[arch-general] [PATCH 21/48] Both rc.single and rc.shutdown use the same code to kill everything.

Victor Lowther victor.lowther at gmail.com
Wed Jun 30 17:47:43 EDT 2010


Move that shared code into functions.
---
 functions   |   29 +++++++++++++++++++++++++++++
 rc.shutdown |   32 +-------------------------------
 rc.single   |   27 +--------------------------
 3 files changed, 31 insertions(+), 57 deletions(-)

diff --git a/functions b/functions
index d8e8e54..bf6ed45 100644
--- a/functions
+++ b/functions
@@ -203,6 +203,35 @@ ck_status() {
   fi
 }
 
+kill_everything() {
+    # 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"
+    run_hook single_prekillall
+    /sbin/killall5 -15 &> /dev/null
+    /bin/sleep 5
+    stat_done
+    
+    stat_busy "Sending SIGKILL To Processes"
+    /sbin/killall5 -9 &> /dev/null
+    /bin/sleep 1
+    stat_done
+
+    run_hook single_postkillall
+}
+
 ###############################
 # Custom hooks in initscripts #
 ###############################
diff --git a/rc.shutdown b/rc.shutdown
index 002a45d..ef9b16d 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -19,37 +19,7 @@ echo " "
 [[ -x /bin/domainname ]] && /bin/domainname ""
 [[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown
 
-
-# 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 -ge 0 ]; do
-	if [ "${DAEMONS[$i]:0:1}" != '!' ]; then
-		ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
-	fi
-	let i=i-1
-done
-
-# Terminate all processes
-stat_busy "Sending SIGTERM To Processes"
-run_hook shutdown_prekillall
-/sbin/killall5 -15 &> /dev/null
-/bin/sleep 5
-stat_done
-
-stat_busy "Sending SIGKILL To Processes"
-/sbin/killall5 -9 &> /dev/null
-/bin/sleep 1
-stat_done
-
-run_hook shutdown_postkillall
+kill_everything
 
 stat_busy "Saving Random Seed"
 RANDOM_SEED=/var/lib/misc/random-seed
diff --git a/rc.single b/rc.single
index aa27be0..a84ece8 100755
--- a/rc.single
+++ b/rc.single
@@ -9,33 +9,8 @@
 run_hook single_start
 
 if [[ $PREVLEVEL != N ]]; then
-    # 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"
-	run_hook single_prekillall
-	/sbin/killall5 -15 &> /dev/null
-	/bin/sleep 5
-	stat_done
-
-	stat_busy "Sending SIGKILL To Processes"
-	/sbin/killall5 -9 &> /dev/null
-	/bin/sleep 1
-	stat_done
-
-	run_hook single_postkillall
 
+        kill_everything
 	stat_busy "Starting UDev Daemon"
 	/sbin/udevd --daemon
 	stat_done
-- 
1.7.1



More information about the arch-general mailing list