Is it considered to be ok to not check the return code of close(2) in base?
Eric van Gyzen
eric at vangyzen.net
Mon Jan 8 17:52:02 UTC 2018
On 01/08/2018 10:55, Rodney W. Grimes wrote:
>> 08.01.2018 23:13, Eric van Gyzen wrote:
>>
>>> Right, which is the reason such bugs are hard to diagnose. Optionally
>>> killing the process on close->EBADF would help find buggy code when
>>> another thread did NOT re-open the file descriptor between the two close
>>> calls.
>>
>> Wouldn't "close(f); assert(errno != EBADF);" be better?
Putting the code in one place is far better than putting it in N
places...after /finding/ those N places. Indeed, the purpose of this
code is to help people find those places, even in their own code,
outside of base.
> Or even
> #ifdef DEBUG_CLOSE
> #define close(f) close(f); assert(errno != EBADF);
> #endif
errno could have been EBADF before the close(). A successful close()
does not modify errno. So, this would have be larger, making it even
more unpalatable.
> Then the people that want to go chasing these errors can,
> and the rest of us are untouched.
Every mention in this thread of killing the process has called it
optional. Tools, not policy.
Eric
More information about the freebsd-hackers
mailing list