This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC][BZ #14627] Make linux close errno to EINPROGRESS when interrupted in signal.


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.

-- 
Russ Allbery (eagle@eyrie.org)              <http://www.eyrie.org/~eagle/>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]