diff options
author | Lukas Nykryn <lnykryn@redhat.com> | 2014-01-20 12:29:47 +0100 |
---|---|---|
committer | Lukas Nykryn <lnykryn@redhat.com> | 2014-01-20 12:29:47 +0100 |
commit | 878b99dec32da6009906ebaa50aee3df1c5ea42b (patch) | |
tree | 31e85c4c7788f528a885497849b68739928a61bc /rc.d | |
parent | 5948bc3af6a9bdd9b043e52e6dab95984fd300a9 (diff) | |
download | initscripts-878b99dec32da6009906ebaa50aee3df1c5ea42b.tar initscripts-878b99dec32da6009906ebaa50aee3df1c5ea42b.tar.gz initscripts-878b99dec32da6009906ebaa50aee3df1c5ea42b.tar.bz2 initscripts-878b99dec32da6009906ebaa50aee3df1c5ea42b.tar.xz initscripts-878b99dec32da6009906ebaa50aee3df1c5ea42b.zip |
init.d/functions: add -b optin to status and killproc (#1047948)
Diffstat (limited to 'rc.d')
-rw-r--r-- | rc.d/init.d/functions | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index d5a654dd..2a2a3a95 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -148,6 +148,7 @@ __umount_loopback_loop() { __pids_var_run() { local base=${1##*/} local pid_file=${2:-/var/run/$base.pid} + local binary=$3 pid= if [ -f "$pid_file" ] ; then @@ -158,7 +159,13 @@ __pids_var_run() { read line [ -z "$line" ] && break for p in $line ; do - [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p" + if [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] ; then + if [ -n "$binary" ] ; then + local b=$(__readlink /proc/$p/exe) + [ "$b" != "$binary" ] && continue + fi + pid="$pid $p" + fi done done < "$pid_file" @@ -269,7 +276,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. @@ -281,6 +288,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 @@ -298,7 +314,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 @@ -402,7 +418,7 @@ pidofproc() { } status() { - local base pid lock_file= pid_file= + local base pid lock_file= pid_file= binary= # Test syntax. if [ "$#" = 0 ] ; then @@ -417,10 +433,19 @@ 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##*/} # 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")" |