9512fe850e98fdd448c638ca63fdd92a8a510255ahl#
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# CDDL HEADER START
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# The contents of this file are subject to the terms of the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# Common Development and Distribution License (the "License").
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# You may not use this file except in compliance with the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# or http://www.opensolaris.org/os/licensing.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# See the License for the specific language governing permissions
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# and limitations under the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# When distributing Covered Code, include this CDDL HEADER in each
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# If applicable, add the following below this CDDL HEADER, with the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# fields enclosed by brackets "[]" replaced with your own identifying
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# information: Portions Copyright [yyyy] [name of copyright owner]
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# CDDL HEADER END
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# Use is subject to license terms.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#ident "%Z%%M% %I% %E% SMI"
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlscript()
9512fe850e98fdd448c638ca63fdd92a8a510255ahl{
9512fe850e98fdd448c638ca63fdd92a8a510255ahl $dtrace -wq -o $tmpfile -s /dev/stdin $tmpfile <<EOF
9512fe850e98fdd448c638ca63fdd92a8a510255ahl BEGIN
9512fe850e98fdd448c638ca63fdd92a8a510255ahl {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl i = 0;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl }
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl tick-10ms
9512fe850e98fdd448c638ca63fdd92a8a510255ahl {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl freopen("%s.%d", \$\$1, i);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("%d\n", i)
9512fe850e98fdd448c638ca63fdd92a8a510255ahl }
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl tick-10ms
9512fe850e98fdd448c638ca63fdd92a8a510255ahl /++i == $iter/
9512fe850e98fdd448c638ca63fdd92a8a510255ahl {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl freopen("");
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("%d\n", i);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(0);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl }
9512fe850e98fdd448c638ca63fdd92a8a510255ahlEOF
9512fe850e98fdd448c638ca63fdd92a8a510255ahl}
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlcleanup()
9512fe850e98fdd448c638ca63fdd92a8a510255ahl{
9512fe850e98fdd448c638ca63fdd92a8a510255ahl let i=0
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if [ -f $tmpfile ]; then
9512fe850e98fdd448c638ca63fdd92a8a510255ahl rm $tmpfile
9512fe850e98fdd448c638ca63fdd92a8a510255ahl fi
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl while [ "$i" -lt "$iter" ]; do
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if [ -f $tmpfile.$i ]; then
9512fe850e98fdd448c638ca63fdd92a8a510255ahl rm $tmpfile.$i
9512fe850e98fdd448c638ca63fdd92a8a510255ahl fi
9512fe850e98fdd448c638ca63fdd92a8a510255ahl let i=i+1
9512fe850e98fdd448c638ca63fdd92a8a510255ahl done
9512fe850e98fdd448c638ca63fdd92a8a510255ahl}
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomeeif [ $# != 1 ]; then
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee echo expected one argument: '<'dtrace-path'>'
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee exit 2
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomeefi
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomeedtrace=$1
9512fe850e98fdd448c638ca63fdd92a8a510255ahltmpfile=/tmp/tst.freopen.$$
9512fe850e98fdd448c638ca63fdd92a8a510255ahliter=20
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlscript
9512fe850e98fdd448c638ca63fdd92a8a510255ahlstatus=$?
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahllet i=0
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlif [ -f $tmpfile.$iter ]; then
9512fe850e98fdd448c638ca63fdd92a8a510255ahl echo "$0: did not expect to find file: $tmpfile.$iter"
9512fe850e98fdd448c638ca63fdd92a8a510255ahl cleanup
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit 100
9512fe850e98fdd448c638ca63fdd92a8a510255ahlfi
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlmv $tmpfile $tmpfile.$iter
9512fe850e98fdd448c638ca63fdd92a8a510255ahllet iter=iter+1
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlwhile [ "$i" -lt "$iter" ]; do
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if [ ! -f $tmpfile.$i ]; then
9512fe850e98fdd448c638ca63fdd92a8a510255ahl echo "$0: did not find expected file: $tmpfile.$i"
9512fe850e98fdd448c638ca63fdd92a8a510255ahl cleanup
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit 101
9512fe850e98fdd448c638ca63fdd92a8a510255ahl fi
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl j=`cat $tmpfile.$i`
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if [ "$i" -ne "$j" ]; then
9512fe850e98fdd448c638ca63fdd92a8a510255ahl echo "$0: unexpected contents in $tmpfile.$i: " \
9512fe850e98fdd448c638ca63fdd92a8a510255ahl "expected $i, found $j"
9512fe850e98fdd448c638ca63fdd92a8a510255ahl cleanup
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit 102
9512fe850e98fdd448c638ca63fdd92a8a510255ahl fi
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl rm $tmpfile.$i
9512fe850e98fdd448c638ca63fdd92a8a510255ahl let i=i+1
9512fe850e98fdd448c638ca63fdd92a8a510255ahldone
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlexit $status