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

2010-09-01 Thread Kurt J. Bosch

2010-08-31 13:16, Dave Reisner:

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. Boschkjb-temp-2...@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 ${daemo...@]} || 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.

NAK. The patch just reverts breaking of the current behaviour which is 
shutdown daemons in reverse order of start. AFAIK bash globbing is 
unable to sort on timestamps, right? p




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

2010-09-01 Thread Victor Lowther
On Wed, Sep 1, 2010 at 5:41 AM, Kurt J. Bosch
kjb-temp-2...@alpenjodel.de wrote:
 2010-08-31 13:16, Dave Reisner:

 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. Boschkjb-temp-2...@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 ${daemo...@]} || 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.

 NAK. The patch just reverts breaking of the current behaviour which is
 shutdown daemons in reverse order of start. AFAIK bash globbing is unable to
 sort on timestamps, right?

Bash globbing cannot handle it, but bash knows how to test file
timestamps, so we could code something up that handles killing the
daemons in reverse timestamp order if we had to. However, there is no
reason to think that the order is significant for daemons not in
$DAEMONS.  If there are any dependencies that this code does not
handle gracefully, the offending daemons will be killed when we kill
-15 and then kill -9 the rest of the processes.  If a daemon does not
handle SIGTERM gracefully because of dependency issues, it has other,
more significant problems.


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

2010-09-01 Thread Kurt J. Bosch

2010-09-01 13:03, Dave Reisner:


The _current_ behavior doesn't define an order unless its in DAEMONS.
I've reverted _your_ behavior, which I don't feel has proper
justification.

I referred to extras/initscripts which indeed does. Please read the 
code: 
http://projects.archlinux.org/initscripts.git/tree/rc.shutdown?id=2010.07-1



Suppose I start daemons foo, bar and baz (in that order) after Arch
boots. Why then, should the shutdown order of these daemons change
merely because I had to restart bar, which is independent of foo and
baz?

Because you know which is the right order and rc.shutdown just rolls 
back what you did. ^^






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

2010-09-01 Thread Kurt J. Bosch

2010-09-01 17:29, Victor Lowther:


Bash globbing cannot handle it, but bash knows how to test file
timestamps, so we could code something up that handles killing the
daemons in reverse timestamp order if we had to. However, there is no
reason to think that the order is significant for daemons not in
$DAEMONS.  If there are any dependencies that this code does not
handle gracefully, the offending daemons will be killed when we kill
-15 and then kill -9 the rest of the processes.  If a daemon does not
handle SIGTERM gracefully because of dependency issues, it has other,
more significant problems.

I really don't know if this 'feature' is actually still wanted or 
needed, but I feel it should be dropped in a separate commit if ever. :)




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

2010-09-01 Thread Dave Reisner
On Wed, Sep 01, 2010 at 07:30:45PM +0200, Kurt J. Bosch wrote:
 2010-09-01 13:03, Dave Reisner:
 
 The _current_ behavior doesn't define an order unless its in DAEMONS.
 I've reverted _your_ behavior, which I don't feel has proper
 justification.
 
 I referred to extras/initscripts which indeed does. Please read the
 code: 
 http://projects.archlinux.org/initscripts.git/tree/rc.shutdown?id=2010.07-1
 

Indeed, I was mistaken. However, I still stand by the idea that trying
to parse the output of /bin/ls is flawed from the ground up. ls is made
for human parsing, not programatical parsing.

 Suppose I start daemons foo, bar and baz (in that order) after Arch
 boots. Why then, should the shutdown order of these daemons change
 merely because I had to restart bar, which is independent of foo and
 baz?
 
 Because you know which is the right order and rc.shutdown just rolls
 back what you did. ^^
 
 

No, rc.shutdown does _not_ know the right order. The current behavior is
broken. Example:

1) start network
2) start rpcbind
3) start nfs-common
4) restart network

network now shuts down first, rendering the OS unable to cleanly close
any outstanding nfs shares. This commonly results in a long hang at
shutdown and the possibility of truncated files.

