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

Dave Reisner d at falconindy.com
Tue Aug 31 07:16:59 EDT 2010


On Tue, Aug 31, 2010 at 10:07:52AM +0200, Kurt J. Bosch wrote:
> --snip--
> 
> I suggest:
> 
> From b202be97f8dc1c0c68aaea792d4457c674c673f3 Mon Sep 17 00:00:00 2001
> From: Kurt J. Bosch <kjb-temp-2009 at alpenjodel.de>
> Date: Tue, 31 Aug 2010 09:57:47 +0200
> Subject: [PATCH 17/17] Correct behaviour of kill_everything()
> 
> ---
>  functions |   11 +++++------
>  1 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/functions b/functions
> index b9ba718..3ca7324 100644
> --- a/functions
> +++ b/functions
> @@ -205,10 +205,9 @@ ck_status() {
>  kill_everything() {
>      # $1 = where we are being called from.
>      # This is used to determine which hooks to run.
> -    # Find daemons NOT in the DAEMONS array. Shut these down first
> -    for daemon in /var/run/daemons/*; do
> -        [[ -f $daemon ]] || continue
> -        daemon=${daemon##*/}
> +    # Find daemons NOT in the DAEMONS array.
> +    # Shut these down first in reverse order.
> +    for daemon in $( /bin/ls -t /var/run/daemons ); do
>  	in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon"
>      done
> 
> @@ -220,7 +219,7 @@ kill_everything() {
> 
>  	# Terminate all processes
>      stat_busy "Sending SIGTERM To Processes"
> -    run_hook "$1_prekillall"
> +    run_hook "${1}_prekillall"
>      /sbin/killall5 -15 &> /dev/null
>      /bin/sleep 5
>      stat_done
> @@ -230,7 +229,7 @@ kill_everything() {
>      /bin/sleep 1
>      stat_done
> 
> -    run_hook "$1_postkillall"
> +    run_hook "${1}_postkillall"
>  }
> 
>  activate_vgs() {
> -- 
> 1.7.0.3
> 

Parsing the output of ls will never be better than using shell globbing
no matter how much simpler it might make the code appear to be. Not only
are you avoiding a fork, but the shell glob will properly handle any odd
characters thrown into the mix. You'll see breakage on something as
simple as a space in your suggestion. While I'm inclined to believe that
there will never be a space in the name of a daemon in Arch, if we're
going for pure Bash in this rewrite, let's use Bash instead of
mindlessly forking.

The only useful change here is to remove the line:

  [[ -f $daemon ]] || continue

and instead call 'shopt -s nullglob' outside the loop. Sorry for the
no-patch patch.

d


More information about the arch-general mailing list