bin/pkill: Fix {pgrep,pkill}-j_test.sh
The POSIX sh case statement does not allow for pattern matching using the regex + qualifier so this case statement never matches. Instead just check for a string starting with a digit followed by any character. While touching these files also fix various shellcheck warnings. `kyua -v parallelism=4 test` failed before, succeeds now. Reviewed By: imp Differential Revision: https://reviews.freebsd.org/D28480
This commit is contained in:
parent
90b5fc9583
commit
5ff2e55e00
@ -9,7 +9,7 @@ jail_name_to_jid()
|
|||||||
|
|
||||||
base=pgrep_j_test
|
base=pgrep_j_test
|
||||||
|
|
||||||
if [ `id -u` -ne 0 ]; then
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
echo "1..0 # skip Test needs uid 0."
|
echo "1..0 # skip Test needs uid 0."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@ -28,12 +28,12 @@ jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
|
|||||||
command=daemon -p ${PWD}/${base}_1_2.pid $sleep $sleep_amount &
|
command=daemon -p ${PWD}/${base}_1_2.pid $sleep $sleep_amount &
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
|
|
||||||
for i in `seq 1 10`; do
|
for i in $(seq 1 10); do
|
||||||
jid1=$(jail_name_to_jid ${base}_1_1)
|
jid1=$(jail_name_to_jid ${base}_1_1)
|
||||||
jid2=$(jail_name_to_jid ${base}_1_2)
|
jid2=$(jail_name_to_jid ${base}_1_2)
|
||||||
jid="${jid1},${jid2}"
|
jid="${jid1},${jid2}"
|
||||||
case "$jid" in
|
case "$jid" in
|
||||||
[0-9]+,[0-9]+)
|
[0-9]*,[0-9]*)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -43,14 +43,14 @@ sleep 0.5
|
|||||||
|
|
||||||
pid1="$(pgrep -f -x -j "$jid" "$sleep $sleep_amount" | sort)"
|
pid1="$(pgrep -f -x -j "$jid" "$sleep $sleep_amount" | sort)"
|
||||||
pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_1_1.pid)" \
|
pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_1_1.pid)" \
|
||||||
$(cat ${PWD}/${base}_1_2.pid) | sort)
|
"$(cat ${PWD}/${base}_1_2.pid)" | sort)
|
||||||
if [ "$pid1" = "$pid2" ]; then
|
if [ "$pid1" = "$pid2" ]; then
|
||||||
echo "ok 1 - $name"
|
echo "ok 1 - $name"
|
||||||
else
|
else
|
||||||
echo "not ok 1 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
|
echo "not ok 1 - $name # pgrep output: '$pid1', pidfile output: '$pid2'"
|
||||||
fi
|
fi
|
||||||
[ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
|
[ -f ${PWD}/${base}_1_1.pid ] && kill "$(cat ${PWD}/${base}_1_1.pid)"
|
||||||
[ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
|
[ -f ${PWD}/${base}_1_2.pid ] && kill "$(cat ${PWD}/${base}_1_2.pid)"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
name="pgrep -j any"
|
name="pgrep -j any"
|
||||||
@ -64,14 +64,14 @@ jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
|
|||||||
sleep 2
|
sleep 2
|
||||||
pid1="$(pgrep -f -x -j any "$sleep $sleep_amount" | sort)"
|
pid1="$(pgrep -f -x -j any "$sleep $sleep_amount" | sort)"
|
||||||
pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_2_1.pid)" \
|
pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_2_1.pid)" \
|
||||||
$(cat ${PWD}/${base}_2_2.pid) | sort)
|
"$(cat ${PWD}/${base}_2_2.pid)" | sort)
|
||||||
if [ "$pid1" = "$pid2" ]; then
|
if [ "$pid1" = "$pid2" ]; then
|
||||||
echo "ok 2 - $name"
|
echo "ok 2 - $name"
|
||||||
else
|
else
|
||||||
echo "not ok 2 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
|
echo "not ok 2 - $name # pgrep output: '$pid1', pidfile output: '$pid2'"
|
||||||
fi
|
fi
|
||||||
[ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
|
[ -f ${PWD}/${base}_2_1.pid ] && kill "$(cat ${PWD}/${base}_2_1.pid)"
|
||||||
[ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
|
[ -f ${PWD}/${base}_2_2.pid ] && kill "$(cat ${PWD}/${base}_2_2.pid)"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
name="pgrep -j none"
|
name="pgrep -j none"
|
||||||
@ -84,10 +84,10 @@ pid="$(pgrep -f -x -j none "$sleep $sleep_amount")"
|
|||||||
if [ "$pid" = "$(cat ${PWD}/${base}_3_1.pid)" ]; then
|
if [ "$pid" = "$(cat ${PWD}/${base}_3_1.pid)" ]; then
|
||||||
echo "ok 3 - $name"
|
echo "ok 3 - $name"
|
||||||
else
|
else
|
||||||
echo "not ok 3 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
|
echo "not ok 3 - $name # pgrep output: '$pid1', pidfile output: '$pid2'"
|
||||||
fi
|
fi
|
||||||
[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat $PWD/${base}_3_1.pid)
|
[ -f ${PWD}/${base}_3_1.pid ] && kill "$(cat $PWD/${base}_3_1.pid)"
|
||||||
[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat $PWD/${base}_3_2.pid)
|
[ -f ${PWD}/${base}_3_2.pid ] && kill "$(cat $PWD/${base}_3_2.pid)"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
# test 4 is like test 1 except with jname instead of jid.
|
# test 4 is like test 1 except with jname instead of jid.
|
||||||
@ -104,14 +104,14 @@ sleep 0.5
|
|||||||
jname="${base}_4_1,${base}_4_2"
|
jname="${base}_4_1,${base}_4_2"
|
||||||
pid1="$(pgrep -f -x -j "$jname" "$sleep $sleep_amount" | sort)"
|
pid1="$(pgrep -f -x -j "$jname" "$sleep $sleep_amount" | sort)"
|
||||||
pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_4_1.pid)" \
|
pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_4_1.pid)" \
|
||||||
$(cat ${PWD}/${base}_4_2.pid) | sort)
|
"$(cat ${PWD}/${base}_4_2.pid)" | sort)
|
||||||
if [ "$pid1" = "$pid2" ]; then
|
if [ "$pid1" = "$pid2" ]; then
|
||||||
echo "ok 4 - $name"
|
echo "ok 4 - $name"
|
||||||
else
|
else
|
||||||
echo "not ok 4 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
|
echo "not ok 4 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
|
||||||
fi
|
fi
|
||||||
[ -f ${PWD}/${base}_4_1.pid ] && kill $(cat ${PWD}/${base}_4_1.pid)
|
[ -f ${PWD}/${base}_4_1.pid ] && kill "$(cat ${PWD}/${base}_4_1.pid)"
|
||||||
[ -f ${PWD}/${base}_4_2.pid ] && kill $(cat ${PWD}/${base}_4_2.pid)
|
[ -f ${PWD}/${base}_4_2.pid ] && kill "$(cat ${PWD}/${base}_4_2.pid)"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
rm -f $sleep
|
rm -f $sleep
|
||||||
|
@ -9,7 +9,7 @@ jail_name_to_jid()
|
|||||||
|
|
||||||
base=pkill_j_test
|
base=pkill_j_test
|
||||||
|
|
||||||
if [ `id -u` -ne 0 ]; then
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
echo "1..0 # skip Test needs uid 0."
|
echo "1..0 # skip Test needs uid 0."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@ -29,28 +29,31 @@ jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
|
|||||||
|
|
||||||
$sleep $sleep_amount &
|
$sleep $sleep_amount &
|
||||||
|
|
||||||
for i in `seq 1 10`; do
|
for i in $(seq 1 10); do
|
||||||
jid1=$(jail_name_to_jid ${base}_1_1)
|
jid1=$(jail_name_to_jid ${base}_1_1)
|
||||||
jid2=$(jail_name_to_jid ${base}_1_2)
|
jid2=$(jail_name_to_jid ${base}_1_2)
|
||||||
jid="${jid1},${jid2}"
|
jid="${jid1},${jid2}"
|
||||||
case "$jid" in
|
case "$jid" in
|
||||||
[0-9]+,[0-9]+)
|
[0-9]*,[0-9]*)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
echo "Did not match: '${jid}'" >&2
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
|
|
||||||
if pkill -f -j "$jid" $sleep && sleep 0.5 &&
|
if pkill -f -j "$jid" $sleep && sleep 0.5 &&
|
||||||
! -f ${PWD}/${base}_1_1.pid &&
|
! test -f "${PWD}/${base}_1_1.pid" &&
|
||||||
! -f ${PWD}/${base}_1_2.pid ; then
|
! test -f "${PWD}/${base}_1_2.pid" ; then
|
||||||
echo "ok 1 - $name"
|
echo "ok 1 - $name"
|
||||||
else
|
else
|
||||||
echo "not ok 1 - $name"
|
echo "not ok 1 - $name"
|
||||||
fi 2>/dev/null
|
fi 2>/dev/null
|
||||||
[ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
|
[ -f ${PWD}/${base}_1_1.pid ] && kill "$(cat ${PWD}/${base}_1_1.pid)"
|
||||||
[ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
|
[ -f ${PWD}/${base}_1_2.pid ] && kill "$(cat ${PWD}/${base}_1_2.pid)"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
name="pkill -j any"
|
name="pkill -j any"
|
||||||
@ -65,14 +68,14 @@ $sleep $sleep_amount &
|
|||||||
chpid3=$!
|
chpid3=$!
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
if pkill -f -j any $sleep && sleep 0.5 &&
|
if pkill -f -j any $sleep && sleep 0.5 &&
|
||||||
[ ! -f ${PWD}/${base}_2_1.pid -a
|
! test -f ${PWD}/${base}_2_1.pid &&
|
||||||
! -f ${PWD}/${base}_2_2.pid ] && kill $chpid3; then
|
! test -f ${PWD}/${base}_2_2.pid && kill $chpid3; then
|
||||||
echo "ok 2 - $name"
|
echo "ok 2 - $name"
|
||||||
else
|
else
|
||||||
echo "not ok 2 - $name"
|
echo "not ok 2 - $name"
|
||||||
fi 2>/dev/null
|
fi 2>/dev/null
|
||||||
[ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
|
[ -f ${PWD}/${base}_2_1.pid ] && kill "$(cat ${PWD}/${base}_2_1.pid)"
|
||||||
[ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
|
[ -f ${PWD}/${base}_2_2.pid ] && kill "$(cat ${PWD}/${base}_2_2.pid)"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
name="pkill -j none"
|
name="pkill -j none"
|
||||||
@ -88,8 +91,8 @@ else
|
|||||||
ls ${PWD}/*.pid
|
ls ${PWD}/*.pid
|
||||||
echo "not ok 3 - $name"
|
echo "not ok 3 - $name"
|
||||||
fi 2>/dev/null
|
fi 2>/dev/null
|
||||||
[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
|
[ -f ${PWD}/${base}_3_1.pid ] && kill "$(cat ${base}_3_1.pid)"
|
||||||
[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
|
[ -f ${PWD}/${base}_3_2.pid ] && kill "$(cat ${base}_3_2.pid)"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
# test 4 is like test 1 except with jname instead of jid.
|
# test 4 is like test 1 except with jname instead of jid.
|
||||||
@ -107,14 +110,14 @@ sleep 0.5
|
|||||||
|
|
||||||
jname="${base}_4_1,${base}_4_2"
|
jname="${base}_4_1,${base}_4_2"
|
||||||
if pkill -f -j "$jname" $sleep && sleep 0.5 &&
|
if pkill -f -j "$jname" $sleep && sleep 0.5 &&
|
||||||
! -f ${PWD}/${base}_4_1.pid &&
|
! test -f ${PWD}/${base}_4_1.pid &&
|
||||||
! -f ${PWD}/${base}_4_2.pid ; then
|
! test -f ${PWD}/${base}_4_2.pid ; then
|
||||||
echo "ok 4 - $name"
|
echo "ok 4 - $name"
|
||||||
else
|
else
|
||||||
echo "not ok 4 - $name"
|
echo "not ok 4 - $name"
|
||||||
fi 2>/dev/null
|
fi 2>/dev/null
|
||||||
[ -f ${PWD}/${base}_4_1.pid ] && kill $(cat ${PWD}/${base}_4_1.pid)
|
[ -f ${PWD}/${base}_4_1.pid ] && kill "$(cat ${PWD}/${base}_4_1.pid)"
|
||||||
[ -f ${PWD}/${base}_4_2.pid ] && kill $(cat ${PWD}/${base}_4_2.pid)
|
[ -f ${PWD}/${base}_4_2.pid ] && kill "$(cat ${PWD}/${base}_4_2.pid)"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
rm -f $sleep
|
rm -f $sleep
|
||||||
|
Loading…
Reference in New Issue
Block a user