From: Jeff Licquia Date: Sat, 10 Nov 2012 15:26:30 +0000 (-0500) Subject: Sanity-check pidofproc parameters X-Git-Tag: archive/raspbian/10.2018112800+rpi1^2~82^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=da8928c8c01484b44e3dd708441ae7092f5449df;p=lsb.git Sanity-check pidofproc parameters Closes: #691422. --- diff --git a/init-functions b/init-functions index 5cb28dc..046dfb9 100644 --- a/init-functions +++ b/init-functions @@ -75,6 +75,10 @@ pidofproc () { esac done shift $(($OPTIND - 1)) + if [ $# -ne 1 ]; then + echo "$0: invalid arguments" >&2 + return 4 + fi base=${1##*/} if [ ! "$specified" ]; then diff --git a/test/lsb-test.sh b/test/lsb-test.sh index 1168a62..2db3457 100644 --- a/test/lsb-test.sh +++ b/test/lsb-test.sh @@ -8,3 +8,31 @@ log_success_msg "This should succeed" log_failure_msg "This fails miserably" echo "OK!" + +# Test pidofproc sanity checking. + +echo "Testing pidofproc command line checks" + +echo " Simple check, no options:" +pidofproc nonexistent +RETVAL=$? +if [ $RETVAL -ne 3 ]; then + echo "Unexpected return value $RETVAL" +fi + +echo " With -p option:" +pidofproc -p /var/run/nonexist.pid nonexistent +RETVAL=$? +if [ $RETVAL -ne 3 ]; then + echo "Unexpected return value $RETVAL" +fi + +echo " With -p option, but in wrong place:" +pidofproc nonexistent -p /var/run/nonexist.pid +RETVAL=$? +if [ $RETVAL -ne 4 ]; then + echo "Unexpected return value $RETVAL" +fi + +echo "OK!" +