linux - Meaning of declarations in /etc/init.d/functions on EL 5 -
i'm of amateur when comes bash shell scripting , baffled first line in killproc() function in /etc/init.d/functions on centos 5.10 system:
local rc killlevel= base pid pid_file= delay try
what meaning of line? believe declaration of local variables perhaps, meaning of = after couple of items? have included complete killproc() function below reference:
# function stop program. killproc() { local rc killlevel= base pid pid_file= delay try rc=0; delay=3; try=0 # test syntax. if [ "$#" -eq 0 ]; echo $"usage: killproc [-p pidfile] [ -d delay] {program} [-signal]" return 1 fi if [ "$1" = "-p" ]; pid_file=$2 shift 2 fi if [ "$1" = "-d" ]; 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 ]; echo $"usage: killproc [-p pidfile] [ -d delay] {program} [-signal]" return 1 fi shift 2 fi # check second arg kill level [ -n "${2:-}" ] && killlevel=$2 # save basename. base=${1##*/} # find pid. __pids_var_run "$1" "$pid_file" if [ -z "$pid_file" -a -z "$pid" ]; pid="$(__pids_pidof "$1")" fi # kill it. if [ -n "$pid" ] ; [ "$bootup" = "verbose" -a -z "${lsb:-}" ] && echo -n "$base " if [ -z "$killlevel" ] ; if checkpid $pid 2>&1; # term first, kill if not dead kill -term $pid >/dev/null 2>&1 usleep 100000 if checkpid $pid ; try=0 while [ $try -lt $delay ] ; checkpid $pid || break sleep 1 let try+=1 done if checkpid $pid ; kill -kill $pid >/dev/null 2>&1 usleep 100000 fi fi fi checkpid $pid rc=$? [ "$rc" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown" rc=$((! $rc)) # use specified level else if checkpid $pid; kill $killlevel $pid >/dev/null 2>&1 rc=$? [ "$rc" -eq 0 ] && success $"$base $killlevel" || failure $"$base $killlevel" elif [ -n "${lsb:-}" ]; rc=7 # program not running fi fi else if [ -n "${lsb:-}" -a -n "$killlevel" ]; rc=7 # program not running else failure $"$base shutdown" rc=0 fi fi # remove pid file if any. if [ -z "$killlevel" ]; rm -f "${pid_file:-/var/run/$base.pid}" fi return $rc }
it's declaring lot of function scope variables, killlevel
, pid_file
assigned empty string , others not assigned anything.
there slight difference. local
variables visible in functions called function. if happen call killproc()
recursively, uninitialized ones remembered caller.
on debian lib/lsb/init-functions
file looks this:
killproc() { local pidfile sig status base name_param is_term_sig optind pidfile= name_param= is_term_sig=
Comments
Post a Comment