Sanity-check pidofproc parameters
authorJeff Licquia <licquia@debian.org>
Sat, 10 Nov 2012 15:26:30 +0000 (10:26 -0500)
committerDidier Raboud <odyx@debian.org>
Mon, 12 Nov 2012 07:57:21 +0000 (08:57 +0100)
Closes: #691422.
init-functions
test/lsb-test.sh

index 5cb28dc4d2a386bfe858bdb82021baa5ffb410ed..046dfb9b4416495bbfc75d90da70675922d8dff5 100644 (file)
@@ -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
index 1168a62d320218dcdef78862d6101a110d1ab4c3..2db3457ed247e812b0a38d9e465d2a0e80d2c3cd 100644 (file)
@@ -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!"
+