d


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

2010-09-01 Thread Kurt J. Bosch

2010-09-01 22:52, Dave Reisner:

On Wed, Sep 01, 2010 at 07:30:45PM +0200, Kurt J. Bosch wrote:

2010-09-01 13:03, Dave Reisner:


The _current_ behavior doesn't define an order unless its in DAEMONS.
I've reverted _your_ behavior, which I don't feel has proper
justification.


I referred to extras/initscripts which indeed does. Please read the
code: 
http://projects.archlinux.org/initscripts.git/tree/rc.shutdown?id=2010.07-1



Indeed, I was mistaken. However, I still stand by the idea that trying
to parse the output of /bin/ls is flawed from the ground up. ls is made
for human parsing, not programatical parsing.


Suppose I start daemons foo, bar and baz (in that order) after Arch
boots. Why then, should the shutdown order of these daemons change
merely because I had to restart bar, which is independent of foo and
baz?


Because you know which is the right order and rc.shutdown just rolls
back what you did. ^^




No, rc.shutdown does _not_ know the right order. The current behavior is
broken. Example:

1) start network
2) start rpcbind
3) start nfs-common
4) restart network

network now shuts down first, rendering the OS unable to cleanly close
any outstanding nfs shares. This commonly results in a long hang at
shutdown and the possibility of truncated files.

That's exactly what I meant. _You_ should now what you're doing and 
rc.shutdown tries its best afterwards. There is no real daemons 
dependency handling in Arch (probably because of KISS) so we can't 
expect it does always the right thing, but at least without the restart 
it would do in your example and that's better than nothing (random 
order) isn't it? :)





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

2010-09-01 Thread Dave Reisner
On Thu, Sep 02, 2010 at 01:53:20AM +0200, Kurt J. Bosch wrote:
 2010-09-01 22:52, Dave Reisner:
 On Wed, Sep 01, 2010 at 07:30:45PM +0200, Kurt J. Bosch wrote:
 2010-09-01 13:03, Dave Reisner:
 
 The _current_ behavior doesn't define an order unless its in DAEMONS.
 I've reverted _your_ behavior, which I don't feel has proper
 justification.
 
 I referred to extras/initscripts which indeed does. Please read the
 code: 
 http://projects.archlinux.org/initscripts.git/tree/rc.shutdown?id=2010.07-1
 
 
 Indeed, I was mistaken. However, I still stand by the idea that trying
 to parse the output of /bin/ls is flawed from the ground up. ls is made
 for human parsing, not programatical parsing.
 
 Suppose I start daemons foo, bar and baz (in that order) after Arch
 boots. Why then, should the shutdown order of these daemons change
 merely because I had to restart bar, which is independent of foo and
 baz?
 
 Because you know which is the right order and rc.shutdown just rolls
 back what you did. ^^
 
 
 
 No, rc.shutdown does _not_ know the right order. The current behavior is
 broken. Example:
 
 1) start network
 2) start rpcbind
 3) start nfs-common
 4) restart network
 
 network now shuts down first, rendering the OS unable to cleanly close
 any outstanding nfs shares. This commonly results in a long hang at
 shutdown and the possibility of truncated files.
 
 That's exactly what I meant. _You_ should now what you're doing and
 rc.shutdown tries its best afterwards. There is no real daemons
 dependency handling in Arch (probably because of KISS) so we can't
 expect it does always the right thing, but at least without the
 restart it would do in your example and that's better than nothing
 (random order) isn't it? :)
 
 

Isn't the KISS solution just to add the thing to the DAEMONS array?

We're clearly in disagreement, and this is getting a little circular.
I'm going to bow out from this gracefully -- the devs can resolve this
as they see fit.



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

2010-08-31 Thread Kurt J. Bosch

2010-07-02 11:27, Thomas Bächler:

