Attached is a series of patches that hopefully resolves all the issues
below. The functions seem to work fine in my testing. I'll describe
them a bit below.
Patch 1 is just a simple fixup to suppress output from kill and
matches other locations in the functions where stderr from kill -0 is
redirected to /dev/null.
On 4/10/07, Alexander E. Patrakov <[EMAIL PROTECTED]> wrote:
Dan Nicholson wrote:
>
> 1. Make statusproc() return unsuccessfully if the process isn't running
+1
Patch 4. The return value from pidofproc is used.
> 2. Make statusproc() use pidofproc() instead of the deprecated getpids()
+1
> 3. Allow the -p pidfile argument to all *proc() functions
+1
These are spread across patches 2, 3 and 5. They affect killproc,
reloadproc and statusproc. reloadproc and statusproc were using
getpids, so I copied the input processing for -p and/or $PIDFILE from
killproc.
> 4. Add the /sbin/service script to allow an agnostic way to query the
> bootscripts
+0
Punting this for now since no one has shown any great interest.
5. Apply the patch from
http://linuxfromscratch.org/pipermail/lfs-dev/2006-October/058454.html -
also needed for hibernation on the LiveCD when the non-standard
implementation of the PPPoE network service is used.
As described elsewhere in this thread, the logic was just broken a bit
in killproc. This fix is rolled into patch 2 so that the handling of
pidfiles and different signals is handled appropriately.
Let me know what you think.
--
Dan
From cf62e9213e661e000749146fee1094744ca024ad Mon Sep 17 00:00:00 2001
From: Dan Nicholson <[EMAIL PROTECTED]>
Date: Wed, 11 Apr 2007 14:47:39 -0700
Subject: [PATCH 1/5] Redirect stderr when using kill to suppress output
---
bootscripts/lfs/init.d/functions | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/bootscripts/lfs/init.d/functions b/bootscripts/lfs/init.d/functions
index 29a9933..032818d 100644
--- a/bootscripts/lfs/init.d/functions
+++ b/bootscripts/lfs/init.d/functions
@@ -373,7 +373,7 @@ pidofproc()
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
--
1.5.0.6
From 6b2fb2df206078c718e1e4fdd7516a9c959fefce Mon Sep 17 00:00:00 2001
From: Dan Nicholson <[EMAIL PROTECTED]>
Date: Wed, 11 Apr 2007 14:56:05 -0700
Subject: [PATCH 2/5] Make killproc work properly with signals and pidfiles
---
bootscripts/lfs/init.d/functions | 50 +++++++++++++++++++++----------------
1 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/bootscripts/lfs/init.d/functions b/bootscripts/lfs/init.d/functions
index 032818d..0473e6a 100644
--- a/bootscripts/lfs/init.d/functions
+++ b/bootscripts/lfs/init.d/functions
@@ -539,10 +539,10 @@ loadproc()
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 @@ killproc()
-*)
log_failure_msg "Unknown Option: ${1}"
return 2
- ;;
+ ;;
*)
break
;;
@@ -572,19 +572,22 @@ killproc()
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 @@ killproc()
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 @@ killproc()
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
}
--
1.5.0.6
From e421f92b8ca64059e7bba321ce1952bb52e08ca1 Mon Sep 17 00:00:00 2001
From: Dan Nicholson <[EMAIL PROTECTED]>
Date: Wed, 11 Apr 2007 15:10:15 -0700
Subject: [PATCH 3/5] Use pidofproc and respect pidfiles in statusproc
---
bootscripts/lfs/init.d/functions | 47 ++++++++++++++++++++++++++++++++-----
1 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/bootscripts/lfs/init.d/functions b/bootscripts/lfs/init.d/functions
index 0473e6a..33195b6 100644
--- a/bootscripts/lfs/init.d/functions
+++ b/bootscripts/lfs/init.d/functions
@@ -279,13 +279,46 @@ reloadproc()
statusproc()
{
- if [ "${#}" = "0" ]
- then
- echo "Usage: statusproc {program}"
- exit 1
+ local pidfile=""
+ local base=""
+
+ while true
+ do
+ case "${1}" in
+ -p)
+ pidfile="${2}"
+ shift 2
+ ;;
+ -*)
+ log_failure_msg "Unknown Option: ${1}"
+ return 2
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+
+ if [ "${#}" != "1" ]; then
+ shift 1
+ log_failure_msg "Usage: statusproc [-p pidfile] pathname"
+ return 2
fi
- getpids "${1}"
+ # Get the process basename
+ base="${1##*/}"
+
+ # This will ensure compatibility with previous LFS Bootscripts
+ if [ -n "${PIDFILE}" ]; then
+ pidfile="${PIDFILE}"
+ fi
+
+ # Is the process running?
+ if [ -z "${pidfile}" ]; then
+ pidofproc -s "${1}"
+ else
+ pidofproc -s -p "${pidfile}" "${1}"
+ fi
if [ -n "${pidlist}" ]; then
${ECHO} -e "${INFO}${base} is running with Process"\
@@ -295,9 +328,9 @@ statusproc()
${ECHO} -e "${WARNING}${1} is not running but"\
"/var/run/${base}.pid exists.${NORMAL}"
else
- if [ -n "${PIDFILE}" -a -e "${PIDFILE}" ]; then
+ if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
${ECHO} -e "${WARNING}${1} is not running"\
- "but ${PIDFILE} exists.${NORMAL}"
+ "but ${pidfile} exists.${NORMAL}"
else
${ECHO} -e "${INFO}${1} is not running.${NORMAL}"
fi
--
1.5.0.6
From 975937af82463834577cf97239bf6929265bcbe9 Mon Sep 17 00:00:00 2001
From: Dan Nicholson <[EMAIL PROTECTED]>
Date: Wed, 11 Apr 2007 15:13:45 -0700
Subject: [PATCH 4/5] Return the status of pidofproc in statusproc
---
bootscripts/lfs/init.d/functions | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/bootscripts/lfs/init.d/functions b/bootscripts/lfs/init.d/functions
index 33195b6..62be816 100644
--- a/bootscripts/lfs/init.d/functions
+++ b/bootscripts/lfs/init.d/functions
@@ -281,6 +281,7 @@ statusproc()
{
local pidfile=""
local base=""
+ local ret=""
while true
do
@@ -320,6 +321,9 @@ statusproc()
pidofproc -s -p "${pidfile}" "${1}"
fi
+ # Store the return status
+ ret=$?
+
if [ -n "${pidlist}" ]; then
${ECHO} -e "${INFO}${base} is running with Process"\
"ID(s) ${pidlist}.${NORMAL}"
@@ -336,6 +340,9 @@ statusproc()
fi
fi
fi
+
+ # Return the status from pidofproc
+ return $ret
}
# The below functions are documented in the LSB-generic 2.1.0
--
1.5.0.6
From 81ac6f2d371b57d19256f987653585640fcd439e Mon Sep 17 00:00:00 2001
From: Dan Nicholson <[EMAIL PROTECTED]>
Date: Wed, 11 Apr 2007 15:30:15 -0700
Subject: [PATCH 5/5] Use pidofproc and respect pidfiles in reloadproc
---
bootscripts/lfs/init.d/functions | 40 +++++++++++++++++++++++++++++++++----
bootscripts/lfs/init.d/sysklogd | 2 +-
2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/bootscripts/lfs/init.d/functions b/bootscripts/lfs/init.d/functions
index 62be816..7160e3d 100644
--- a/bootscripts/lfs/init.d/functions
+++ b/bootscripts/lfs/init.d/functions
@@ -254,15 +254,45 @@ print_status()
reloadproc()
{
- if [ "${#}" = "0" ]; then
- echo "Usage: reloadproc [{program}]"
- exit 1
+ local pidfile=""
+ local failure=0
+
+ while true
+ do
+ case "${1}" in
+ -p)
+ pidfile="${2}"
+ shift 2
+ ;;
+ -*)
+ log_failure_msg "Unknown Option: ${1}"
+ return 2
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+
+ if [ "${#}" != "1" ]; then
+ shift 1
+ log_failure_msg "Usage: reloadproc [-p pidfile] pathname"
+ return 2
fi
- getpids "${1}"
+ # This will ensure compatibility with previous LFS Bootscripts
+ if [ -n "${PIDFILE}" ]; then
+ pidfile="${PIDFILE}"
+ fi
+
+ # Is the process running?
+ if [ -z "${pidfile}" ]; then
+ pidofproc -s "${1}"
+ else
+ pidofproc -s -p "${pidfile}" "${1}"
+ fi
if [ -n "${pidlist}" ]; then
- failure="0"
for pid in ${pidlist}
do
kill -"${RELOADSIG}" "${pid}" || failure="1"
diff --git a/bootscripts/lfs/init.d/sysklogd b/bootscripts/lfs/init.d/sysklogd
index 1912df4..e0a568c 100644
--- a/bootscripts/lfs/init.d/sysklogd
+++ b/bootscripts/lfs/init.d/sysklogd
@@ -34,7 +34,7 @@ case "${1}" in
reload)
boot_mesg "Reloading system log daemon config file..."
- reloadproc syslogd 1
+ reloadproc syslogd
;;
restart)
--
1.5.0.6
--
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page