Is it considered to be ok to not check the return code of close(2) in base?

Don Lewis truckman at FreeBSD.org
Mon Jan 8 18:06:02 UTC 2018


On  8 Jan, Eugene Grosbein 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?

That can produce false positives.  The close() might be successful,
in which case it will not touch errno, and errno might have been set
to EBADF by some earlier operation.



More information about the freebsd-hackers mailing list