1178476Sjb# 2178476Sjb# CDDL HEADER START 3178476Sjb# 4178476Sjb# The contents of this file are subject to the terms of the 5178476Sjb# Common Development and Distribution License (the "License"). 6178476Sjb# You may not use this file except in compliance with the License. 7178476Sjb# 8178476Sjb# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9178476Sjb# or http://www.opensolaris.org/os/licensing. 10178476Sjb# See the License for the specific language governing permissions 11178476Sjb# and limitations under the License. 12178476Sjb# 13178476Sjb# When distributing Covered Code, include this CDDL HEADER in each 14178476Sjb# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15178476Sjb# If applicable, add the following below this CDDL HEADER, with the 16178476Sjb# fields enclosed by brackets "[]" replaced with your own identifying 17178476Sjb# information: Portions Copyright [yyyy] [name of copyright owner] 18178476Sjb# 19178476Sjb# CDDL HEADER END 20178476Sjb# 21178476Sjb 22178476Sjb# 23178476Sjb# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24178476Sjb# Use is subject to license terms. 25178476Sjb# 26178476Sjb#ident "%Z%%M% %I% %E% SMI" 27178476Sjb 28178476Sjbscript() 29178476Sjb{ 30178476Sjb $dtrace -wq -o $tmpfile -s /dev/stdin $tmpfile <<EOF 31178476Sjb BEGIN 32178476Sjb { 33178476Sjb i = 0; 34178476Sjb } 35178476Sjb 36178476Sjb tick-10ms 37178476Sjb { 38178476Sjb freopen("%s.%d", \$\$1, i); 39178476Sjb printf("%d\n", i) 40178476Sjb } 41178476Sjb 42178476Sjb tick-10ms 43178476Sjb /++i == $iter/ 44178476Sjb { 45178476Sjb freopen(""); 46178476Sjb printf("%d\n", i); 47178476Sjb exit(0); 48178476Sjb } 49178476SjbEOF 50178476Sjb} 51178476Sjb 52178476Sjbcleanup() 53178476Sjb{ 54178476Sjb let i=0 55178476Sjb 56178476Sjb if [ -f $tmpfile ]; then 57178476Sjb rm $tmpfile 58178476Sjb fi 59178476Sjb 60178476Sjb while [ "$i" -lt "$iter" ]; do 61178476Sjb if [ -f $tmpfile.$i ]; then 62178476Sjb rm $tmpfile.$i 63178476Sjb fi 64178476Sjb let i=i+1 65178476Sjb done 66178476Sjb} 67178476Sjb 68178476Sjbif [ $# != 1 ]; then 69178476Sjb echo expected one argument: '<'dtrace-path'>' 70178476Sjb exit 2 71178476Sjbfi 72178476Sjb 73178476Sjbdtrace=$1 74178476Sjbtmpfile=/tmp/tst.freopen.$$ 75178476Sjbiter=20 76178476Sjb 77178476Sjbscript 78178476Sjbstatus=$? 79178476Sjb 80178476Sjblet i=0 81178476Sjb 82178476Sjbif [ -f $tmpfile.$iter ]; then 83178476Sjb echo "$0: did not expect to find file: $tmpfile.$iter" 84178476Sjb cleanup 85178476Sjb exit 100 86178476Sjbfi 87178476Sjb 88178476Sjbmv $tmpfile $tmpfile.$iter 89178476Sjblet iter=iter+1 90178476Sjb 91178476Sjbwhile [ "$i" -lt "$iter" ]; do 92178476Sjb if [ ! -f $tmpfile.$i ]; then 93178476Sjb echo "$0: did not find expected file: $tmpfile.$i" 94178476Sjb cleanup 95178476Sjb exit 101 96178476Sjb fi 97178476Sjb 98178476Sjb j=`cat $tmpfile.$i` 99178476Sjb 100178476Sjb if [ "$i" -ne "$j" ]; then 101178476Sjb echo "$0: unexpected contents in $tmpfile.$i: " \ 102178476Sjb "expected $i, found $j" 103178476Sjb cleanup 104178476Sjb exit 102 105178476Sjb fi 106178476Sjb 107178476Sjb rm $tmpfile.$i 108178476Sjb let i=i+1 109178476Sjbdone 110178476Sjb 111178476Sjbexit $status 112