pkill-j_test.sh revision 963c317160962081a48ff2448abdedf53e6b99c7
1#!/bin/sh
2# $FreeBSD$
3
4jail_name_to_jid()
5{
6	local check_name="$1"
7	jls -j "$check_name" -s 2>/dev/null | tr ' ' '\n' | grep jid= | sed -e 's/.*=//g'
8}
9
10base=pkill_j_test
11
12if [ `id -u` -ne 0 ]; then
13	echo "1..0 # skip Test needs uid 0."
14	exit 0
15fi
16
17echo "1..3"
18
19sleep=$(pwd)/sleep.txt
20ln -sf /bin/sleep $sleep
21
22name="pkill -j <jid>"
23sleep_amount=5
24jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
25    command=daemon -p ${PWD}/${base}_1_1.pid $sleep $sleep_amount &
26
27jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
28    command=daemon -p ${PWD}/${base}_1_2.pid $sleep $sleep_amount &
29
30$sleep $sleep_amount &
31
32for i in `seq 1 10`; do
33	jid1=$(jail_name_to_jid ${base}_1_1)
34	jid2=$(jail_name_to_jid ${base}_1_2)
35	jid="${jid1},${jid2}"
36	case "$jid" in
37	[0-9]+,[0-9]+)
38		break
39		;;
40	esac
41	sleep 0.1
42done
43
44if pkill -f -j "$jid" $sleep && sleep 0.5 &&
45    ! -f ${PWD}/${base}_1_1.pid &&
46    ! -f ${PWD}/${base}_1_2.pid ; then
47	echo "ok 1 - $name"
48else
49	echo "not ok 1 - $name"
50fi 2>/dev/null
51[ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
52[ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
53wait
54
55name="pkill -j any"
56sleep_amount=6
57jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
58    command=daemon -p ${PWD}/${base}_2_1.pid $sleep $sleep_amount &
59
60jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
61    command=daemon -p ${PWD}/${base}_2_2.pid $sleep $sleep_amount &
62
63$sleep $sleep_amount &
64chpid3=$!
65sleep 0.5
66if pkill -f -j any $sleep && sleep 0.5 &&
67    [ ! -f ${PWD}/${base}_2_1.pid -a
68      ! -f ${PWD}/${base}_2_2.pid ] && kill $chpid3; then
69	echo "ok 2 - $name"
70else
71	echo "not ok 2 - $name"
72fi 2>/dev/null
73[ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
74[ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
75wait
76
77name="pkill -j none"
78sleep_amount=7
79daemon -p ${PWD}/${base}_3_1.pid $sleep $sleep_amount
80jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
81    command=daemon -p ${PWD}/${base}_3_2.pid $sleep $sleep_amount &
82sleep 1
83if pkill -f -j none "$sleep $sleep_amount" && sleep 1 &&
84    [ ! -f ${PWD}/${base}_3_1.pid -a -f ${PWD}/${base}_3_2.pid ] ; then
85	echo "ok 3 - $name"
86else
87	ls ${PWD}/*.pid
88	echo "not ok 3 - $name"
89fi 2>/dev/null
90[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
91[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
92
93rm -f $sleep
94