1#!/bin/sh 2 3# 4# Copyright (c) 2008 Peter Holm <pho@FreeBSD.org> 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28# $FreeBSD$ 29# 30 31# Stopped at devfs_open+0x23f: pushl 0x14(%ebx) 32# db> where 33# Tracing pid 46017 tid 100350 td 0xc4c08510 34# devfs_open(e6d06a10) at devfs_open+0x23f 35# VOP_OPEN_APV(c09edda0,e6d06a10) at VOP_OPEN_APV+0x9b 36# vn_open_cred(e6d06b78,e6d06c78,0,c4883900,3,...) at vn_open_cred+0x41e 37# vn_open(e6d06b78,e6d06c78,0,3) at vn_open+0x1e 38# kern_open(c4c08510,8048887,0,1,0,...) at kern_open+0xb7 39# open(c4c08510,e6d06d00) at open+0x18 40# syscall(e6d06d38) at syscall+0x252 41 42# Test scenario by kib@freebsd.org 43 44odir=`pwd` 45dir=/tmp 46 47cd $dir 48sed '1,/^EOF/d' < $odir/$0 > $dir/devfs2.c 49cc -o devfs2 -Wall devfs2.c -lthr 50rm -f devfs2.c 51 52./devfs2 53 54rm devfs2 55 56exit 57 58EOF 59#include <pthread.h> 60#include <stdio.h> 61#include <signal.h> 62#include <stdlib.h> 63#include <unistd.h> 64#include <fcntl.h> 65#include <string.h> 66#include <err.h> 67 68void * 69thr1(void *arg) 70{ 71 int fd; 72 int i; 73 74 for (i = 0; i < 1024; i++) { 75 if ((fd = open("/dev/zero", O_RDONLY)) == -1) 76 perror("open /dev/zero"); 77 close(fd); 78 } 79 return (0); 80} 81 82void * 83thr2(void *arg) 84{ 85 int i; 86 for (i = 0; i < 1024; i++) 87 close(3); 88 return (0); 89} 90 91int 92main() 93{ 94 pthread_t threads[2]; 95 int i; 96 int r; 97 98 if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) 99 err(1, "pthread_create(): %s\n", strerror(r)); 100 if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) 101 err(1, "pthread_create(): %s\n", strerror(r)); 102 103 for (i = 0; i < 2; i++) 104 if (pthread_join(threads[i], NULL) != 0) 105 err(1, "pthread_join(%d)", i); 106 107 return (0); 108} 109