diff --git a/configure.ac b/configure.ac index b77b516d9..c452cf5d3 100644 --- a/configure.ac +++ b/configure.ac @@ -56,15 +56,9 @@ AC_CHECK_TYPE([Elf64_Ehdr], AC_DEFINE([HAVE_ELF64], [1], [Define to 1 if the system has the type 'Elf64_Ehdr'.]), [], [[#include ]]) -AC_MSG_CHECKING([for glibc]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[int v = __GLIBC__;return 0;]])], - [have_glibc=yes], [have_glibc=no]) -AC_MSG_RESULT($have_glibc) - AC_CHECK_HEADERS([fcntl.h]) AC_CHECK_HEADERS([linux/pci.h]) AC_CHECK_HEADERS([linux/spi/spidev.h]) -AC_CHECK_HEADERS([malloc.h]) AC_CHECK_HEADERS([netdb.h]) AC_CHECK_HEADERS([poll.h]) AC_CHECK_HEADERS([strings.h]) @@ -102,6 +96,8 @@ AC_CHECK_FUNCS([strnlen]) AC_CHECK_FUNCS([gettimeofday]) AC_CHECK_FUNCS([usleep]) AC_CHECK_FUNCS([realpath]) +AC_CHECK_FUNCS([mallinfo], [has_at_least_one_mallinfo=yes]) +AC_CHECK_FUNCS([mallinfo2], [has_at_least_one_mallinfo=yes]) # guess-rev.sh only exists in the repository, not in the released archives AC_MSG_CHECKING([whether to build a release]) @@ -276,7 +272,10 @@ AC_ARG_ENABLE([malloc_logging], AC_MSG_CHECKING([whether to enable malloc free space logging]); AC_MSG_RESULT([$debug_malloc]) -AS_IF([test "x$debug_malloc" = "xyes" -a "x$have_glibc" = "xyes"], [ +AS_IF([test "x$debug_malloc" = "xyes"], [ + AS_IF([test "x$has_at_least_one_mallinfo" != "xyes"], [ + AC_MSG_ERROR([Option --enable-malloc-logging needs a libc with mallinfo or mallinfo2.]) + ]) AC_DEFINE([_DEBUG_FREE_SPACE_],[1], [Include malloc free space in logging]) ]) diff --git a/src/helper/log.c b/src/helper/log.c index a157b78b1..1d459825f 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -25,23 +25,7 @@ #include #ifdef _DEBUG_FREE_SPACE_ -#ifdef HAVE_MALLOC_H -#include -#else -#error "malloc.h is required to use --enable-malloc-logging" -#endif - -#ifdef __GLIBC__ -#if __GLIBC_PREREQ(2, 33) -#define FORDBLKS_FORMAT " %zu" -#else -/* glibc older than 2.33 (2021-02-01) use mallinfo(). Overwrite it */ -#define mallinfo2 mallinfo -#define FORDBLKS_FORMAT " %d" -#endif -#else -#error "GNU glibc is required to use --enable-malloc-logging" -#endif +#include // For mallinfo/mallinfo2. #endif int debug_level = LOG_LVL_INFO; @@ -118,11 +102,23 @@ static void log_puts(enum log_levels level, /* print with count and time information */ int64_t t = timeval_ms() - start; #ifdef _DEBUG_FREE_SPACE_ +#ifdef HAVE_MALLINFO2 struct mallinfo2 info = mallinfo2(); +#elif defined(HAVE_MALLINFO) + struct mallinfo info = mallinfo(); +#else +#error "Configuration error: Neither mallinfo() nor mallinfo2() are available." +#endif #endif fprintf(log_output, "%s%d %" PRId64 " %s:%d %s()" #ifdef _DEBUG_FREE_SPACE_ - FORDBLKS_FORMAT +#ifdef HAVE_MALLINFO2 + " %zu" +#elif defined(HAVE_MALLINFO) + " %d" +#else +#error "Configuration error: Neither mallinfo() nor mallinfo2() are available." +#endif #endif ": %s", log_strings[level + 1], count, t, file, line, function, #ifdef _DEBUG_FREE_SPACE_