svn commit: r278742 - head/bin/pkill/tests

Garrett Cooper ngie at FreeBSD.org
Sat Feb 14 06:19:25 UTC 2015


Author: ngie
Date: Sat Feb 14 06:19:24 2015
New Revision: 278742
URL: https://svnweb.freebsd.org/changeset/base/278742

Log:
  Simplify jail_name_to_jid and try to be more fault tolerant when scanning for
  the jail ID (poll up to 10 times for the jail IDs to become available)
  
  If the scan fails, the code will fall through and fail as it does with Jenkins
  today

Modified:
  head/bin/pkill/tests/pgrep-j_test.sh

Modified: head/bin/pkill/tests/pgrep-j_test.sh
==============================================================================
--- head/bin/pkill/tests/pgrep-j_test.sh	Sat Feb 14 04:28:51 2015	(r278741)
+++ head/bin/pkill/tests/pgrep-j_test.sh	Sat Feb 14 06:19:24 2015	(r278742)
@@ -4,17 +4,7 @@
 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
-	)
+	jls -j "$check_name" -s 2>/dev/null | tr ' ' '\n' | grep jid= | sed -e 's/.*=//g'
 }
 
 base=pgrep_j_test
@@ -37,10 +27,19 @@ jail -c path=/ name=${base}_1_1 ip4.addr
 jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
     command=daemon -p ${PWD}/${base}_1_2.pid $sleep $sleep_amount &
 
-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 $sleep_amount" | sort)"
+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
+
+pid1="$(pgrep -f -x -j "$jid" "$sleep $sleep_amount" | sort)"
 pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_1_1.pid)" \
     $(cat ${PWD}/${base}_1_2.pid) | sort)
 if [ "$pid1" = "$pid2" ]; then


More information about the svn-src-head mailing list