Re: close return value (was Re: [ANNOUNCE] Ext3 vs Reiserfs benchmarks)

Elladan (elladan@eskimo.com)
Tue, 16 Jul 2002 20:31:02 -0700


On Tue, Jul 16, 2002 at 09:10:49PM -0600, Thunder from the hill wrote:
> Hi,
>
> On Tue, 16 Jul 2002, Elladan wrote:
> > > Thread 2 shouldn't be able to reuse a currently open fd. This application
> > > design is seriously broken.
>
> Okay, again. It's about doing a second close() in case the first one fails
> with EAGAIN. If we have to do it again, the filehandle is not closed, and
> if the filehandle is not closed, the kernel knows that, and if the kernel
> knows that the filehandle is still open, it won't get reassigned. Problem
> gone.

This is case 2, "Close is guaranteed to leave the file open on error."

In this case, all applications are required to reissue close commands
upon certain errors, or leak a file descriptor. This would be a well
defined behavior, though perhaps error prone.

However, note that this is manifestly different from case 1, "Close is
guaranteed to close the file the first time." If the system behaves via
case 1, closing the handle again is broken as the example illustrated.

The worst, of course, would be undefined behavior for close. In this
case, the application effectively can't do the right thing without
extreme measures.

-J
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/