summaryrefslogtreecommitdiff
path: root/bin/pkill
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2014-11-19 01:07:58 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2014-11-19 01:07:58 +0000
commit9268022b74279434ed6300244e3f977e56a8ceb5 (patch)
tree377ac0ac449528621eb192cd245adadb5fd53668 /bin/pkill
parent29c34e9d2781cf25403647fb5af7d7ddb23be7e1 (diff)
parent8c3d6a4ab2a4a95d864d9a32d0157d7de90498a4 (diff)
downloadsrc-test-9268022b74279434ed6300244e3f977e56a8ceb5.tar.gz
src-test-9268022b74279434ed6300244e3f977e56a8ceb5.zip
Merge from head@274682
Notes
Notes: svn path=/projects/bmake/; revision=274683
Diffstat (limited to 'bin/pkill')
-rw-r--r--bin/pkill/tests/Makefile2
-rw-r--r--bin/pkill/tests/pgrep-j_test.sh84
-rw-r--r--bin/pkill/tests/pkill-j_test.sh75
3 files changed, 108 insertions, 53 deletions
diff --git a/bin/pkill/tests/Makefile b/bin/pkill/tests/Makefile
index b131d59256677..a4a2c915182fc 100644
--- a/bin/pkill/tests/Makefile
+++ b/bin/pkill/tests/Makefile
@@ -14,6 +14,7 @@ TAP_TESTS_SH+= pgrep-g_test
TAP_TESTS_SH+= pgrep-i_test
TAP_TESTS_SH+= pgrep-j_test
TEST_METADATA.pgrep-j_test+= required_user="root"
+TEST_METADATA.pgrep-j_test+= required_programs="jail jls"
TAP_TESTS_SH+= pgrep-l_test
TAP_TESTS_SH+= pgrep-n_test
TAP_TESTS_SH+= pgrep-o_test
@@ -31,6 +32,7 @@ TAP_TESTS_SH+= pkill-g_test
TAP_TESTS_SH+= pkill-i_test
TAP_TESTS_SH+= pkill-j_test
TEST_METADATA.pkill-j_test+= required_user="root"
+TEST_METADATA.pkill-j_test+= required_programs="jail jls"
TAP_TESTS_SH+= pkill-s_test
TAP_TESTS_SH+= pkill-t_test
TAP_TESTS_SH+= pkill-x_test
diff --git a/bin/pkill/tests/pgrep-j_test.sh b/bin/pkill/tests/pgrep-j_test.sh
index 6656a9bd789fb..6acfb4be35adf 100644
--- a/bin/pkill/tests/pgrep-j_test.sh
+++ b/bin/pkill/tests/pgrep-j_test.sh
@@ -1,7 +1,23 @@
#!/bin/sh
# $FreeBSD$
-base=`basename $0`
+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=pgrep_j_test
echo "1..3"
@@ -9,21 +25,25 @@ name="pgrep -j <jid>"
if [ `id -u` -eq 0 ]; then
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
- jail / $base-1 127.0.0.1 $sleep 5 &
- chpid=$!
- 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}"`
- pid=`pgrep -f -j $jid $sleep`
- if [ "$pid" = "$chpid" ]; then
+ 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 &
+
+ jid1=$(jail_name_to_jid ${base}_1_1)
+ jid2=$(jail_name_to_jid ${base}_1_2)
+ jid="${jid1},${jid2}"
+ pid1="$(pgrep -f -x -j $jid "$sleep 5" | sort)"
+ pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_1_1.pid)" \
+ $(cat ${PWD}/${base}_1_2.pid) | sort)
+ if [ "$pid1" = "$pid2" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
- kill $chpid $chpid2 $chpid3
+ [ -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)
rm -f $sleep
else
echo "ok 1 - $name # skip Test needs uid 0."
@@ -33,21 +53,23 @@ name="pgrep -j any"
if [ `id -u` -eq 0 ]; then
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
- jail / $base-1 127.0.0.1 $sleep 5 &
- chpid=$!
- 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
+ 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 &
+
+ sleep 2
+ pid1="$(pgrep -f -x -j any "$sleep 5" | sort)"
+ pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_2_1.pid)" \
+ $(cat ${PWD}/${base}_2_2.pid) | sort)
+ if [ "$pid1" = "$pid2" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
- kill $chpid $chpid2 $chpid3
+ [ -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)
rm -f $sleep
else
echo "ok 2 - $name # skip Test needs uid 0."
@@ -57,19 +79,19 @@ name="pgrep -j none"
if [ `id -u` -eq 0 ]; then
sleep=$(pwd)/sleep.txt
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
+ 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 2
+ pid="$(pgrep -f -x -j none "$sleep 5")"
+ if [ "$pid" = "$(cat ${PWD}/${base}_3_1.pid)" ]; then
echo "ok 3 - $name"
else
echo "not ok 3 - $name"
fi
- kill $chpid $chpid2
rm -f $sleep
+ [ -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)
else
echo "ok 3 - $name # skip Test needs uid 0."
fi
diff --git a/bin/pkill/tests/pkill-j_test.sh b/bin/pkill/tests/pkill-j_test.sh
index 48e7c721bbecc..a844149cedb04 100644
--- a/bin/pkill/tests/pkill-j_test.sh
+++ b/bin/pkill/tests/pkill-j_test.sh
@@ -1,7 +1,23 @@
#!/bin/sh
# $FreeBSD$
-base=`basename $0`
+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
echo "1..3"
@@ -9,21 +25,28 @@ name="pkill -j <jid>"
if [ `id -u` -eq 0 ]; then
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
- jail / $base-1 127.0.0.1 $sleep 5 &
- chpid=$!
- jail / $base-2 127.0.0.1 $sleep 5 &
- chpid2=$!
+ 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 &
+
$sleep 5 &
- chpid3=$!
sleep 0.5
- jid=`jls | awk "/127\\.0\\.0\\.1.*${base}-1/ {print \$1}"`
- if pkill -f -j $jid $sleep && sleep 0.5 &&
- ! kill $chpid && kill $chpid2 $chpid3; then
+ 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
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi 2>/dev/null
rm -f $sleep
+ [ -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
else
echo "ok 1 - $name # skip Test needs uid 0."
fi
@@ -32,20 +55,26 @@ name="pkill -j any"
if [ `id -u` -eq 0 ]; then
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
- jail / $base-1 127.0.0.1 $sleep 5 &
- chpid=$!
- jail / $base-2 127.0.0.1 $sleep 5 &
- chpid2=$!
+ 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 &
+
$sleep 5 &
- chpid3=$!
sleep 0.5
+ chpid3=$!
if pkill -f -j any $sleep && sleep 0.5 &&
- ! kill $chpid && ! kill $chpid2 && kill $chpid3; then
+ [ ! -f ${PWD}/${base}_2_1.pid -a
+ ! -f ${PWD}/${base}_2_2.pid ] && kill $chpid3; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi 2>/dev/null
rm -f $sleep
+ [ -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
else
echo "ok 2 - $name # skip Test needs uid 0."
fi
@@ -54,18 +83,20 @@ name="pkill -j none"
if [ `id -u` -eq 0 ]; then
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
- $sleep 5 &
- chpid=$!
- jail / $base 127.0.0.1 $sleep 5 &
- chpid2=$!
- sleep 0.5
- if pkill -f -j none $sleep && sleep 0.5 &&
- ! kill $chpid && kill $chpid2; then
+ 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
echo "ok 3 - $name"
else
+ ls ${PWD}/*.pid
echo "not ok 3 - $name"
fi 2>/dev/null
rm -f $sleep
+ [ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
+ [ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
else
echo "ok 3 - $name # skip Test needs uid 0."
fi