Problem: Fix fork detection on gcc 7

Solution: When compiling with gcc 7 and newer, the program produced by
AC_CHECK_FUNCS(fork) produces a warning, which results in configure
incorrectly disabling fork support. Fix the issue by using an
AC_COMPILE_IFELSE which correctly detects fork availability.
Tested by running configure and make check on a system with gcc 7
installed, and verifying that HAVE_FORK was defined correctly.

See issue #3313.
This commit is contained in:
David Gloe 2021-11-23 15:39:42 +00:00
parent 4b48007927
commit 240e36af4e

View File

@ -795,9 +795,24 @@ AC_LANG_POP([C++])
# Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(perror gettimeofday clock_gettime memset socket getifaddrs freeifaddrs fork mkdtemp accept4)
AC_CHECK_FUNCS(perror gettimeofday clock_gettime memset socket getifaddrs freeifaddrs mkdtemp accept4)
AC_CHECK_HEADERS([alloca.h])
# AC_CHECK_FUNCS(fork) fails on gcc 7
AC_MSG_CHECKING([whether fork is available])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <unistd.h>]],
[[return fork();]])
],[
AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_FORK, [1], [fork is available])
AM_CONDITIONAL(HAVE_FORK, true)
],[
AC_MSG_RESULT([no])
AM_CONDITIONAL(HAVE_FORK, false)
])
# string.h doesn't seem to be included by default in Fedora 30
AC_MSG_CHECKING([whether strnlen is available])
AC_COMPILE_IFELSE(
@ -995,8 +1010,6 @@ LIBZMQ_CHECK_GETRANDOM([
[Whether getrandom is supported.])
])
AM_CONDITIONAL(HAVE_FORK, test "x$ac_cv_func_fork" = "xyes")
if test "x$cross_compiling" = "xyes"; then
# Enable draft by default when cross-compiling
defaultval=yes