On 4/11/07, Alexander E. Patrakov <[EMAIL PROTECTED]> wrote:
Dan Nicholson wrote:
> There is still another copy of pppd running when this occurs, right?

Yes.

> I think when I was testing things out I never actually had two copies of
> the process running. Could you see if the attached patch against SVN
> works correctly? Hopefully, this fixes the whole codepath to do the
> right thing.

The patch passes my testcase.

Later I realized what the [ -z "$killsig" ] was for. The subsequent
tests check whether the process is still running, but this isn't
appropriate is you just sent SIGHUP, for example. With my previous
patch, this could break some bootscripts that send a non terminating
signal through killproc, e.g.:

killproc process HUP

Although, in that case, it would probably be more appropriate to use
reloadproc. Still, I don't want to break the existing behavior, so I
changed the function a bit so that it will only check if the process
is still running if the signal is SIGTERM or SIGKILL. I don't know if
this is totally appropriate since I'm no signal expert.

Attached is the updated patch. I'd appreciate if you could test again.

--
Dan
Index: bootscripts/lfs/init.d/functions
===================================================================
--- bootscripts/lfs/init.d/functions	(revision 8042)
+++ bootscripts/lfs/init.d/functions	(working copy)
@@ -373,7 +373,7 @@
 		for pid in ${lpids}
 		do
 			if [ "${pid}" -ne "$$" -a "${pid}" -ne "${PPID}" ]; then
-				kill -0 "${pid}" > /dev/null &&
+				kill -0 "${pid}" 2>/dev/null &&
 				pidlist="${pidlist} ${pid}"
 			fi
 			
@@ -539,10 +539,10 @@
 killproc()
 {
 	local pidfile=""
-	local killsig=""
+	local killsig=TERM # default signal is SIGTERM
 	pidlist=""
 
-# This will ensure compatibility with previous LFS Bootscripts
+	# This will ensure compatibility with previous LFS Bootscripts
 	if [ -n "${PIDFILE}" ];	then
 		pidfile="${PIDFILE}"
 	fi
@@ -557,7 +557,7 @@
 			-*)
 				log_failure_msg "Unknown Option: ${1}"
 				return 2
-			;;
+				;;
 			*)
  				break
 				;;
@@ -572,18 +572,19 @@
 		return 2
 	fi
 
+	# Is the process running?
 	if [ -z "${pidfile}" ];	then
 		pidofproc -s "${1}"
 	else
 		pidofproc -s -p "${pidfile}" "${1}"
 	fi
 
-    # Change....
+    # If running, send the signal
     if [ -n "${pidlist}" ]; then
 	for pid in ${pidlist}
 	do
-		kill -${killsig:-TERM} ${pid} 2>/dev/null
-		if [ -z "${killsig}" ]; then
+		kill -${killsig} ${pid} 2>/dev/null
+		if [ "${killsig}" = TERM ]; then
 			# Wait up to 3 seconds, for ${pid} to terminate
 			local dtime=${KILLDELAY}
 			while [ "${dtime}" != "0" ]
@@ -597,12 +598,18 @@
 		fi
 	done
 
-	if [ -z "${killsig}" ];	then
-		pidofproc -s "${1}"
+	# Check if the process is still running if we tried to stop it
+	case "${killsig}" in
+	TERM|SIGTERM|KILL|SIGKILL)
+		if [ -z "${pidfile}" ];	then
+			pidofproc -s "${1}"
+		else
+			pidofproc -s -p "${pidfile}" "${1}"
+		fi
 
 		# Program was terminated
 		if [ "$?" != "0" ]; then
-			# Pidfile Exists
+			# Remove the pidfile if necessary
 			if [ -f "${pidfile}" ];	then
 				rm -f "${pidfile}"
 			fi
@@ -612,17 +619,9 @@
 			echo_failure
 			return 4 # Unknown Status
 		fi
-	else
-		if [ -z "${pidfile}" ];	then
-			pidofproc -s "${1}"
-		else
-			pidofproc -s -p "${pidfile}" "${1}"
-		fi
-	fi
-
-	evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
-
-    else
+		;;
+	esac
+    else # process not running
 	print_status warning not_running
     fi
 }
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to