aboutsummaryrefslogtreecommitdiff
path: root/bin/pkill/tests/pkill-j_test.sh
blob: 26e185fc89882038b497963700d2262385ceda2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
# $FreeBSD$

jail_name_to_jid()
{
	local check_name="$1"
	jls -j "$check_name" -s | tr ' ' '\n' | grep jid= | sed -e 's/.*=//g'
}

base=pkill_j_test

if [ `id -u` -ne 0 ]; then
	echo "1..0 # skip Test needs uid 0."
	exit 0
fi

echo "1..3"

sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep

name="pkill -j <jid>"
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 &

jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
    command=daemon -p ${PWD}/${base}_1_2.pid $sleep $sleep_amount &

$sleep $sleep_amount &

for i in `seq 1 10`; do
	jid1=$(jail_name_to_jid ${base}_1_1)
	jid2=$(jail_name_to_jid ${base}_1_2)
	jid="${jid1},${jid2}"
	case "$jid" in
	[0-9]+,[0-9]+)
		break
		;;
	esac
	sleep 0.1
done
sleep 0.5

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
[ -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

name="pkill -j any"
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 &

jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
    command=daemon -p ${PWD}/${base}_2_2.pid $sleep $sleep_amount &

$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"
else
	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

name="pkill -j none"
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"
else
	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)

rm -f $sleep