killproc arguments

DJ Lucas dj at linuxfromscratch.org
Sun Jul 18 23:19:27 PDT 2004


Right now we need to pass an argument to killproc else it errors.  If 
PIDFILE is set, then there is no need, but optionally it could take a 
signal.  Looking at my proposed patch (below), it may be better to 
re-write the function completely and add a fallback variable ($2 and $3) 
sometime in the future.

-- DJ Lucas

Index: functions
===================================================================
--- functions   (revision 3942)
+++ functions   (working copy)
@@ -173,30 +173,43 @@
  # Stops a process if it is running
  killproc()
  {
-        if [ $# = 0 ]
-        then
-                echo "Usage: killproc {program} [signal]"
-                exit 1
-        fi
+       #if PIDFILE is set, no need to pass arguments

-        if [ -z "$2" ]; then
-                signal=TERM
-                fallback=KILL
-        else-                signal=${2##-}
-                signal=${signal##SIG}
-                fallback=""
-        fi
-
-       if [ -n "$PIDFILE" -a -r "$PIDFILE" ]; then
+       if [ -n "$PIDFILE" -a -r "$PIDFILE" ]
+       then
                 pidlist=`cat $PIDFILE`
+               if [ -z "$1" ]
+               then
+                       signal=TERM
+                       fallback=KILL
+               else
+                       signal=${1##-}
+                       signal=${signal##SIG}
+                       fallback=""
+               fi
         else
+               if [ $# = 0 ]
+               then
+                       echo "Usage: killproc {program} [signal]"
+                       exit 1
+               fi
+
+
+               if [ -z "$2" ]; then
+                       signal=TERM
+                       fallback=KILL
+               else
+                       signal=${2##-}
+                       signal=${signal##SIG}
+                       fallback=""
+               fi
+
                 getpids $1
         fi
+
+       if [ -n "$pidlist" ]; then
+               local i=0

-        if [ -n "$pidlist" ]; then
-                local i=0
-
                  for pid in $pidlist
                  do
                          kill -$signal $pid 2>/dev/null



More information about the lfs-dev mailing list