Is it considered to be ok to not check the return code of close(2) in base?
Stefan Esser
se at freebsd.org
Wed Jan 10 11:12:33 UTC 2018
Am 10.01.18 um 11:47 schrieb Poul-Henning Kamp:
> --------
> In message <b7d5cc97-2042-42ff-914c-35a28560932b at freebsd.org>, Stefan Esser wri
> tes:
>
>>> Ok, so lets get a bit more clever,
>>> #ifdef DEBUG_CLOSE
>>> #define close(f) assert(close(f) && errno != EBADF)
>>> #endif
>>
>> This will lead to close() being removed from the program,
>> if NDEBUG is defined ...
>>
>> So, at least test for NDEBUG in addition to DEBUG_CLOSE,
>> to enable this macro.
>
> More importantly, it will lead to the assert failing if close(2)
> succeeds...
Oh, yes, I missed that detail ;-)
> The NDEBUG details is easiest solved by:
>
> #undef NDEBUG // assert()'s not to be removed
> #include <assert.h>
There has been the much better suggestion by Conrad Meyer (which
uses a GCC extension that might not be supported by CLANG?) and
the LD_PRELOAD hack suggested by Konstantin Belousov, which even
works without recompilation of the program that is to be checked.
I should have read the full thread before replying to a post in
the middle of the discussion ...
Regards, STefan
More information about the freebsd-hackers
mailing list