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"
|
|
|
|
(
|
|
|
|
line="$(jls -n 2> /dev/null | grep name=$check_name )"
|
|
|
|
for nv in $line; do
|
|
|
|
local name="${nv%=*}"
|
|
|
|
if [ "${name}" = "jid" ]; then
|
|
|
|
eval $nv
|
|
|
|
echo $jid
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
base=pkill_j_test
|
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
|
|
|
echo "1..3"
|
2005-03-20 12:38:08 +00:00
|
|
|
|
|
|
|
name="pkill -j <jid>"
|
|
|
|
if [ `id -u` -eq 0 ]; then
|
2014-03-19 12:46:04 +00:00
|
|
|
sleep=$(pwd)/sleep.txt
|
2005-03-20 12:38:08 +00:00
|
|
|
ln -sf /bin/sleep $sleep
|
2014-09-30 15:27:49 +00:00
|
|
|
jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_1_1.pid $sleep 5 &
|
|
|
|
|
|
|
|
jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_1_2.pid $sleep 5 &
|
|
|
|
|
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
|
|
|
$sleep 5 &
|
|
|
|
sleep 0.5
|
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}"
|
|
|
|
if pkill -f -j "$jid" $sleep && sleep 0.5 &&
|
|
|
|
! -f ${PWD}/${base}_1_1.pid &&
|
|
|
|
! -f ${PWD}/${base}_1_2.pid ; then
|
2005-03-20 12:38:08 +00:00
|
|
|
echo "ok 1 - $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
|
2005-03-20 12:38:08 +00:00
|
|
|
echo "not ok 1 - $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
|
|
|
fi 2>/dev/null
|
2005-03-20 12:38:08 +00:00
|
|
|
rm -f $sleep
|
2014-09-30 15:27:49 +00:00
|
|
|
[ -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
|
|
|
else
|
|
|
|
echo "ok 1 - $name # skip Test needs uid 0."
|
|
|
|
fi
|
|
|
|
|
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"
|
2005-03-20 12:38:08 +00:00
|
|
|
if [ `id -u` -eq 0 ]; then
|
2014-03-19 12:46:04 +00:00
|
|
|
sleep=$(pwd)/sleep.txt
|
2005-03-20 12:38:08 +00:00
|
|
|
ln -sf /bin/sleep $sleep
|
2014-09-30 15:27:49 +00:00
|
|
|
jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_2_1.pid $sleep 5 &
|
|
|
|
|
|
|
|
jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_2_2.pid $sleep 5 &
|
|
|
|
|
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
|
|
|
$sleep 5 &
|
|
|
|
sleep 0.5
|
2014-09-30 15:27:49 +00:00
|
|
|
chpid3=$!
|
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
|
|
|
if pkill -f -j any $sleep && sleep 0.5 &&
|
2014-09-30 15:27:49 +00:00
|
|
|
[ ! -f ${PWD}/${base}_2_1.pid -a
|
|
|
|
! -f ${PWD}/${base}_2_2.pid ] && kill $chpid3; then
|
2005-03-20 12:38:08 +00:00
|
|
|
echo "ok 2 - $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
|
2005-03-20 12:38:08 +00:00
|
|
|
echo "not ok 2 - $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
|
|
|
fi 2>/dev/null
|
2005-03-20 12:38:08 +00:00
|
|
|
rm -f $sleep
|
2014-09-30 15:27:49 +00:00
|
|
|
[ -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
|
2005-03-20 12:38:08 +00:00
|
|
|
else
|
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
|
|
|
echo "ok 2 - $name # skip Test needs uid 0."
|
|
|
|
fi
|
|
|
|
|
|
|
|
name="pkill -j none"
|
|
|
|
if [ `id -u` -eq 0 ]; then
|
2014-03-19 12:46:04 +00:00
|
|
|
sleep=$(pwd)/sleep.txt
|
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
|
|
|
ln -sf /bin/sleep $sleep
|
2014-09-30 15:27:49 +00:00
|
|
|
daemon -p ${PWD}/${base}_3_1.pid $sleep 5
|
|
|
|
jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
|
|
|
|
command=daemon -p ${PWD}/${base}_3_2.pid $sleep 5 &
|
|
|
|
sleep 1
|
|
|
|
if pkill -f -j none "$sleep 5" && sleep 1 &&
|
|
|
|
[ ! -f ${PWD}/${base}_3_1.pid -a -f ${PWD}/${base}_3_2.pid ] ; then
|
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
|
|
|
echo "ok 3 - $name"
|
|
|
|
else
|
2014-09-30 15:27:49 +00:00
|
|
|
ls ${PWD}/*.pid
|
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
|
|
|
echo "not ok 3 - $name"
|
|
|
|
fi 2>/dev/null
|
|
|
|
rm -f $sleep
|
2014-09-30 15:27:49 +00:00
|
|
|
[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
|
|
|
|
[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
|
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
|
|
|
|
echo "ok 3 - $name # skip Test needs uid 0."
|
2005-03-20 12:38:08 +00:00
|
|
|
fi
|