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

Bug in `do_pclose'



Hi,

the problem occured together with the `gemar.xfs' tape-device
driver. This device locks all access after the first one, because its
close() function is not called properly.

Here is what's happening:
The `open()' function of the mintlib first opens the device-file with
`Fopen'. Afterwards it duplicates the filehandle with `Fcntl'.

Now we have one open file with two handles pointing to it (this is
represented in the FILEPTR by a links-count=2).

`open()' determines which handle to keep and Fclose()s the other. This
"Fclose" call gets passed to device driver independ of the
links-counter, so `open()' actually closes the device driver! (In the
special case the device driver locks, because a second `Fclose' closed
the filehandle returned by `open()' is passed to the device also. But
I can imagine other problems caused by this behaviour.)

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.

cu, Steffen
--
steffen.ries@gondolin.camelot.de  | .sig intentionally left blank
steffen_ries@m4.maus.de           |