aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Kaspar [Dee'Kej] <dkaspar@redhat.com>2017-03-24 16:30:08 +0100
committerDee'Kej <deekej@linuxmail.org>2017-03-28 12:27:10 +0200
commitbbf53ab26475d8c7a63662458d62877f4d7e3914 (patch)
treeee237bde69c1cea086d137dbbc01ff07e0716073
parent5b048aea7192678e37bf2806a4b025f51f67165e (diff)
downloadinitscripts-bbf53ab26475d8c7a63662458d62877f4d7e3914.tar
initscripts-bbf53ab26475d8c7a63662458d62877f4d7e3914.tar.gz
initscripts-bbf53ab26475d8c7a63662458d62877f4d7e3914.tar.bz2
initscripts-bbf53ab26475d8c7a63662458d62877f4d7e3914.tar.xz
initscripts-bbf53ab26475d8c7a63662458d62877f4d7e3914.zip
killproc/status: add missing '-b <binary>' option
Taken from RHEL-6.9, for forward compatibility.
-rw-r--r--rc.d/init.d/functions35
1 files changed, 30 insertions, 5 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
index f378720e..b2a29190 100644
--- a/rc.d/init.d/functions
+++ b/rc.d/init.d/functions
@@ -183,6 +183,7 @@ __pids_var_run() {
local base=${1##*/}
local pid_file=${2:-/var/run/$base.pid}
local pid_dir=$(/usr/bin/dirname $pid_file > /dev/null)
+ local binary=$3
[ -d "$pid_dir" -a ! -r "$pid_dir" ] && return 4
@@ -195,7 +196,13 @@ __pids_var_run() {
read line
[ -z "$line" ] && break
for p in $line ; do
- [ -z "${p//[0-9]/}" ] && [ -d "/proc/$p" ] && pid="$pid $p"
+ if [ -z "${p//[0-9]/}" ] && [ -d "/proc/$p" ] ; then
+ if [ -n "$binary" ] ; then
+ local b=$(readlink /proc/$p/exe | sed -e 's/\s*(deleted)$//')
+ [ "$b" != "$binary" ] && continue
+ fi
+ pid="$pid $p"
+ fi
done
done < "$pid_file"
@@ -310,7 +317,7 @@ daemon() {
# A function to stop a program.
killproc() {
- local RC killlevel= base pid pid_file= delay try
+ local RC killlevel= base pid pid_file= delay try binary=
RC=0; delay=3; try=0
# Test syntax.
@@ -322,6 +329,15 @@ killproc() {
pid_file=$2
shift 2
fi
+ if [ "$1" = "-b" ]; then
+ if [ -z $pid_file ]; then
+ echo $"-b option can be used only with -p"
+ echo $"Usage: killproc -p pidfile -b binary program"
+ return 1
+ fi
+ binary=$2
+ shift 2
+ fi
if [ "$1" = "-d" ]; then
delay=$(echo $2 | awk -v RS=' ' -v IGNORECASE=1 '{if($1!~/^[0-9.]+[smhd]?$/) exit 1;d=$1~/s$|^[0-9.]*$/?1:$1~/m$/?60:$1~/h$/?60*60:$1~/d$/?24*60*60:-1;if(d==-1) exit 1;delay+=d*$1} END {printf("%d",delay+0.5)}')
if [ "$?" -eq 1 ]; then
@@ -339,7 +355,7 @@ killproc() {
base=${1##*/}
# Find pid.
- __pids_var_run "$1" "$pid_file"
+ __pids_var_run "$1" "$pid_file" "$binary"
RC=$?
if [ -z "$pid" ]; then
if [ -z "$pid_file" ]; then
@@ -425,7 +441,7 @@ pidofproc() {
}
status() {
- local base pid lock_file= pid_file=
+ local base pid lock_file= pid_file= binary=
# Test syntax.
if [ "$#" = 0 ] ; then
@@ -440,6 +456,15 @@ status() {
lock_file=$2
shift 2
fi
+ if [ "$1" = "-b" ]; then
+ if [ -z $pid_file ]; then
+ echo $"-b option can be used only with -p"
+ echo $"Usage: status -p pidfile -b binary program"
+ return 1
+ fi
+ binary=$2
+ shift 2
+ fi
base=${1##*/}
if [ "$_use_systemctl" = "1" ]; then
@@ -455,7 +480,7 @@ status() {
fi
# First try "pidof"
- __pids_var_run "$1" "$pid_file"
+ __pids_var_run "$1" "$pid_file" "$binary"
RC=$?
if [ -z "$pid_file" -a -z "$pid" ]; then
pid="$(__pids_pidof "$1")"