Author: dnicholson
Date: 2007-04-16 15:24:57 -0600 (Mon, 16 Apr 2007)
New Revision: 8072
Modified:
trunk/bootscripts/ChangeLog
trunk/bootscripts/lfs/init.d/functions
Log:
Make killproc work properly with signals and pidfiles
Modified: trunk/bootscripts/ChangeLog
===================================================================
--- trunk/bootscripts/ChangeLog 2007-04-16 21:18:52 UTC (rev 8071)
+++ trunk/bootscripts/ChangeLog 2007-04-16 21:24:57 UTC (rev 8072)
@@ -1,6 +1,11 @@
2007-04-16 Dan Nicholson <[EMAIL PROTECTED]>
* lfs/init.d/functions: Redirect stderr when using kill to suppress
output.
+ * lfs/init.d/functions: killproc() was not handling the case where a
+ pidfile is passed to the function. The logic with the signal to be
+ used was causing issues with the handling of pidfiles. This has been
+ fixes, and now killproc() will recheck the process if the signal
+ was TERM (the default) or KILL.
2007-03-13 Dan Nicholson <[EMAIL PROTECTED]>
* lfs/init.d/functions: If pidofproc() is passed the -p argument
Modified: trunk/bootscripts/lfs/init.d/functions
===================================================================
--- trunk/bootscripts/lfs/init.d/functions 2007-04-16 21:18:52 UTC (rev
8071)
+++ trunk/bootscripts/lfs/init.d/functions 2007-04-16 21:24:57 UTC (rev
8072)
@@ -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,19 +572,22 @@
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
- # Wait up to 3 seconds, for ${pid} to terminate
+ kill -${killsig} ${pid} 2>/dev/null
+
+ # Wait up to 3 seconds, for ${pid} to terminate
+ case "${killsig}" in
+ TERM|SIGTERM|KILL|SIGKILL)
local dtime=${KILLDELAY}
while [ "${dtime}" != "0" ]
do
@@ -594,15 +597,22 @@
done
# If ${pid} is still running, kill it
kill -0 ${pid} 2>/dev/null && kill -KILL ${pid}
2>/dev/null
- fi
+ ;;
+ esac
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 +622,13 @@
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
+ ;;
+ *)
+ # Just see if the kill returned successfully
+ evaluate_retval
+ ;;
+ esac
+ else # process not running
print_status warning not_running
fi
}
--
http://linuxfromscratch.org/mailman/listinfo/lfs-book
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page