12633Sahl# 22633Sahl# CDDL HEADER START 32633Sahl# 42633Sahl# The contents of this file are subject to the terms of the 52633Sahl# Common Development and Distribution License (the "License"). 62633Sahl# You may not use this file except in compliance with the License. 72633Sahl# 82633Sahl# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92633Sahl# or http://www.opensolaris.org/os/licensing. 102633Sahl# See the License for the specific language governing permissions 112633Sahl# and limitations under the License. 122633Sahl# 132633Sahl# When distributing Covered Code, include this CDDL HEADER in each 142633Sahl# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152633Sahl# If applicable, add the following below this CDDL HEADER, with the 162633Sahl# fields enclosed by brackets "[]" replaced with your own identifying 172633Sahl# information: Portions Copyright [yyyy] [name of copyright owner] 182633Sahl# 192633Sahl# CDDL HEADER END 202633Sahl# 212633Sahl 222633Sahl# 232633Sahl# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 242633Sahl# Use is subject to license terms. 252633Sahl# 262633Sahl#ident "%Z%%M% %I% %E% SMI" 272633Sahl 282633Sahlscript() 292633Sahl{ 302633Sahl $dtrace -wq -o $tmpfile -s /dev/stdin $tmpfile <<EOF 312633Sahl BEGIN 322633Sahl { 332633Sahl i = 0; 342633Sahl } 352633Sahl 362633Sahl tick-10ms 372633Sahl { 382633Sahl freopen("%s.%d", \$\$1, i); 392633Sahl printf("%d\n", i) 402633Sahl } 412633Sahl 422633Sahl tick-10ms 432633Sahl /++i == $iter/ 442633Sahl { 452633Sahl freopen(""); 462633Sahl printf("%d\n", i); 472633Sahl exit(0); 482633Sahl } 492633SahlEOF 502633Sahl} 512633Sahl 522633Sahlcleanup() 532633Sahl{ 542633Sahl let i=0 552633Sahl 562633Sahl if [ -f $tmpfile ]; then 572633Sahl rm $tmpfile 582633Sahl fi 592633Sahl 602633Sahl while [ "$i" -lt "$iter" ]; do 612633Sahl if [ -f $tmpfile.$i ]; then 622633Sahl rm $tmpfile.$i 632633Sahl fi 642633Sahl let i=i+1 652633Sahl done 662633Sahl} 672633Sahl 68*2804Stomeeif [ $# != 1 ]; then 69*2804Stomee echo expected one argument: '<'dtrace-path'>' 70*2804Stomee exit 2 71*2804Stomeefi 72*2804Stomee 73*2804Stomeedtrace=$1 742633Sahltmpfile=/tmp/tst.freopen.$$ 752633Sahliter=20 762633Sahl 772633Sahlscript 782633Sahlstatus=$? 792633Sahl 802633Sahllet i=0 812633Sahl 822633Sahlif [ -f $tmpfile.$iter ]; then 832633Sahl echo "$0: did not expect to find file: $tmpfile.$iter" 842633Sahl cleanup 852633Sahl exit 100 862633Sahlfi 872633Sahl 882633Sahlmv $tmpfile $tmpfile.$iter 892633Sahllet iter=iter+1 902633Sahl 912633Sahlwhile [ "$i" -lt "$iter" ]; do 922633Sahl if [ ! -f $tmpfile.$i ]; then 932633Sahl echo "$0: did not find expected file: $tmpfile.$i" 942633Sahl cleanup 952633Sahl exit 101 962633Sahl fi 972633Sahl 982633Sahl j=`cat $tmpfile.$i` 992633Sahl 1002633Sahl if [ "$i" -ne "$j" ]; then 1012633Sahl echo "$0: unexpected contents in $tmpfile.$i: " \ 1022633Sahl "expected $i, found $j" 1032633Sahl cleanup 1042633Sahl exit 102 1052633Sahl fi 1062633Sahl 1072633Sahl rm $tmpfile.$i 1082633Sahl let i=i+1 1092633Sahldone 1102633Sahl 1112633Sahlexit $status 112