17c478bd9Sstevel@tonic-gate#!/bin/ksh -p
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*20c1c355SRod Evans# Common Development and Distribution License (the "License").
7*20c1c355SRod Evans# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
22*20c1c355SRod Evans# Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate
247c478bd9Sstevel@tonic-gateusage() {
257c478bd9Sstevel@tonic-gate	echo "usage: sotruss [-F:-T:-o:-f] utility [utility arguments]"
267c478bd9Sstevel@tonic-gate	echo "	-F <bindfromlist>"
277c478bd9Sstevel@tonic-gate	echo "		A colon seperated list of libraries that are to be"
287c478bd9Sstevel@tonic-gate	echo "		traced.  Only calls from these libraries will be"
297c478bd9Sstevel@tonic-gate	echo "		traced.  The default is to trace calls from the"
307c478bd9Sstevel@tonic-gate	echo "		main executable."
317c478bd9Sstevel@tonic-gate	echo "	-T <bindtolist>"
327c478bd9Sstevel@tonic-gate	echo "		A colon seperated list of libraries that are to be"
337c478bd9Sstevel@tonic-gate	echo "		traced.  Only calls to these libraries will be"
347c478bd9Sstevel@tonic-gate	echo "		traced.  The default is to trace all calls."
357c478bd9Sstevel@tonic-gate	echo "	-o <outputfile>"
367c478bd9Sstevel@tonic-gate	echo "		sotruss output will be directed to 'outputfile'."
377c478bd9Sstevel@tonic-gate	echo "		by default it is placed on stdout."
387c478bd9Sstevel@tonic-gate	echo "	-f"
397c478bd9Sstevel@tonic-gate	echo "		Follow all children created by fork() and also"
407c478bd9Sstevel@tonic-gate	echo "		print truss output for the children.  This also"
417c478bd9Sstevel@tonic-gate	echo "		causes a 'pid' to be added to each truss output line."
427c478bd9Sstevel@tonic-gate}
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gatebindto=""
457c478bd9Sstevel@tonic-gatebindfrom=""
467c478bd9Sstevel@tonic-gateoutfile=""
477c478bd9Sstevel@tonic-gatenoindentopt=""
487c478bd9Sstevel@tonic-gatetrusslib32="/usr/lib/link_audit/32/truss.so.1"
497c478bd9Sstevel@tonic-gatetrusslib64="/usr/lib/link_audit/64/truss.so.1"
507c478bd9Sstevel@tonic-gatepidopt=""
517c478bd9Sstevel@tonic-gatenoexitopt="1"
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gateoptlet="eF:T:o:fl:i"
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gateif [[ $# -lt 1 ]]; then
567c478bd9Sstevel@tonic-gate	usage
577c478bd9Sstevel@tonic-gate	exit 1
587c478bd9Sstevel@tonic-gatefi
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gatewhile getopts $optlet c
617c478bd9Sstevel@tonic-gatedo
627c478bd9Sstevel@tonic-gate	case $c in
637c478bd9Sstevel@tonic-gate	F)
647c478bd9Sstevel@tonic-gate		bindfrom="$OPTARG"
657c478bd9Sstevel@tonic-gate		;;
667c478bd9Sstevel@tonic-gate	T)
677c478bd9Sstevel@tonic-gate		bindto="$OPTARG"
687c478bd9Sstevel@tonic-gate		;;
697c478bd9Sstevel@tonic-gate	o)
707c478bd9Sstevel@tonic-gate		outfile="$OPTARG"
717c478bd9Sstevel@tonic-gate		;;
727c478bd9Sstevel@tonic-gate	l)
737c478bd9Sstevel@tonic-gate		trusslib32="$OPTARG"
747c478bd9Sstevel@tonic-gate		trusslib64="$OPTARG"
757c478bd9Sstevel@tonic-gate		;;
767c478bd9Sstevel@tonic-gate	f)
777c478bd9Sstevel@tonic-gate		pidopt="1"
787c478bd9Sstevel@tonic-gate		;;
797c478bd9Sstevel@tonic-gate	i)
807c478bd9Sstevel@tonic-gate		noindentopt="1"
817c478bd9Sstevel@tonic-gate		;;
827c478bd9Sstevel@tonic-gate	e)
837c478bd9Sstevel@tonic-gate		noexitopt=""
847c478bd9Sstevel@tonic-gate		;;
857c478bd9Sstevel@tonic-gate	\?)
867c478bd9Sstevel@tonic-gate		usage
877c478bd9Sstevel@tonic-gate		exit 1
887c478bd9Sstevel@tonic-gate		;;
897c478bd9Sstevel@tonic-gate	esac
907c478bd9Sstevel@tonic-gatedone
917c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate#
947c478bd9Sstevel@tonic-gate# Build environment variables
957c478bd9Sstevel@tonic-gate#
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gateTRUSS_BINDTO="$bindto" \
987c478bd9Sstevel@tonic-gateTRUSS_BINDFROM="$bindfrom" \
997c478bd9Sstevel@tonic-gateTRUSS_OUTPUT="$outfile" \
1007c478bd9Sstevel@tonic-gateTRUSS_PID="$pidopt" \
1017c478bd9Sstevel@tonic-gateTRUSS_NOINDENT="$noindentopt" \
1027c478bd9Sstevel@tonic-gateTRUSS_NOEXIT="$noexitopt" \
1037c478bd9Sstevel@tonic-gateLD_AUDIT_32="$trusslib32" \
1047c478bd9Sstevel@tonic-gateLD_AUDIT_64="$trusslib64" \
1057c478bd9Sstevel@tonic-gate"$@"
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gateexit 0
108