From owner-freebsd-hackers Mon Apr 21 06:21:46 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id GAA12583 for hackers-outgoing; Mon, 21 Apr 1997 06:21:46 -0700 (PDT) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id GAA12575 for ; Mon, 21 Apr 1997 06:21:38 -0700 (PDT) Received: (from uucp@localhost) by sax.sax.de (8.6.12/8.6.12-s1) with UUCP id PAA25212 for hackers@freebsd.org; Mon, 21 Apr 1997 15:21:06 +0200 Received: (from j@localhost) by uriah.heep.sax.de (8.8.5/8.8.5) id PAA22705; Mon, 21 Apr 1997 15:05:25 +0200 (MET DST) Message-ID: <19970421150525.FM29102@uriah.heep.sax.de> Date: Mon, 21 Apr 1997 15:05:25 +0200 From: j@uriah.heep.sax.de (J Wunsch) To: hackers@freebsd.org Subject: Re: concurrent calls to device drivers References: <199704210613.PAA08016@genesis.atrad.adelaide.edu.au> <199704210727.JAA15119@labinfo.iet.unipi.it> X-Mailer: Mutt 0.60_p2-3,5,8-9 Mime-Version: 1.0 X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) In-Reply-To: <199704210727.JAA15119@labinfo.iet.unipi.it>; from Luigi Rizzo on Apr 21, 1997 09:27:37 +0200 Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk As Luigi Rizzo wrote: > > The driver claims to only permit a single opener, which as Bruce has > > pointed out before is pointless as fd's are duplicated across forks. > > which reminds me that many device drivers in /sys/i386/isa (some > of which were contributed by me... :( ) are "broken" in the same > way: they keep a flag to remember that the device is open, but do > not prevent concurrent calls, assuming the single open as a guarantee > that there are no concurrent calls. The single open at least reduced the possibility of an error to the writer of some program (since he must pass the open fd on to his child). Preventing multiple opens avoids two different programs from opening it at the same time (incidentally, or malicuously). That is, somebody who's writing code like: fd = open("/dev/speaker", ...); switch (fork()) { case 0: write(fd, "cdefg", 5); exit(0); case -1: perror("fork failed"); exit(1); default: write(fd, "gfedc", 5); } ...simply gets what he deserves. It doesn't make more sense in this case to interleave or serialize the calls to write() above except to prevent kernel data corruption. The ``only one open'' should still stay there, to prevent multiple programs from competing for the device. -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)