First of all, sorry for not continuing the review yesterday, time is
short :(

Still, I'll finish this, as I'd like to have this applied eventually.

Am 02.07.2010 11:21, schrieb Kurt J. Bosch:

Am 2010-06-30 23:47, schrieb Victor Lowther:

Move that shared code into functions.
+run_hook single_prekillall


This line should be  run_hook ${0##*/rc.}_prekillall  IMHO


Kurt is right here. We call this code from rc.single and rc.shutdown I
think. We use two distinct hooks, you can register functions for these
hooks independently!



Hmm, git bashification-redux has now:

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##*/}
in_array $daemon ${daemo...@]} || stop_daemon $daemon
done

# Shutdown daemons in reverse order
for ((i=${#daemo...@]}-1; i=0; i--)); do
[[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
done

# Terminate all processes
stat_busy Sending SIGTERM To Processes
run_hook $1_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 $1_postkillall
}

I suggest:

From b202be97f8dc1c0c68aaea792d4457c674c673f3 Mon Sep 17 00:00:00 2001
From: Kurt J. Bosch kjb-temp-2...@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 ${daemo...@]} || 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



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

2010-08-31 Thread Dave Reisner
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-2...@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 ${daemo...@]} || 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


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

2010-07-02 Thread Kurt J. Bosch

Am 2010-06-30 23:47, schrieb Victor Lowther:

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 ${daemo...@]} || stop_daemon $daemon
+done
+   
+# Shutdown daemons in reverse order
+for ((i=${#daemo...@]}-1; i=0; i--)); do
+   [[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
+   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
+done
+
+   # Terminate all processes
+stat_busy Sending SIGTERM To Processes
+run_hook single_prekillall


This line should be  run_hook ${0##*/rc.}_prekillall  IMHO



+/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


Similar as above.


+}
+
  ###
  # 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 ${daemo...@]}; then
-   stop_daemon $daemon
-   fi
-   done
-fi
-# Shutdown daemons in reverse order
-let i=${#daemo...@]}-1
-while [ $i -ge 0 ]; do
-   if [ ${DAEMONS[$i]:0:1} != '!' ]; then
-   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
-   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 ${daemo...@]} || stop_daemon $daemon
-done
-   
-# Shutdown daemons in reverse order
-for ((i=${#daemo...@]}-1; i=0; i--)); do
-   [[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
-   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
-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





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

2010-07-02 Thread Thomas Bächler
First of all, sorry for not continuing the review yesterday, time is
short :(

Still, I'll finish this, as I'd like to have this applied eventually.

Am 02.07.2010 11:21, schrieb Kurt J. Bosch:
 Am 2010-06-30 23:47, schrieb Victor Lowther:
 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 ${daemo...@]} || stop_daemon $daemon
 +done
 +   
 +# Shutdown daemons in reverse order
 +for ((i=${#daemo...@]}-1; i=0; i--)); do
 +[[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
 +ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
 +done
 +
 +# Terminate all processes
 +stat_busy Sending SIGTERM To Processes
 +run_hook single_prekillall
 
 This line should be  run_hook ${0##*/rc.}_prekillall  IMHO

Kurt is right here. We call this code from rc.single and rc.shutdown I
think. We use two distinct hooks, you can register functions for these
hooks independently!



signature.asc
Description: OpenPGP digital signature


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

2010-06-30 Thread Victor Lowther
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 ${daemo...@]} || stop_daemon $daemon
+done
+   
+# Shutdown daemons in reverse order
+for ((i=${#daemo...@]}-1; i=0; i--)); do
+   [[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
+   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
+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 ${daemo...@]}; then
-   stop_daemon $daemon
-   fi
-   done
-fi
-# Shutdown daemons in reverse order
-let i=${#daemo...@]}-1
-while [ $i -ge 0 ]; do
-   if [ ${DAEMONS[$i]:0:1} != '!' ]; then
-   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
-   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 ${daemo...@]} || stop_daemon $daemon
-done
-   
-# Shutdown daemons in reverse order
-for ((i=${#daemo...@]}-1; i=0; i--)); do
-   [[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
-   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
-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