xref: /titanic_51/usr/src/cmd/dtrace/test/tst/common/privs/tst.providers.ksh (revision b0f673c4626e4cb1db7785287eaeed2731dfefe8)
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 (c) 2012, Joyent, Inc. All rights reserved.
24#
25
26#
27# First, make sure that we can successfully enable the io provider
28#
29if ! dtrace -P io -n BEGIN'{exit(0)}' > /dev/null 2>&1 ; then
30	echo failed to enable io provider with full privs
31	exit 1
32fi
33
34ppriv -s A=basic,dtrace_proc,dtrace_user $$
35
36#
37# Now make sure that we cannot enable the io provider with reduced privs
38#
39if ! dtrace -x errtags -P io -n BEGIN'{exit(1)}' 2>&1 | \
40    grep D_PDESC_ZERO > /dev/null 2>&1 ; then
41	echo successfully enabled the io provider with reduced privs
42	exit 1
43fi
44
45#
46# Keeping our reduced privs, we want to assure that we can see every provider
47# that we think we should be able to see -- and that we can see curpsinfo
48# state but can't otherwise see arguments.
49#
50/usr/sbin/dtrace -wq -Cs /dev/stdin <<EOF
51
52int seen[string];
53int err;
54
55#define CANENABLE(provider) \
56provider:::								\
57/err == 0 && progenyof(\$pid) && !seen["provider"]/			\
58{									\
59	trace(arg0);							\
60	printf("\nsuccessful trace of arg0 in %s:%s:%s:%s\n",		\
61	    probeprov, probemod, probefunc, probename);			\
62	exit(++err);							\
63}									\
64									\
65provider:::								\
66/progenyof(\$pid)/							\
67{									\
68	seen["provider"]++;						\
69}									\
70									\
71provider:::								\
72/progenyof(\$pid)/							\
73{									\
74	errstr = "provider";						\
75	this->ignore = stringof(curpsinfo->pr_psargs);			\
76	errstr = "";							\
77}									\
78									\
79END									\
80/err == 0 && !seen["provider"]/						\
81{									\
82	printf("no probes from provider\n");				\
83	exit(++err);							\
84}									\
85									\
86END									\
87/err == 0/								\
88{									\
89	printf("saw %d probes from provider\n", seen["provider"]);	\
90}
91
92CANENABLE(proc)
93CANENABLE(sched)
94CANENABLE(vminfo)
95CANENABLE(sysinfo)
96
97BEGIN
98{
99	/*
100	 * We'll kick off a system of a do-nothing command -- which should be
101	 * enough to kick proc, sched, vminfo and sysinfo probes.
102	 */
103	system("echo > /dev/null");
104}
105
106ERROR
107/err == 0 && errstr != ""/
108{
109	printf("fatal error: couldn't read curpsinfo->pr_psargs in ");
110	printf("%s-provided probe\n", errstr);
111	exit(++err);
112}
113
114proc:::exit
115/progenyof(\$pid)/
116{
117	exit(0);
118}
119
120tick-10ms
121/i++ > 500/
122{
123	printf("exit probe did not seem to fire\n");
124	exit(++err);
125}
126EOF
127