xref: /onnv-gate/usr/src/cmd/dtrace/test/tst/common/funcs/tst.badfreopen.ksh (revision 2804:e8e3422f18c2)
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 2> $errfile <<EOF
312633Sahl	BEGIN
322633Sahl	{
332633Sahl		/*
342633Sahl		 * All of these should fail...
352633Sahl		 */
362633Sahl		freopen("..");
372633Sahl		freopen("%s", ".");
382633Sahl		freopen("%c%c", '.', '.');
392633Sahl		freopen("%c", '.');
402633Sahl
412633Sahl		/*
422633Sahl		 * ...so stdout should still be open here.
432633Sahl		 */
442633Sahl		printf("%d", ++i);
452633Sahl
462633Sahl		freopen("%s%s", ".", ".");
472633Sahl		freopen("%s%s", ".", ".");
482633Sahl
492633Sahl		printf("%d", ++i);
502633Sahl	}
512633Sahl
522633Sahl	BEGIN
532633Sahl	/i == 2/
542633Sahl	{
552633Sahl		/*
562633Sahl		 * ...and here.
572633Sahl		 */
582633Sahl		printf("%d\n", ++i);
592633Sahl		exit(0);
602633Sahl	}
612633Sahl
622633Sahl	BEGIN
632633Sahl	{
642633Sahl		exit(1);
652633Sahl	}
662633SahlEOF
672633Sahl}
682633Sahl
69*2804Stomeeif [ $# != 1 ]; then
70*2804Stomee	echo expected one argument: '<'dtrace-path'>'
71*2804Stomee	exit 2
72*2804Stomeefi
73*2804Stomee
74*2804Stomeedtrace=$1
752633Sahltmpfile=/tmp/tst.badfreopen.$$
762633Sahlerrfile=/tmp/tst.badfreopen.$$.stderr
772633Sahl
782633Sahlscript
792633Sahlstatus=$?
802633Sahl
812633Sahlif [ "$status" -eq 0 ]; then
822633Sahl	i=`cat $tmpfile`
832633Sahl
842633Sahl	if [[ $i != "123" ]]; then
852633Sahl		echo "$0: unexpected contents in $tmpfile: " \
862633Sahl		    "expected 123, found $i"
872633Sahl		status=100
882633Sahl	fi
892633Sahl
902633Sahl	i=`wc -l $errfile | nawk '{ print $1 }'`
912633Sahl
922633Sahl	if [ "$i" -lt 6 ]; then
932633Sahl		echo "$0: expected at least 6 lines of stderr, found $i lines"
942633Sahl		status=101
952633Sahl	fi
962633Sahlelse
972633Sahl	cat $errfile > /dev/fd/2
982633Sahlfi
992633Sahl
1002633Sahlrm $tmpfile $errfile
1012633Sahl
1022633Sahlexit $status
103