xref: /titanic_50/usr/src/cmd/dtrace/test/tst/common/privs/tst.fds.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
26tmpin=/tmp/tst.fds.$$.d
27tmpout1=/tmp/tst.fds.$$.out1
28tmpout2=/tmp/tst.fds.$$.out2
29
30cat > $tmpin <<EOF
31#define DUMPFIELD(fd, fmt, field) \
32	errmsg = "could not dump field"; \
33	printf("%d: field =fmt\n", fd, fds[fd].field);
34
35/*
36 * Note that we are explicitly not looking at fi_mount -- it (by design) does
37 * not work if not running with kernel permissions.
38 */
39#define DUMP(fd)	\
40	DUMPFIELD(fd, %s, fi_name); \
41	DUMPFIELD(fd, %s, fi_dirname); \
42	DUMPFIELD(fd, %s, fi_pathname); \
43	DUMPFIELD(fd, %d, fi_offset); \
44	DUMPFIELD(fd, %s, fi_fs); \
45	DUMPFIELD(fd, %o, fi_oflags);
46
47BEGIN
48{
49	DUMP(0);
50	DUMP(1);
51	DUMP(2);
52	DUMP(3);
53	DUMP(4);
54	exit(0);
55}
56
57ERROR
58{
59	printf("error: %s\n", errmsg);
60	exit(1);
61}
62EOF
63
64#
65# First, with all privs
66#
67/usr/sbin/dtrace -q -Cs /dev/stdin < $tmpin > $tmpout2
68mv $tmpout2 $tmpout1
69
70#
71# And now with only dtrace_proc and dtrace_user -- the output should be
72# identical.
73#
74ppriv -s A=basic,dtrace_proc,dtrace_user $$
75
76/usr/sbin/dtrace -q -Cs /dev/stdin < $tmpin > $tmpout2
77
78echo ">>> $tmpout1"
79cat $tmpout1
80
81echo ">>> $tmpout2"
82cat $tmpout2
83
84rval=0
85
86if ! cmp $tmpout1 $tmpout2 ; then
87	rval=1
88fi
89
90rm $tmpout1 $tmpout2 $tmpin
91exit $rval
92