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