From a7b8b772dee4f159028e3b998454d7466fbbc88f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 11 Jul 2019 14:00:07 -0700 Subject: pidof: fix default behavior, add -x. Before this patch, we're effectively doing `pidof -x` all the time. This patch changes names_to_pid() to allow us to say whether or not we want to include scripts, and adjusts the callers appropriately. Also add tests for `pidof` versus `pidof -x` which pass after this patch, without regressing the existing killall tests. --- tests/pidof.test | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/pidof.test (limited to 'tests') diff --git a/tests/pidof.test b/tests/pidof.test new file mode 100644 index 00000000..7de31fc2 --- /dev/null +++ b/tests/pidof.test @@ -0,0 +1,33 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# +# pidof (unlike killall) doesn't match argv[1] unless you supply -x. +# + +echo "#!$(which sh) +while true; do + sleep 0.1 +done" > toybox.pidof.test.script +chmod a+x toybox.pidof.test.script +cp toybox.pidof.test.script pidof.test + +./pidof.test & +pid=$! +testcmd "short argv[1]" "pidof.test" "" "" "" +testcmd "short argv[1] -x" "-x pidof.test" "$pid\n" "" "" +kill $pid + +./toybox.pidof.test.script & +pid=$! +testcmd "long argv[1]" "toybox.pidof.test.script" "" "" "" +testcmd "long argv[1] -x" "-x toybox.pidof.test.script" "$pid\n" "" "" +kill $pid + +rm -f toybox.pidof.test.script toybox.test + +# pidof (unlike killall) will match itself. +testcmd "pidof pidof" "pidof > /dev/null && echo found" "found\n" "" "" -- cgit v1.2.3