FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux General Discussion

 
 
LinkBack Thread Tools
 
Old 06-30-2010, 09:47 PM
Victor Lowther
 
Default Simplify daemon-killing loops in rc.single.

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
 

Thread Tools




All times are GMT. The time now is 08:18 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org