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# 233944Sahl# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 242633Sahl# Use is subject to license terms. 252633Sahl# 263944Sahl# ident "%Z%%M% %I% %E% SMI" 272633Sahl 282633Sahlunload() 292633Sahl{ 303944Sahl # 313944Sahl # Get the list of services whose processes have USDT probes. Ideally 323944Sahl # it would be possible to unload the fasttrap provider while USDT 333944Sahl # probes exist -- once that fix is integrated, this hack can go away 34*4821Sahl # We create two lists -- one of regular SMF services and one of legacy 35*4821Sahl # services -- since each must be enabled and disabled using a specific 36*4821Sahl # mechanism. 373944Sahl # 383944Sahl pids=$(dtrace -l | \ 393944Sahl perl -ne 'print "$1\n" if (/^\s*\S+\s+\S*\D(\d+)\s+/);' | \ 403944Sahl sort | uniq | tr '\n' ',') 413944Sahl 423944Sahl ctids=$(ps -p $pids -o ctid | tail +2 | sort | uniq) 433944Sahl svcs= 44*4821Sahl lrcs= 453944Sahl 463944Sahl for ct in $ctids 473944Sahl do 483944Sahl line=$(svcs -o fmri,ctid | grep " $ct\$") 493944Sahl svc=$(echo $line | cut -d' ' -f1) 50*4821Sahl 51*4821Sahl if [[ $(svcs -Ho STA $svc) == "LRC" ]]; then 52*4821Sahl lrc=$(svcs -Ho SVC $svc | tr _ '?') 53*4821Sahl lrcs="$lrcs $lrc" 54*4821Sahl else 55*4821Sahl svcs="$svcs $svc" 56*4821Sahl fi 573944Sahl done 583944Sahl 593944Sahl for svc in $svcs 603944Sahl do 613944Sahl svcadm disable -ts $svc 623944Sahl done 632633Sahl 64*4821Sahl for lrc in $lrcs 65*4821Sahl do 66*4821Sahl # 67*4821Sahl # Does it seem a little paternalistic that lsvcrun requires 68*4821Sahl # this environment variable to be set? I'd say so... 69*4821Sahl # 70*4821Sahl SMF_RESTARTER=svc:/system/svc/restarter:default \ 71*4821Sahl /lib/svc/bin/lsvcrun $lrc stop 72*4821Sahl done 73*4821Sahl 742633Sahl modunload -i 0 752633Sahl modunload -i 0 762633Sahl modunload -i 0 77*4821Sahl modinfo | grep dtrace 78*4821Sahl success=$? 792633Sahl 803944Sahl for svc in $svcs 813944Sahl do 823944Sahl svcadm enable -ts $svc 833944Sahl done 84*4821Sahl 85*4821Sahl for lrc in $lrcs 86*4821Sahl do 87*4821Sahl SMF_RESTARTER=svc:/system/svc/restarter:default \ 88*4821Sahl /lib/svc/bin/lsvcrun $lrc start 89*4821Sahl done 90*4821Sahl 91*4821Sahl if [ ! $success ]; then 92*4821Sahl echo $tst: could not unload dtrace 93*4821Sahl exit 1 94*4821Sahl fi 952633Sahl} 962633Sahl 972633Sahlscript1() 982633Sahl{ 992633Sahl $dtrace -s /dev/stdin <<EOF 1002633Sahl syscall:::entry 1012633Sahl /pid != $ppid/ 1022633Sahl { 1032633Sahl @a[probefunc] = count(); 1042633Sahl } 1052633Sahl 1062633Sahl tick-1sec 1072633Sahl /i++ == 5/ 1082633Sahl { 1092633Sahl exit(0); 1102633Sahl } 1112633SahlEOF 1122633Sahl} 1132633Sahl 1142633Sahlscript2() 1152633Sahl{ 1162633Sahl $dtrace -s /dev/stdin <<EOF 1172633Sahl 1182633Sahl #pragma D option statusrate=1ms 1192633Sahl 1202633Sahl syscall:::entry 1212633Sahl /pid == $ppid/ 1222633Sahl { 1232633Sahl ttl++; 1242633Sahl } 1252633Sahl 1262633Sahl tick-1sec 1272633Sahl /i++ == 5/ 1282633Sahl { 1292633Sahl exit(2); 1302633Sahl } 1312633Sahl 1322633Sahl END 1332633Sahl /ttl/ 1342633Sahl { 1352633Sahl printf("success; ttl is %d", ttl); 1362633Sahl exit(0); 1372633Sahl } 1382633Sahl 1392633Sahl END 1402633Sahl /ttl == 0/ 1412633Sahl { 1422633Sahl printf("error -- total should be non-zero"); 1432633Sahl exit(1); 1442633Sahl } 1452633SahlEOF 1462633Sahl} 1472633Sahl 1482804Stomeeif [ $# != 1 ]; then 1492804Stomee echo expected one argument: '<'dtrace-path'>' 1502804Stomee exit 2 1512804Stomeefi 1522804Stomee 1532633Sahlppid=$$ 1542804Stomeedtrace=$1 1552633Sahl 1562633Sahlunload 1572633Sahlscript1 & 1582633Sahlchild=$! 1592633Sahl 1602633Sahllet waited=0 1612633Sahl 1622633Sahlwhile [ "$waited" -lt 5 ]; do 1632633Sahl seconds=`date +%S` 1642633Sahl 1652633Sahl if [ "$seconds" -ne "$last" ]; then 1662633Sahl last=$seconds 1672633Sahl let waited=waited+1 1682633Sahl fi 1692633Sahldone 1702633Sahl 1712633Sahlwait $child 1722633Sahlstatus=$? 1732633Sahl 1742633Sahlif [ "$status" -ne 0 ]; then 1752633Sahl echo $tst: first dtrace failed 1762633Sahl exit $status 1772633Sahlfi 1782633Sahl 1792633Sahlunload 1802633Sahlscript2 & 1812633Sahlchild=$! 1822633Sahl 1832633Sahllet waited=0 1842633Sahl 1852633Sahlwhile [ "$waited" -lt 10 ]; do 1862633Sahl seconds=`date +%S` 1872633Sahl 1882633Sahl if [ "$seconds" -ne "$last" ]; then 1892633Sahl last=$seconds 1902633Sahl let waited=waited+1 1912633Sahl fi 1922633Sahldone 1932633Sahl 1942633Sahlwait $child 1952633Sahlstatus=$? 1962633Sahl 1972633Sahlexit $status 198