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 29# Stopped at devfs_open+0x23f: pushl 0x14(%ebx) 30# db> where 31# Tracing pid 46017 tid 100350 td 0xc4c08510 32# devfs_open(e6d06a10) at devfs_open+0x23f 33# VOP_OPEN_APV(c09edda0,e6d06a10) at VOP_OPEN_APV+0x9b 34# vn_open_cred(e6d06b78,e6d06c78,0,c4883900,3,...) at vn_open_cred+0x41e 35# vn_open(e6d06b78,e6d06c78,0,3) at vn_open+0x1e 36# kern_open(c4c08510,8048887,0,1,0,...) at kern_open+0xb7 37# open(c4c08510,e6d06d00) at open+0x18 38# syscall(e6d06d38) at syscall+0x252 39 40# Test scenario by kib@freebsd.org 41 42. ../default.cfg 43 44odir=`pwd` 45dir=/tmp 46 47cd $dir 48sed '1,/^EOF/d' < $odir/$0 > $dir/devfs2.c 49mycc -o devfs2 -Wall devfs2.c -lthr || exit 1 50rm -f devfs2.c 51 52./devfs2 53 54rm devfs2 55exit 0 56 57EOF 58#include <pthread.h> 59#include <stdio.h> 60#include <signal.h> 61#include <stdlib.h> 62#include <unistd.h> 63#include <fcntl.h> 64#include <string.h> 65#include <err.h> 66 67void * 68thr1(void *arg) 69{ 70 int fd; 71 int i; 72 73 for (i = 0; i < 1024; i++) { 74 if ((fd = open("/dev/zero", O_RDONLY)) == -1) 75 perror("open /dev/zero"); 76 close(fd); 77 } 78 return (0); 79} 80 81void * 82thr2(void *arg) 83{ 84 int i; 85 for (i = 0; i < 1024; i++) 86 close(3); 87 return (0); 88} 89 90int 91main() 92{ 93 pthread_t threads[2]; 94 int i; 95 int r; 96 97 if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) 98 err(1, "pthread_create(): %s\n", strerror(r)); 99 if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) 100 err(1, "pthread_create(): %s\n", strerror(r)); 101 102 for (i = 0; i < 2; i++) 103 if ((r = pthread_join(threads[i], NULL)) != 0) 104 errc(1, r, "pthread_join(%d)", i); 105 106 return (0); 107} 108