1178476Sjb/* 2178476Sjb * CDDL HEADER START 3178476Sjb * 4178476Sjb * The contents of this file are subject to the terms of the 5178476Sjb * Common Development and Distribution License (the "License"). 6178476Sjb * You may not use this file except in compliance with the License. 7178476Sjb * 8178476Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9178476Sjb * or http://www.opensolaris.org/os/licensing. 10178476Sjb * See the License for the specific language governing permissions 11178476Sjb * and limitations under the License. 12178476Sjb * 13178476Sjb * When distributing Covered Code, include this CDDL HEADER in each 14178476Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15178476Sjb * If applicable, add the following below this CDDL HEADER, with the 16178476Sjb * fields enclosed by brackets "[]" replaced with your own identifying 17178476Sjb * information: Portions Copyright [yyyy] [name of copyright owner] 18178476Sjb * 19178476Sjb * CDDL HEADER END 20178476Sjb */ 21178476Sjb 22178476Sjb/* 23178476Sjb * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24178476Sjb * Use is subject to license terms. 25178476Sjb */ 26178476Sjb 27178476Sjb#pragma ident "%Z%%M% %I% %E% SMI" 28178476Sjb 29313485Sngie#include <sys/ioctl.h> 30313485Sngie 31178476Sjb#include <assert.h> 32178476Sjb#include <setjmp.h> 33178476Sjb#include <signal.h> 34178476Sjb#include <unistd.h> 35178476Sjb#include <stdlib.h> 36178476Sjb#include <stdio.h> 37178476Sjb#include <fcntl.h> 38178476Sjb 39178476Sjbstatic sigjmp_buf env; 40178476Sjb 41178476Sjbstatic void 42178476Sjbinterrupt(int sig) 43178476Sjb{ 44178476Sjb siglongjmp(env, sig); 45178476Sjb} 46178476Sjb 47178476Sjbint 48178476Sjbmain(int argc, char *argv[]) 49178476Sjb{ 50178476Sjb const char *file = "/dev/null"; 51178476Sjb int i, n, fds[10]; 52178476Sjb struct sigaction act; 53178476Sjb 54178476Sjb if (argc > 1) { 55178476Sjb (void) fprintf(stderr, "Usage: %s\n", argv[0]); 56178476Sjb return (EXIT_FAILURE); 57178476Sjb } 58178476Sjb 59178476Sjb act.sa_handler = interrupt; 60178476Sjb act.sa_flags = 0; 61178476Sjb 62178476Sjb (void) sigemptyset(&act.sa_mask); 63178476Sjb (void) sigaction(SIGUSR1, &act, NULL); 64178476Sjb 65178476Sjb closefrom(0); 66178476Sjb n = 0; 67178476Sjb 68178476Sjb /* 69178476Sjb * With all of our file descriptors closed, wait here spinning in bogus 70178476Sjb * ioctl() calls until DTrace hits us with a SIGUSR1 to start the test. 71178476Sjb */ 72178476Sjb if (sigsetjmp(env, 1) == 0) { 73178476Sjb for (;;) 74313485Sngie (void) ioctl(-1, 0, NULL); 75178476Sjb } 76178476Sjb 77178476Sjb /* 78178476Sjb * To test the fds[] array, we open /dev/null (a file with reliable 79178476Sjb * pathname and properties) using various flags and seek offsets. 80178476Sjb */ 81178476Sjb fds[n++] = open(file, O_RDONLY); 82178476Sjb fds[n++] = open(file, O_WRONLY); 83178476Sjb fds[n++] = open(file, O_RDWR); 84178476Sjb 85313485Sngie fds[n++] = open(file, O_RDWR | O_APPEND | O_CREAT | 86313485Sngie O_NOCTTY | O_NONBLOCK | O_NDELAY | O_SYNC | O_TRUNC | 0666); 87178476Sjb 88178476Sjb fds[n++] = open(file, O_RDWR); 89178476Sjb (void) lseek(fds[n - 1], 123, SEEK_SET); 90178476Sjb 91178476Sjb /* 92178476Sjb * Once we have all the file descriptors in the state we want to test, 93313485Sngie * issue a bogus ioctl() on each fd with cmd 0 and arg NULL to whack 94178476Sjb * our DTrace script into recording the content of the fds[] array. 95178476Sjb */ 96178476Sjb for (i = 0; i < n; i++) 97313485Sngie (void) ioctl(fds[i], 0, NULL); 98178476Sjb 99178476Sjb assert(n <= sizeof (fds) / sizeof (fds[0])); 100178476Sjb exit(0); 101178476Sjb} 102