2005-03-20 12:38:08 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# $FreeBSD$
|
|
|
|
|
|
|
|
base=`basename $0`
|
|
|
|
|
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="pgrep -j <jid>"
|
|
|
|
if [ `id -u` -eq 0 ]; then
|
|
|
|
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
|
|
|
|
ln -sf /bin/sleep $sleep
|
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
|
|
|
jail / $base-1 127.0.0.1 $sleep 5 &
|
2005-03-20 12:38:08 +00:00
|
|
|
chpid=$!
|
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
|
|
|
jail / $base-2 127.0.0.1 $sleep 5 &
|
|
|
|
chpid2=$!
|
|
|
|
$sleep 5 &
|
|
|
|
chpid3=$!
|
|
|
|
sleep 0.5
|
|
|
|
jid=`jls | awk "/127\\.0\\.0\\.1.*${base}-1/ {print \$1}"`
|
2005-03-20 12:38:08 +00:00
|
|
|
pid=`pgrep -f -j $jid $sleep`
|
|
|
|
if [ "$pid" = "$chpid" ]; then
|
|
|
|
echo "ok 1 - $name"
|
|
|
|
else
|
|
|
|
echo "not ok 1 - $name"
|
|
|
|
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
|
|
|
kill $chpid $chpid2 $chpid3
|
2005-03-20 12:38:08 +00:00
|
|
|
rm -f $sleep
|
|
|
|
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="pgrep -j any"
|
2005-03-20 12:38:08 +00:00
|
|
|
if [ `id -u` -eq 0 ]; then
|
|
|
|
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
|
|
|
|
ln -sf /bin/sleep $sleep
|
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
|
|
|
jail / $base-1 127.0.0.1 $sleep 5 &
|
2005-03-20 12:38:08 +00:00
|
|
|
chpid=$!
|
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
|
|
|
jail / $base-2 127.0.0.1 $sleep 5 &
|
|
|
|
chpid2=$!
|
|
|
|
$sleep 5 &
|
|
|
|
chpid3=$!
|
|
|
|
sleep 0.5
|
|
|
|
pids=`pgrep -f -j any $sleep | sort`
|
|
|
|
refpids=`{ echo $chpid; echo $chpid2; } | sort`
|
|
|
|
if [ "$pids" = "$refpids" ]; then
|
2005-03-20 12:38:08 +00:00
|
|
|
echo "ok 2 - $name"
|
|
|
|
else
|
|
|
|
echo "not ok 2 - $name"
|
|
|
|
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
|
|
|
kill $chpid $chpid2 $chpid3
|
2005-03-20 12:38:08 +00:00
|
|
|
rm -f $sleep
|
|
|
|
else
|
|
|
|
echo "ok 2 - $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="pgrep -j none"
|
|
|
|
if [ `id -u` -eq 0 ]; then
|
|
|
|
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
|
|
|
|
ln -sf /bin/sleep $sleep
|
|
|
|
$sleep 5 &
|
|
|
|
chpid=$!
|
|
|
|
jail / $base 127.0.0.1 $sleep 5 &
|
|
|
|
chpid2=$!
|
|
|
|
sleep 0.5
|
|
|
|
pid=`pgrep -f -j none $sleep`
|
|
|
|
if [ "$pid" = "$chpid" ]; then
|
|
|
|
echo "ok 3 - $name"
|
|
|
|
else
|
|
|
|
echo "not ok 3 - $name"
|
|
|
|
fi
|
|
|
|
kill $chpid $chpid2
|
|
|
|
rm -f $sleep
|
|
|
|
else
|
|
|
|
echo "ok 3 - $name # skip Test needs uid 0."
|
|
|
|
fi
|