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 2> $errfile <<EOF 31178476Sjb BEGIN 32178476Sjb { 33178476Sjb /* 34178476Sjb * All of these should fail... 35178476Sjb */ 36178476Sjb freopen(".."); 37178476Sjb freopen("%s", "."); 38178476Sjb freopen("%c%c", '.', '.'); 39178476Sjb freopen("%c", '.'); 40178476Sjb 41178476Sjb /* 42178476Sjb * ...so stdout should still be open here. 43178476Sjb */ 44178476Sjb printf("%d", ++i); 45178476Sjb 46178476Sjb freopen("%s%s", ".", "."); 47178476Sjb freopen("%s%s", ".", "."); 48178476Sjb 49178476Sjb printf("%d", ++i); 50178476Sjb } 51178476Sjb 52178476Sjb BEGIN 53178476Sjb /i == 2/ 54178476Sjb { 55178476Sjb /* 56178476Sjb * ...and here. 57178476Sjb */ 58178476Sjb printf("%d\n", ++i); 59178476Sjb exit(0); 60178476Sjb } 61178476Sjb 62178476Sjb BEGIN 63178476Sjb { 64178476Sjb exit(1); 65178476Sjb } 66178476SjbEOF 67178476Sjb} 68178476Sjb 69178476Sjbif [ $# != 1 ]; then 70178476Sjb echo expected one argument: '<'dtrace-path'>' 71178476Sjb exit 2 72178476Sjbfi 73178476Sjb 74178476Sjbdtrace=$1 75178476Sjbtmpfile=/tmp/tst.badfreopen.$$ 76178476Sjberrfile=/tmp/tst.badfreopen.$$.stderr 77178476Sjb 78178476Sjbscript 79178476Sjbstatus=$? 80178476Sjb 81178476Sjbif [ "$status" -eq 0 ]; then 82178476Sjb i=`cat $tmpfile` 83178476Sjb 84178476Sjb if [[ $i != "123" ]]; then 85178476Sjb echo "$0: unexpected contents in $tmpfile: " \ 86178476Sjb "expected 123, found $i" 87178476Sjb status=100 88178476Sjb fi 89178476Sjb 90178476Sjb i=`wc -l $errfile | nawk '{ print $1 }'` 91178476Sjb 92178476Sjb if [ "$i" -lt 6 ]; then 93178476Sjb echo "$0: expected at least 6 lines of stderr, found $i lines" 94178476Sjb status=101 95178476Sjb fi 96178476Sjbelse 97178476Sjb cat $errfile > /dev/fd/2 98178476Sjbfi 99178476Sjb 100178476Sjbrm $tmpfile $errfile 101178476Sjb 102178476Sjbexit $status 103