1 2633 ahl # 2 2633 ahl # CDDL HEADER START 3 2633 ahl # 4 2633 ahl # The contents of this file are subject to the terms of the 5 2633 ahl # Common Development and Distribution License (the "License"). 6 2633 ahl # You may not use this file except in compliance with the License. 7 2633 ahl # 8 2633 ahl # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 2633 ahl # or http://www.opensolaris.org/os/licensing. 10 2633 ahl # See the License for the specific language governing permissions 11 2633 ahl # and limitations under the License. 12 2633 ahl # 13 2633 ahl # When distributing Covered Code, include this CDDL HEADER in each 14 2633 ahl # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 2633 ahl # If applicable, add the following below this CDDL HEADER, with the 16 2633 ahl # fields enclosed by brackets "[]" replaced with your own identifying 17 2633 ahl # information: Portions Copyright [yyyy] [name of copyright owner] 18 2633 ahl # 19 2633 ahl # CDDL HEADER END 20 2633 ahl # 21 2633 ahl 22 2633 ahl # 23 3944 ahl # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 2633 ahl # Use is subject to license terms. 25 2633 ahl # 26 3944 ahl # ident "%Z%%M% %I% %E% SMI" 27 2633 ahl 28 2633 ahl unload() 29 2633 ahl { 30 3944 ahl # 31 3944 ahl # Get the list of services whose processes have USDT probes. Ideally 32 3944 ahl # it would be possible to unload the fasttrap provider while USDT 33 3944 ahl # probes exist -- once that fix is integrated, this hack can go away 34 4821 ahl # We create two lists -- one of regular SMF services and one of legacy 35 4821 ahl # services -- since each must be enabled and disabled using a specific 36 4821 ahl # mechanism. 37 3944 ahl # 38 3944 ahl pids=$(dtrace -l | \ 39 3944 ahl perl -ne 'print "$1\n" if (/^\s*\S+\s+\S*\D(\d+)\s+/);' | \ 40 3944 ahl sort | uniq | tr '\n' ',') 41 3944 ahl 42 3944 ahl ctids=$(ps -p $pids -o ctid | tail +2 | sort | uniq) 43 3944 ahl svcs= 44 4821 ahl lrcs= 45 3944 ahl 46 3944 ahl for ct in $ctids 47 3944 ahl do 48 3944 ahl line=$(svcs -o fmri,ctid | grep " $ct\$") 49 3944 ahl svc=$(echo $line | cut -d' ' -f1) 50 4821 ahl 51 4821 ahl if [[ $(svcs -Ho STA $svc) == "LRC" ]]; then 52 4821 ahl lrc=$(svcs -Ho SVC $svc | tr _ '?') 53 4821 ahl lrcs="$lrcs $lrc" 54 4821 ahl else 55 4821 ahl svcs="$svcs $svc" 56 4821 ahl fi 57 3944 ahl done 58 3944 ahl 59 3944 ahl for svc in $svcs 60 3944 ahl do 61 3944 ahl svcadm disable -ts $svc 62 3944 ahl done 63 2633 ahl 64 4821 ahl for lrc in $lrcs 65 4821 ahl do 66 4821 ahl # 67 4821 ahl # Does it seem a little paternalistic that lsvcrun requires 68 4821 ahl # this environment variable to be set? I'd say so... 69 4821 ahl # 70 4821 ahl SMF_RESTARTER=svc:/system/svc/restarter:default \ 71 4821 ahl /lib/svc/bin/lsvcrun $lrc stop 72 4821 ahl done 73 4821 ahl 74 2633 ahl modunload -i 0 75 2633 ahl modunload -i 0 76 2633 ahl modunload -i 0 77 4821 ahl modinfo | grep dtrace 78 4821 ahl success=$? 79 2633 ahl 80 3944 ahl for svc in $svcs 81 3944 ahl do 82 3944 ahl svcadm enable -ts $svc 83 3944 ahl done 84 4821 ahl 85 4821 ahl for lrc in $lrcs 86 4821 ahl do 87 4821 ahl SMF_RESTARTER=svc:/system/svc/restarter:default \ 88 4821 ahl /lib/svc/bin/lsvcrun $lrc start 89 4821 ahl done 90 4821 ahl 91 4821 ahl if [ ! $success ]; then 92 4821 ahl echo $tst: could not unload dtrace 93 4821 ahl exit 1 94 4821 ahl fi 95 2633 ahl } 96 2633 ahl 97 2633 ahl script1() 98 2633 ahl { 99 2633 ahl $dtrace -s /dev/stdin <<EOF 100 2633 ahl syscall:::entry 101 2633 ahl /pid != $ppid/ 102 2633 ahl { 103 2633 ahl @a[probefunc] = count(); 104 2633 ahl } 105 2633 ahl 106 2633 ahl tick-1sec 107 2633 ahl /i++ == 5/ 108 2633 ahl { 109 2633 ahl exit(0); 110 2633 ahl } 111 2633 ahl EOF 112 2633 ahl } 113 2633 ahl 114 2633 ahl script2() 115 2633 ahl { 116 2633 ahl $dtrace -s /dev/stdin <<EOF 117 2633 ahl 118 2633 ahl #pragma D option statusrate=1ms 119 2633 ahl 120 2633 ahl syscall:::entry 121 2633 ahl /pid == $ppid/ 122 2633 ahl { 123 2633 ahl ttl++; 124 2633 ahl } 125 2633 ahl 126 2633 ahl tick-1sec 127 2633 ahl /i++ == 5/ 128 2633 ahl { 129 2633 ahl exit(2); 130 2633 ahl } 131 2633 ahl 132 2633 ahl END 133 2633 ahl /ttl/ 134 2633 ahl { 135 2633 ahl printf("success; ttl is %d", ttl); 136 2633 ahl exit(0); 137 2633 ahl } 138 2633 ahl 139 2633 ahl END 140 2633 ahl /ttl == 0/ 141 2633 ahl { 142 2633 ahl printf("error -- total should be non-zero"); 143 2633 ahl exit(1); 144 2633 ahl } 145 2633 ahl EOF 146 2633 ahl } 147 2633 ahl 148 2804 tomee if [ $# != 1 ]; then 149 2804 tomee echo expected one argument: '<'dtrace-path'>' 150 2804 tomee exit 2 151 2804 tomee fi 152 2804 tomee 153 2633 ahl ppid=$$ 154 2804 tomee dtrace=$1 155 2633 ahl 156 2633 ahl unload 157 2633 ahl script1 & 158 2633 ahl child=$! 159 2633 ahl 160 2633 ahl let waited=0 161 2633 ahl 162 2633 ahl while [ "$waited" -lt 5 ]; do 163 2633 ahl seconds=`date +%S` 164 2633 ahl 165 2633 ahl if [ "$seconds" -ne "$last" ]; then 166 2633 ahl last=$seconds 167 2633 ahl let waited=waited+1 168 2633 ahl fi 169 2633 ahl done 170 2633 ahl 171 2633 ahl wait $child 172 2633 ahl status=$? 173 2633 ahl 174 2633 ahl if [ "$status" -ne 0 ]; then 175 2633 ahl echo $tst: first dtrace failed 176 2633 ahl exit $status 177 2633 ahl fi 178 2633 ahl 179 2633 ahl unload 180 2633 ahl script2 & 181 2633 ahl child=$! 182 2633 ahl 183 2633 ahl let waited=0 184 2633 ahl 185 2633 ahl while [ "$waited" -lt 10 ]; do 186 2633 ahl seconds=`date +%S` 187 2633 ahl 188 2633 ahl if [ "$seconds" -ne "$last" ]; then 189 2633 ahl last=$seconds 190 2633 ahl let waited=waited+1 191 2633 ahl fi 192 2633 ahl done 193 2633 ahl 194 2633 ahl wait $child 195 2633 ahl status=$? 196 2633 ahl 197 2633 ahl exit $status 198