1266986Smarkj#
2266986Smarkj# CDDL HEADER START
3266986Smarkj#
4266986Smarkj# The contents of this file are subject to the terms of the
5266986Smarkj# Common Development and Distribution License (the "License").
6266986Smarkj# You may not use this file except in compliance with the License.
7266986Smarkj#
8266986Smarkj# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9266986Smarkj# or http://www.opensolaris.org/os/licensing.
10266986Smarkj# See the License for the specific language governing permissions
11266986Smarkj# and limitations under the License.
12266986Smarkj#
13266986Smarkj# When distributing Covered Code, include this CDDL HEADER in each
14266986Smarkj# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15266986Smarkj# If applicable, add the following below this CDDL HEADER, with the
16266986Smarkj# fields enclosed by brackets "[]" replaced with your own identifying
17266986Smarkj# information: Portions Copyright [yyyy] [name of copyright owner]
18266986Smarkj#
19266986Smarkj# CDDL HEADER END
20266986Smarkj#
21266986Smarkj
22266986Smarkj#
23266986Smarkj# Copyright (c) 2012, Joyent, Inc. All rights reserved.
24266986Smarkj#
25266986Smarkj
26266986Smarkjtmpin=/tmp/tst.fds.$$.d
27266986Smarkjtmpout1=/tmp/tst.fds.$$.out1
28266986Smarkjtmpout2=/tmp/tst.fds.$$.out2
29266986Smarkj
30266986Smarkjcat > $tmpin <<EOF
31266986Smarkj#define DUMPFIELD(fd, fmt, field) \
32266986Smarkj	errmsg = "could not dump field"; \
33266986Smarkj	printf("%d: field =fmt\n", fd, fds[fd].field);
34266986Smarkj
35266986Smarkj/*
36266986Smarkj * Note that we are explicitly not looking at fi_mount -- it (by design) does
37266986Smarkj * not work if not running with kernel permissions.
38266986Smarkj */
39266986Smarkj#define DUMP(fd)	\
40266986Smarkj	DUMPFIELD(fd, %s, fi_name); \
41266986Smarkj	DUMPFIELD(fd, %s, fi_dirname); \
42266986Smarkj	DUMPFIELD(fd, %s, fi_pathname); \
43266986Smarkj	DUMPFIELD(fd, %d, fi_offset); \
44266986Smarkj	DUMPFIELD(fd, %s, fi_fs); \
45266986Smarkj	DUMPFIELD(fd, %o, fi_oflags);
46266986Smarkj
47266986SmarkjBEGIN
48266986Smarkj{
49266986Smarkj	DUMP(0);
50266986Smarkj	DUMP(1);
51266986Smarkj	DUMP(2);
52266986Smarkj	DUMP(3);
53266986Smarkj	DUMP(4);
54266986Smarkj	exit(0);
55266986Smarkj}
56266986Smarkj
57266986SmarkjERROR
58266986Smarkj{
59266986Smarkj	printf("error: %s\n", errmsg);
60266986Smarkj	exit(1);
61266986Smarkj}
62266986SmarkjEOF
63266986Smarkj
64266986Smarkj#
65266986Smarkj# First, with all privs
66266986Smarkj#
67266986Smarkj/usr/sbin/dtrace -q -Cs /dev/stdin < $tmpin > $tmpout2
68266986Smarkjmv $tmpout2 $tmpout1
69266986Smarkj
70266986Smarkj#
71266986Smarkj# And now with only dtrace_proc and dtrace_user -- the output should be
72266986Smarkj# identical.
73266986Smarkj#
74266986Smarkjppriv -s A=basic,dtrace_proc,dtrace_user $$
75266986Smarkj
76266986Smarkj/usr/sbin/dtrace -q -Cs /dev/stdin < $tmpin > $tmpout2
77266986Smarkj
78266986Smarkjecho ">>> $tmpout1"
79266986Smarkjcat $tmpout1
80266986Smarkj
81266986Smarkjecho ">>> $tmpout2"
82266986Smarkjcat $tmpout2
83266986Smarkj
84266986Smarkjrval=0
85266986Smarkj
86266986Smarkjif ! cmp $tmpout1 $tmpout2 ; then
87266986Smarkj	rval=1
88266986Smarkjfi
89266986Smarkj
90266986Smarkjrm $tmpout1 $tmpout2 $tmpin
91266986Smarkjexit $rval
92