--- /etc/init.d/functions.orig	2007-08-24 12:34:35 +0400
+++ /etc/init.d/functions	2007-08-24 12:34:24 +0400
@@ -237,7 +237,7 @@
 
 stop_daemon()
 {
-	local ANNOUNCE BASENAME CMDNAME DEFAULT DISPNAME EXPECT FLAGS HUPSIG LOCKFILE MESSAGE NAME PIDFILE SIGNAL STATUS WHICH
+	local ANNOUNCE BASENAME CMDNAME DEFAULT DISPNAME EXPECT FLAGS HUPSIG LOCKFILE MESSAGE NAME PIDFILE SIGNAL STATUS WHICH TIMEOUT
 
 # Process options.
 	ANNOUNCE=1
@@ -248,6 +248,7 @@
 	LOCKFILE=
 	NAME=
 	PIDFILE=
+	TIMEOUT=1
 # start-stop-daemon wants a signal number.
 	SIGNAL="$(kill -l TERM)" || SIGNAL=15
 	HUPSIG="$(kill -l HUP)" || HUPSIG=1
@@ -292,6 +293,11 @@
 			PIDFILE="$1"
 			shift
 			;;
+		--timeout)
+			shift
+			TIMEOUT="$1"
+			shift
+			;;
 		-[0-9]*)
 			SIGNAL="${1##-}"
 			DEFAULT=false
@@ -372,11 +378,19 @@
 # custom signal.
 	if [ "$DEFAULT" = true -a $STATUS -eq 0 ]; then
 		usleep 100000
-		if start-stop-daemon $FLAGS --test > /dev/null; then
-			sleep 1
-			SIGNAL="$(kill -l KILL)" || SIGNAL=9
-			start-stop-daemon $FLAGS --signal "$SIGNAL" > /dev/null
-		fi
+		for ((i=1; i <= TIMEOUT ; i++))
+		do
+			if start-stop-daemon $FLAGS --test > /dev/null; then
+				sleep 1
+				if [ $i == $TIMEOUT  ]; then
+					SIGNAL="$(kill -l KILL)" || SIGNAL=9
+					start-stop-daemon $FLAGS --signal "$SIGNAL" > /dev/null
+				fi
+			else
+				break
+			fi
+			
+		done
 		[ -z "$PIDFILE" ] || rm -f "$PIDFILE"
 	fi