[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in `do_pclose'



Steffen Ries wrote:

> Now we have one open file with two handles pointing to it (this is
> represented in the FILEPTR by a links-count=2).
> [...]
> My idea is to evaluate the links-counter too, and only close the
> device-driver, when the last opened filehandle is closed. (That is,
> call the device-close() only if links<=0)
> 
> --- dosfile.c.org	Fri Oct 20 17:03:12 1995
> +++ dosfile.c	Fri Oct 20 17:03:28 1995
> @@ -437,7 +437,7 @@
>  		}
>  	}
>  
> -	if (f->dev) {
> +	if (f->dev && f->links <= 0) {
>  		r = (*f->dev->close)(f, p->pid);
>  		if (r) {
>  			DEBUG(("close: device close failed"));
> 
> I hope this change does not break any application, at least I have not
> experienced any problems up to now. I would appreciate, if anyone
> could check this problem/patch.

Well, I haven't written MiNT device drivers for a long time, but my
impression was that the device driver had to test for (f->links) itself, and
only release the associated resources when the counter reached zero.
I'm also confident that this behaviour is documented. BTW, it's the only way
to implement POSIX-compliant advisory locking, because you have to release
all locks on the _first_ close(), even if there are other descriptors
referring to the same file/device.

Thierry.