This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC][BZ #14627] Make linux close errno to EINPROGRESS when interrupted in signal.
- From: Rich Felker <dalias at aerifal dot cx>
- To: Russ Allbery <eagle at eyrie dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 5 Dec 2013 17:32:23 -0500
- Subject: Re: [RFC][BZ #14627] Make linux close errno to EINPROGRESS when interrupted in signal.
- Authentication-results: sourceware.org; auth=none
- References: <20131205175749 dot GL24286 at brightrain dot aerifal dot cx> <20131205195802 dot GA19289 at lst dot de> <20131205201126 dot GO24286 at brightrain dot aerifal dot cx> <20131205 dot 155009 dot 707968344039994800 dot davem at davemloft dot net> <87ob4vggn3 dot fsf at windlord dot stanford dot edu>
On Thu, Dec 05, 2013 at 12:57:36PM -0800, Russ Allbery wrote:
> David Miller <davem@davemloft.net> writes:
>
> > At one time many years ago there was a path in the kernel that returned
> > an error from close and it broke so many things. Even emacs crashed.
>
> > The widespread overwhelming belief is that close() is just going to
> > always succeed, and there is more harm than good from signalling errors
> > at all from that function.
>
> Indeed, all the C code that I've seen either assumes that failure on
> close() is some sort of write failure and treats it as such, or ignores
> failure entirely. Having close() return a failure and leave the file
> descriptor open would cause a file descriptor leak in most code I've seen
> and would result in a possibly incorrect diagnosed failure to write to the
> file in all of the rest.
>
> It's very unclear what a C programmer should do when close() returns
> failure. POSIX 2008 says that the state of the file descriptor after a
> close failure is undefined, which I assume means that one should just
> retry the close (how many times?), but that relies on the assumption that
> it's safe to close a file descriptor that's already closed and the worst
> that will happen is that you'll get back EBADF.
You missed the beginning of this discussion (which, to be fair, was in
another thread: https://www.sourceware.org/ml/libc-alpha/2013-12/msg00108.html)
where it was noted that POSIX has fixed this bug:
http://austingroupbugs.net/view.php?id=529
The new requirement is that EINTR means the fd is still open and
EINPROGRESS means the operation was interrupted by a signal but the fd
is no longer valid.
Rich