14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#/bin/ksh -p
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# or http://www.opensolaris.org/os/licensing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Use is subject to license terms.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# ident "%Z%%M% %I% %E% SMI"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# This script verifies that user-land stacks can be walked safely
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# when the trapstat(1M) utility is running. An arbitrary program, w(1),
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# is started once a second to ensure stacks can be walked at all stages
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# of the process lifecycle.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncscript()
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync $dtrace -o $dtraceout -s /dev/stdin <<EOF
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt:::
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync @[ustackdepth] = count();
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncEOF
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncrun_commands()
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cnt=0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while [ $cnt -lt 10 ]; do
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync w > /dev/null
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync sleep 1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cnt=$(($cnt+1))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync done
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncif [ $# != 1 ]; then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync echo expected one argument: '<'dtrace-path'>'
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync exit 2
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfi
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace=$1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtraceout=/tmp/dtrace.out.$$
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncscript 2>/dev/null &
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctimeout=15
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Sleep while the above script fires into life. To guard against dtrace dying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# and us sleeping forever we allow 15 secs for this to happen. This should be
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# enough for even the slowest systems.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncwhile [ ! -f $dtraceout ]; do
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync sleep 1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync timeout=$(($timeout-1))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if [ $timeout -eq 0 ]; then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync echo "dtrace failed to start. Exiting."
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync exit 1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fi
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdone
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncrun_commands &
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctrapstat -t 1 10
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatus=$?
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncrm $dtraceout
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncexit $status