8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / dtrace / test / tst / common / io / tst.fds.c
blob2785b51f3084253ac61ffc68da5d80b03b3c3479
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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 <assert.h>
30 #include <setjmp.h>
31 #include <signal.h>
32 #include <unistd.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <fcntl.h>
37 static sigjmp_buf env;
39 static void
40 interrupt(int sig)
42 siglongjmp(env, sig);
45 int
46 main(int argc, char *argv[])
48 const char *file = "/dev/null";
49 int i, n, fds[10];
50 struct sigaction act;
52 if (argc > 1) {
53 (void) fprintf(stderr, "Usage: %s\n", argv[0]);
54 return (EXIT_FAILURE);
57 act.sa_handler = interrupt;
58 act.sa_flags = 0;
60 (void) sigemptyset(&act.sa_mask);
61 (void) sigaction(SIGUSR1, &act, NULL);
63 closefrom(0);
64 n = 0;
67 * With all of our file descriptors closed, wait here spinning in bogus
68 * ioctl() calls until DTrace hits us with a SIGUSR1 to start the test.
70 if (sigsetjmp(env, 1) == 0) {
71 for (;;)
72 (void) ioctl(-1, -1, NULL);
76 * To test the fds[] array, we open /dev/null (a file with reliable
77 * pathname and properties) using various flags and seek offsets.
79 fds[n++] = open(file, O_RDONLY);
80 fds[n++] = open(file, O_WRONLY);
81 fds[n++] = open(file, O_RDWR);
83 fds[n++] = open(file, O_RDWR | O_APPEND | O_CREAT | O_DSYNC |
84 O_LARGEFILE | O_NOCTTY | O_NONBLOCK | O_NDELAY | O_RSYNC |
85 O_SYNC | O_TRUNC | O_XATTR);
87 fds[n++] = open(file, O_RDWR);
88 (void) lseek(fds[n - 1], 123, SEEK_SET);
91 * Once we have all the file descriptors in the state we want to test,
92 * issue a bogus ioctl() on each fd with cmd -1 and arg NULL to whack
93 * our DTrace script into recording the content of the fds[] array.
95 for (i = 0; i < n; i++)
96 (void) ioctl(fds[i], -1, NULL);
98 assert(n <= sizeof (fds) / sizeof (fds[0]));
99 exit(0);