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.
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.
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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/ioctl.h>
39 static sigjmp_buf env;
48 main(int argc, char *argv[])
50 const char *file = "/dev/null";
55 (void) fprintf(stderr, "Usage: %s\n", argv[0]);
56 return (EXIT_FAILURE);
59 act.sa_handler = interrupt;
62 (void) sigemptyset(&act.sa_mask);
63 (void) sigaction(SIGUSR1, &act, NULL);
69 * With all of our file descriptors closed, wait here spinning in bogus
70 * ioctl() calls until DTrace hits us with a SIGUSR1 to start the test.
72 if (sigsetjmp(env, 1) == 0) {
74 (void) ioctl(-1, 0, NULL);
78 * To test the fds[] array, we open /dev/null (a file with reliable
79 * pathname and properties) using various flags and seek offsets.
81 fds[n++] = open(file, O_RDONLY);
82 fds[n++] = open(file, O_WRONLY);
83 fds[n++] = open(file, O_RDWR);
85 fds[n++] = open(file, O_RDWR | O_APPEND | O_CREAT |
86 O_NOCTTY | O_NONBLOCK | O_NDELAY | O_SYNC | O_TRUNC | 0666);
88 fds[n++] = open(file, O_RDWR);
89 (void) lseek(fds[n - 1], 123, SEEK_SET);
92 * Once we have all the file descriptors in the state we want to test,
93 * issue a bogus ioctl() on each fd with cmd 0 and arg NULL to whack
94 * our DTrace script into recording the content of the fds[] array.
96 for (i = 0; i < n; i++)
97 (void) ioctl(fds[i], 0, NULL);
99 assert(n <= sizeof (fds) / sizeof (fds[0]));