1 4821 ahl #!/bin/ksh -p 2 4821 ahl # 3 4821 ahl # CDDL HEADER START 4 4821 ahl # 5 4821 ahl # The contents of this file are subject to the terms of the 6 4821 ahl # Common Development and Distribution License (the "License"). 7 4821 ahl # You may not use this file except in compliance with the License. 8 4821 ahl # 9 4821 ahl # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 4821 ahl # or http://www.opensolaris.org/os/licensing. 11 4821 ahl # See the License for the specific language governing permissions 12 4821 ahl # and limitations under the License. 13 4821 ahl # 14 4821 ahl # When distributing Covered Code, include this CDDL HEADER in each 15 4821 ahl # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 4821 ahl # If applicable, add the following below this CDDL HEADER, with the 17 4821 ahl # fields enclosed by brackets "[]" replaced with your own identifying 18 4821 ahl # information: Portions Copyright [yyyy] [name of copyright owner] 19 4821 ahl # 20 4821 ahl # CDDL HEADER END 21 4821 ahl # 22 4821 ahl 23 4821 ahl # 24 4821 ahl # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25 4821 ahl # Use is subject to license terms. 26 4821 ahl # 27 4821 ahl # ident "%Z%%M% %I% %E% SMI" 28 4821 ahl 29 4821 ahl # 30 4821 ahl # This test verifies that performing a dlclose(3dl) on a library doesn't 31 4821 ahl # cause existing pid provider probes to become invalid. 32 4821 ahl # 33 4821 ahl 34 4821 ahl if [ $# != 1 ]; then 35 4821 ahl echo expected one argument: '<'dtrace-path'>' 36 4821 ahl exit 2 37 4821 ahl fi 38 4821 ahl 39 4821 ahl dtrace=$1 40 4821 ahl DIR=/var/tmp/dtest.$$ 41 4821 ahl 42 4821 ahl mkdir $DIR 43 4821 ahl cd $DIR 44 4821 ahl 45 4821 ahl cat > Makefile <<EOF 46 4821 ahl all: main livelib.so deadlib.so 47 4821 ahl 48 4821 ahl main: main.o prov.o 49 4821 ahl cc -o main main.o 50 4821 ahl 51 4821 ahl main.o: main.c 52 4821 ahl cc -c main.c 53 4821 ahl 54 4821 ahl 55 4821 ahl livelib.so: livelib.o prov.o 56 4821 ahl cc -z defs -G -o livelib.so livelib.o prov.o -lc 57 4821 ahl 58 4821 ahl livelib.o: livelib.c prov.h 59 4821 ahl cc -c livelib.c 60 4821 ahl 61 4821 ahl prov.o: livelib.o prov.d 62 4821 ahl $dtrace -G -s prov.d livelib.o 63 4821 ahl 64 4821 ahl prov.h: prov.d 65 4821 ahl $dtrace -h -s prov.d 66 4821 ahl 67 4821 ahl 68 4821 ahl deadlib.so: deadlib.o 69 4821 ahl cc -z defs -G -o deadlib.so deadlib.o -lc 70 4821 ahl 71 4821 ahl deadlib.o: deadlib.c 72 4821 ahl cc -c deadlib.c 73 4821 ahl 74 4821 ahl clean: 75 4821 ahl rm -f main.o livelib.o prov.o prov.h deadlib.o 76 4821 ahl 77 4821 ahl clobber: clean 78 4821 ahl rm -f main livelib.so deadlib.so 79 4821 ahl EOF 80 4821 ahl 81 4821 ahl cat > prov.d <<EOF 82 4821 ahl provider test_prov { 83 4821 ahl probe go(); 84 4821 ahl }; 85 4821 ahl EOF 86 4821 ahl 87 4821 ahl cat > livelib.c <<EOF 88 4821 ahl #include "prov.h" 89 4821 ahl 90 4821 ahl void 91 4821 ahl go(void) 92 4821 ahl { 93 4821 ahl TEST_PROV_GO(); 94 4821 ahl } 95 4821 ahl EOF 96 4821 ahl 97 4821 ahl cat > deadlib.c <<EOF 98 4821 ahl void 99 4821 ahl go(void) 100 4821 ahl { 101 4821 ahl } 102 4821 ahl EOF 103 4821 ahl 104 4821 ahl 105 4821 ahl cat > main.c <<EOF 106 4821 ahl #include <dlfcn.h> 107 4821 ahl #include <unistd.h> 108 4821 ahl #include <stdio.h> 109 4821 ahl 110 4821 ahl static void 111 4821 ahl foo(void) 112 4821 ahl { 113 4821 ahl (void) close(-1); 114 4821 ahl } 115 4821 ahl 116 4821 ahl int 117 4821 ahl main(int argc, char **argv) 118 4821 ahl { 119 4821 ahl void *live; 120 4821 ahl 121 4821 ahl if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { 122 4821 ahl printf("dlopen of livelib.so failed: %s\n", dlerror()); 123 4821 ahl return (1); 124 4821 ahl } 125 4821 ahl 126 4821 ahl (void) dlclose(live); 127 4821 ahl 128 4821 ahl foo(); 129 4821 ahl 130 4821 ahl return (0); 131 4821 ahl } 132 4821 ahl EOF 133 4821 ahl 134 4821 ahl /usr/ccs/bin/make > /dev/null 135 4821 ahl if [ $? -ne 0 ]; then 136 4821 ahl print -u2 "failed to build" 137 4821 ahl exit 1 138 4821 ahl fi 139 4821 ahl 140 4821 ahl script() { 141 4821 ahl $dtrace -c ./main -s /dev/stdin <<EOF 142 4821 ahl pid\$target:a.out:foo:entry 143 4821 ahl { 144 4821 ahl gotit = 1; 145 4821 ahl exit(0); 146 4821 ahl } 147 4821 ahl 148 4821 ahl tick-1s 149 4821 ahl /i++ == 5/ 150 4821 ahl { 151 4821 ahl printf("test timed out"); 152 4821 ahl exit(1); 153 4821 ahl } 154 4821 ahl 155 4821 ahl END 156 4821 ahl /!gotit/ 157 4821 ahl { 158 4821 ahl printf("program ended without hitting probe"); 159 4821 ahl exit(1); 160 4821 ahl } 161 4821 ahl EOF 162 4821 ahl } 163 4821 ahl 164 4821 ahl script 165 4821 ahl status=$? 166 4821 ahl 167 4821 ahl cd / 168 4821 ahl /usr/bin/rm -rf $DIR 169 4821 ahl 170 4821 ahl exit $status 171