DJ Lucas wrote:
I'll hack up a
tenative patch real quick, but do know that it's 3:00AM here and will be
completely untested. If somebody can reproduce the problem easily, and
test the patch, that would be great, otherwise I can test it tomorrow.
Scratch most of that...I put the -s flag back in and reused pidlist and
just renamed my pidlist pidslist.
It works in my head, it might work without modification. :-) See
attached...
-- DJ Lucas
Index: functions
===================================================================
--- functions (revision 8496)
+++ functions (working copy)
@@ -399,84 +399,89 @@
#*******************************************************************************
pidofproc()
{
- local pidfile=""
- local lpids=""
- local silent=""
- pidlist=""
- while true
- do
- case "${1}" in
- -p)
- pidfile="${2}"
- shift 2
- ;;
- -s)
- # Added for legacy opperation of getpids
- # eliminates several '> /dev/null'
- silent="1"
- shift 1
- ;;
- -*)
- log_failure_msg "Unknown Option: ${1}"
- return 2
- ;;
- *)
- break
- ;;
- esac
- done
+local pidfile
+local program
+local prefix
+local progname
+local pidslist
+local lpids
+local silent
+pidlist=""
- if [ "${#}" != "1" ]; then
- shift 1
- log_failure_msg "Usage: pidofproc [-s] [-p pidfile] pathname"
- return 2
- fi
+ # Process arguments
+ while true
+ do
+ case "${1}" in
- if [ -n "${pidfile}" ]; then
- if [ ! -r "${pidfile}" ]; then
- return 3 # Program is not running
- fi
+ -p)
+ pidfile="${2}"
+ shift 2
+ ;;
- lpids=`head -n 1 ${pidfile}`
- for pid in ${lpids}
- do
- if [ "${pid}" -ne "$$" -a "${pid}" -ne "${PPID}" ]; then
- kill -0 "${pid}" 2>/dev/null &&
- pidlist="${pidlist} ${pid}"
- fi
-
- if [ "${silent}" != "1" ]; then
- echo "${pidlist}"
- fi
+ -s)
+ silent="1"
+ shift 1
+ ;;
+ *)
+ program="${1}"
+ if [ -n "${2}" ]
+ then
+ # Too many arguments
+ # Since this is status, return unknown
+ return 4
+ else
+ break
+ fi
+ ;;
+ esac
+ done
- test -z "${pidlist}" &&
- # Program is dead, pidfile exists
- return 1
- # else
- return 0
- done
+ # If a PID file is not specified, try and find one.
+ if [ -z "${pidfile}" ]
+ then
+ # get the program's basename
+ prefix=`echo "${program}" | sed 's/[^/]*$//'`
+ progname=`echo "${program}" | sed "[EMAIL PROTECTED]@@"`
+ # if a PID file exists with that name, assume that is it.
+ if [ -e "/var/run/${progname}.pid" ]
+ then
+ pidfile="/var/run/${progname}.pid"
+ fi
+ fi
- else
- pidlist=`pidof -o $$ -o $PPID -x "$1"`
- if [ "${silent}" != "1" ]; then
- echo "${pidlist}"
- fi
+ # if a PID file is set and exists, use it.
+ if [ -n "${pidfile}" -a -e "${pidfile}" ]
+ then
+ # use the value in the first line of the pidfile
+ pidslist=`/bin/head -n1 "${pidfile}"`
+ # This can optionally be written as 'sed 1q' to repalce 'head -n1'
+ # should LFS move /bin/head to /usr/bin/head
+ else
+ # use pidof
+ pidslist=`pidof "${program}"`
+ fi
- # Get provide correct running status
- if [ -n "${pidlist}" ]; then
- return 0
- else
- return 3
- fi
+ # Figure out if all listed PIDs are running.
+ for pid in ${pidslist}
+ do
+ kill -0 ${pid} 2> /dev/null
+ if [ "${?}" = "0" ]; then
+ lpids="${pids}${pid} "
+ fi
+ done
- fi
-
- if [ "$?" != "0" ]; then
- return 3 # Program is not running
- fi
+ if [ -z "${lpids}" -a -z "${pidfile}" ]; then
+ return 3
+ else
+ pidlist=`echo "${lpids}"`
+ if [ "${silent}" != "1" ]; then
+ echo "${lpids}"
+ fi
+ fi
}
+
# This will ensure compatibility with previous LFS Bootscripts
getpids()
{
@@ -610,6 +615,7 @@
local pidfile=""
local killsig=TERM # default signal is SIGTERM
pidlist=""
+}
# This will ensure compatibility with previous LFS Bootscripts
if [ -n "${PIDFILE}" ]; then
--
http://linuxfromscratch.org/mailman/listinfo/lfs-book
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page