2005-03-20 12:38:08 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# $FreeBSD$
|
|
|
|
|
2014-09-30 15:27:49 +00:00
|
|
|
jail_name_to_jid()
|
|
|
|
{
|
|
|
|
local check_name="$1"
|
2015-02-21 23:39:43 +00:00
|
|
|
jls -j "$check_name" -s | tr ' ' '\n' | grep jid= | sed -e 's/.*=//g'
|
2014-09-30 15:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
base=pkill_j_test
|
2005-03-20 12:38:08 +00:00
|
|
|
|
2015-02-14 19:21:04 +00:00
|
|
|
if [ `id -u` -ne 0 ]; then
|
|
|
|
echo "1..0 # skip Test needs uid 0."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-08-22 05:04:36 +00:00
|
|
|
echo "1..4"
|
2005-03-20 12:38:08 +00:00
|
|
|
|
2015-02-14 19:21:04 +00:00
|
|
|
sleep=$(pwd)/sleep.txt
|
|
|
|
ln -sf /bin/sleep $sleep
|
|
|
|
|
2005-03-20 12:38:08 +00:00
|
|
|
name="pkill -j <jid>"
|
2015-02-14 19:21:04 +00:00
|
|
|
sleep_amount=5
|
|
|
|
jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_1_1.pid $sleep $sleep_amount &
|
2014-09-30 15:27:49 +00:00
|
|
|
|
2015-02-14 19:21:04 +00:00
|
|
|
jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_1_2.pid $sleep $sleep_amount &
|
2014-09-30 15:27:49 +00:00
|
|
|
|
2015-02-14 19:21:04 +00:00
|
|
|
$sleep $sleep_amount &
|
|
|
|
|
|
|
|
for i in `seq 1 10`; do
|
2014-09-30 15:27:49 +00:00
|
|
|
jid1=$(jail_name_to_jid ${base}_1_1)
|
|
|
|
jid2=$(jail_name_to_jid ${base}_1_2)
|
|
|
|
jid="${jid1},${jid2}"
|
2015-02-14 19:21:04 +00:00
|
|
|
case "$jid" in
|
|
|
|
[0-9]+,[0-9]+)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
sleep 0.1
|
|
|
|
done
|
2015-02-21 23:39:43 +00:00
|
|
|
sleep 0.5
|
2015-02-14 19:21:04 +00:00
|
|
|
|
|
|
|
if pkill -f -j "$jid" $sleep && sleep 0.5 &&
|
|
|
|
! -f ${PWD}/${base}_1_1.pid &&
|
|
|
|
! -f ${PWD}/${base}_1_2.pid ; then
|
|
|
|
echo "ok 1 - $name"
|
2005-03-20 12:38:08 +00:00
|
|
|
else
|
2015-02-14 19:21:04 +00:00
|
|
|
echo "not ok 1 - $name"
|
|
|
|
fi 2>/dev/null
|
|
|
|
[ -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)
|
|
|
|
wait
|
2005-03-20 12:38:08 +00:00
|
|
|
|
Fix and extend the -j option to pkill/pgrep WRT the jail
wildcard specifications. Earlier the only wildcard syntax
was "-j 0" for "any jail". There were at least
two shortcomings in it: First, jail ID 0 was abused; it
meant "no jail" in other utils, e.g., ps(1). Second, it
was impossible to match processed not in jail, which could
be useful to rc.d developers. Therefore a new syntax is
introduced: "-j any" means any jail while "-j none" means
out of jail. The old syntax is preserved for compatibility,
but now it's deprecated because it's limited and confusing.
Update the respective regression tests. While I'm here,
make the tests more complex but sensitive: Start several
processes, some in jail and some out of jail, so we can
detect that only the right processes are killed by pkill
or matched by pgrep.
Reviewed by: gad, pjd
MFC after: 1 week
2006-11-23 11:55:17 +00:00
|
|
|
name="pkill -j any"
|
2015-02-14 19:21:04 +00:00
|
|
|
sleep_amount=6
|
|
|
|
jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_2_1.pid $sleep $sleep_amount &
|
2014-09-30 15:27:49 +00:00
|
|
|
|
2015-02-14 19:21:04 +00:00
|
|
|
jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_2_2.pid $sleep $sleep_amount &
|
2014-09-30 15:27:49 +00:00
|
|
|
|
2015-02-14 19:21:04 +00:00
|
|
|
$sleep $sleep_amount &
|
|
|
|
chpid3=$!
|
|
|
|
sleep 0.5
|
|
|
|
if pkill -f -j any $sleep && sleep 0.5 &&
|
|
|
|
[ ! -f ${PWD}/${base}_2_1.pid -a
|
|
|
|
! -f ${PWD}/${base}_2_2.pid ] && kill $chpid3; then
|
|
|
|
echo "ok 2 - $name"
|
2005-03-20 12:38:08 +00:00
|
|
|
else
|
2015-02-14 19:21:04 +00:00
|
|
|
echo "not ok 2 - $name"
|
|
|
|
fi 2>/dev/null
|
|
|
|
[ -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)
|
|
|
|
wait
|
Fix and extend the -j option to pkill/pgrep WRT the jail
wildcard specifications. Earlier the only wildcard syntax
was "-j 0" for "any jail". There were at least
two shortcomings in it: First, jail ID 0 was abused; it
meant "no jail" in other utils, e.g., ps(1). Second, it
was impossible to match processed not in jail, which could
be useful to rc.d developers. Therefore a new syntax is
introduced: "-j any" means any jail while "-j none" means
out of jail. The old syntax is preserved for compatibility,
but now it's deprecated because it's limited and confusing.
Update the respective regression tests. While I'm here,
make the tests more complex but sensitive: Start several
processes, some in jail and some out of jail, so we can
detect that only the right processes are killed by pkill
or matched by pgrep.
Reviewed by: gad, pjd
MFC after: 1 week
2006-11-23 11:55:17 +00:00
|
|
|
|
|
|
|
name="pkill -j none"
|
2015-02-14 19:21:04 +00:00
|
|
|
sleep_amount=7
|
|
|
|
daemon -p ${PWD}/${base}_3_1.pid $sleep $sleep_amount
|
|
|
|
jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_3_2.pid $sleep $sleep_amount &
|
|
|
|
sleep 1
|
|
|
|
if pkill -f -j none "$sleep $sleep_amount" && sleep 1 &&
|
|
|
|
[ ! -f ${PWD}/${base}_3_1.pid -a -f ${PWD}/${base}_3_2.pid ] ; then
|
|
|
|
echo "ok 3 - $name"
|
Fix and extend the -j option to pkill/pgrep WRT the jail
wildcard specifications. Earlier the only wildcard syntax
was "-j 0" for "any jail". There were at least
two shortcomings in it: First, jail ID 0 was abused; it
meant "no jail" in other utils, e.g., ps(1). Second, it
was impossible to match processed not in jail, which could
be useful to rc.d developers. Therefore a new syntax is
introduced: "-j any" means any jail while "-j none" means
out of jail. The old syntax is preserved for compatibility,
but now it's deprecated because it's limited and confusing.
Update the respective regression tests. While I'm here,
make the tests more complex but sensitive: Start several
processes, some in jail and some out of jail, so we can
detect that only the right processes are killed by pkill
or matched by pgrep.
Reviewed by: gad, pjd
MFC after: 1 week
2006-11-23 11:55:17 +00:00
|
|
|
else
|
2015-02-14 19:21:04 +00:00
|
|
|
ls ${PWD}/*.pid
|
|
|
|
echo "not ok 3 - $name"
|
|
|
|
fi 2>/dev/null
|
|
|
|
[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
|
|
|
|
[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
|
2015-08-22 05:04:36 +00:00
|
|
|
wait
|
|
|
|
|
|
|
|
# test 4 is like test 1 except with jname instead of jid.
|
|
|
|
name="pkill -j <jname>"
|
|
|
|
sleep_amount=8
|
|
|
|
jail -c path=/ name=${base}_4_1 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_4_1.pid $sleep $sleep_amount &
|
|
|
|
|
|
|
|
jail -c path=/ name=${base}_4_2 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_4_2.pid $sleep $sleep_amount &
|
|
|
|
|
|
|
|
$sleep $sleep_amount &
|
|
|
|
|
|
|
|
sleep 0.5
|
|
|
|
|
|
|
|
jname="${base}_4_1,${base}_4_2"
|
|
|
|
if pkill -f -j "$jname" $sleep && sleep 0.5 &&
|
|
|
|
! -f ${PWD}/${base}_4_1.pid &&
|
|
|
|
! -f ${PWD}/${base}_4_2.pid ; then
|
|
|
|
echo "ok 4 - $name"
|
|
|
|
else
|
|
|
|
echo "not ok 4 - $name"
|
|
|
|
fi 2>/dev/null
|
|
|
|
[ -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)
|
|
|
|
wait
|
2015-02-14 19:21:04 +00:00
|
|
|
|
|
|
|
rm -f $sleep
|