include/closestream: add close_stdout_atexit()

It seems better to have a way to control when atexit(close_stdout()) is
used, because close stdout means that for example ASAN (or another
into binary integrated tool) is not able to print the final summary.

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-04-16 13:42:34 +02:00
parent 7f8787d094
commit 31c66833cb
2 changed files with 13 additions and 0 deletions

View File

@ -156,6 +156,8 @@ AC_ARG_ENABLE([asan],
AS_IF([test "x$enable_asan" = xyes], [
UL_WARN_ADD([-fsanitize=address])
ASAN_LDFLAGS="-fsanitize=address"
],[
AC_DEFINE([USE_CLOSE_ATEXIT], [1], [close stdout at exit])
])
AC_SUBST([ASAN_LDFLAGS])

View File

@ -51,6 +51,17 @@ close_stdout(void)
_exit(CLOSE_EXIT_CODE);
}
static inline void
close_stdout_atexit(void)
{
/*
* Note that close stdout at exit disables ASAN to report memory leaks
*/
#ifdef USE_CLOSE_ATEXIT
atexit(close_stdout);
#endif
}
#ifndef HAVE_FSYNC
static inline int
fsync(int fd __attribute__((__unused__)))