Skip site navigation (1)Skip section navigation (2)
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
Message-ID:  <19970421150525.FM29102@uriah.heep.sax.de>
In-Reply-To: <199704210727.JAA15119@labinfo.iet.unipi.it>; from Luigi Rizzo on Apr 21, 1997 09:27:37 %2B0200
References:  <199704210613.PAA08016@genesis.atrad.adelaide.edu.au> <199704210727.JAA15119@labinfo.iet.unipi.it>

next in thread | previous in thread | raw e-mail | index | archive | help
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. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970421150525.FM29102>