1#!/bin/sh 2# $FreeBSD$ 3 4jail_name_to_jid() 5{ 6 local check_name="$1" 7 jls -j "$check_name" -s | 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..4" 18 19sleep=$(pwd)/sleep.txt 20ln -sf /bin/sleep $sleep 21 22name="pkill -j <jid>" 23sleep_amount=15 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 43sleep 0.5 44 45if pkill -f -j "$jid" $sleep && sleep 0.5 && 46 ! -f ${PWD}/${base}_1_1.pid && 47 ! -f ${PWD}/${base}_1_2.pid ; then 48 echo "ok 1 - $name" 49else 50 echo "not ok 1 - $name" 51fi 2>/dev/null 52[ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid) 53[ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid) 54wait 55 56name="pkill -j any" 57sleep_amount=16 58jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \ 59 command=daemon -p ${PWD}/${base}_2_1.pid $sleep $sleep_amount & 60 61jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \ 62 command=daemon -p ${PWD}/${base}_2_2.pid $sleep $sleep_amount & 63 64$sleep $sleep_amount & 65chpid3=$! 66sleep 0.5 67if pkill -f -j any $sleep && sleep 0.5 && 68 [ ! -f ${PWD}/${base}_2_1.pid -a 69 ! -f ${PWD}/${base}_2_2.pid ] && kill $chpid3; then 70 echo "ok 2 - $name" 71else 72 echo "not ok 2 - $name" 73fi 2>/dev/null 74[ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid) 75[ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid) 76wait 77 78name="pkill -j none" 79sleep_amount=17 80daemon -p ${PWD}/${base}_3_1.pid $sleep $sleep_amount 81jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \ 82 command=daemon -p ${PWD}/${base}_3_2.pid $sleep $sleep_amount & 83sleep 1 84if pkill -f -j none "$sleep $sleep_amount" && sleep 1 && 85 [ ! -f ${PWD}/${base}_3_1.pid -a -f ${PWD}/${base}_3_2.pid ] ; then 86 echo "ok 3 - $name" 87else 88 ls ${PWD}/*.pid 89 echo "not ok 3 - $name" 90fi 2>/dev/null 91[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid) 92[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid) 93wait 94 95# test 4 is like test 1 except with jname instead of jid. 96name="pkill -j <jname>" 97sleep_amount=18 98jail -c path=/ name=${base}_4_1 ip4.addr=127.0.0.1 \ 99 command=daemon -p ${PWD}/${base}_4_1.pid $sleep $sleep_amount & 100 101jail -c path=/ name=${base}_4_2 ip4.addr=127.0.0.1 \ 102 command=daemon -p ${PWD}/${base}_4_2.pid $sleep $sleep_amount & 103 104$sleep $sleep_amount & 105 106sleep 0.5 107 108jname="${base}_4_1,${base}_4_2" 109if pkill -f -j "$jname" $sleep && sleep 0.5 && 110 ! -f ${PWD}/${base}_4_1.pid && 111 ! -f ${PWD}/${base}_4_2.pid ; then 112 echo "ok 4 - $name" 113else 114 echo "not ok 4 - $name" 115fi 2>/dev/null 116[ -f ${PWD}/${base}_4_1.pid ] && kill $(cat ${PWD}/${base}_4_1.pid) 117[ -f ${PWD}/${base}_4_2.pid ] && kill $(cat ${PWD}/${base}_4_2.pid) 118wait 119 120rm -f $sleep 121