Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 55 additions & 22 deletions cmake/CheckFDPassing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,63 @@ if(HAVE_CONTROL_IN_MSGHDR)
set(EXTRA_COMPILE_DEFINITIONS "${EXTRA_COMPILE_DEFINITIONS} -DHAVE_SYS_UIO_H=1")
endif()

# Try without _XOPEN_SOURCE first
try_run(
# Name of variable to store the run result (process exit status; number) in:
test_run_result
# Name of variable to store the compile result (TRUE or FALSE) in:
test_compile_result
# Binary directory:
${CMAKE_CURRENT_BINARY_DIR}
# Source file to be compiled:
${_selfdir_CheckFDPassing}/CheckFDPassing.c
# Extra -D Compile Definitions
COMPILE_DEFINITIONS ${EXTRA_COMPILE_DEFINITIONS}
# Where to store the output produced during compilation:
COMPILE_OUTPUT_VARIABLE test_compile_output
# Where to store the output produced by running the compiled executable:
RUN_OUTPUT_VARIABLE test_run_output )

# Did compilation succeed and process return 0 (success)?
if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0))
set(HAVE_FD_PASSING 1)
else()
# Try again, this time with: #define _XOPEN_SOURCE 500
# OpenBSD requires _XOPEN_SOURCE for proper fdpassing support
if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
set(EXTRA_COMPILE_DEFINITIONS "${EXTRA_COMPILE_DEFINITIONS} -D_XOPEN_SOURCE=500")
set(FORCE_XOPEN_TEST 1)
else()
set(FORCE_XOPEN_TEST 0)
endif()

# Try without _XOPEN_SOURCE first (unless OpenBSD)
if(NOT FORCE_XOPEN_TEST)
try_run(
# Name of variable to store the run result (process exit status; number) in:
test_run_result
# Name of variable to store the compile result (TRUE or FALSE) in:
test_compile_result
# Binary directory:
${CMAKE_CURRENT_BINARY_DIR}
# Source file to be compiled:
${_selfdir_CheckFDPassing}/CheckFDPassing.c
# Extra -D Compile Definitions
COMPILE_DEFINITIONS ${EXTRA_COMPILE_DEFINITIONS}
# Where to store the output produced during compilation:
COMPILE_OUTPUT_VARIABLE test_compile_output
# Where to store the output produced by running the compiled executable:
RUN_OUTPUT_VARIABLE test_run_output )

# Did compilation succeed and process return 0 (success)?
if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0))
set(HAVE_FD_PASSING 1)
else()
# Try again, this time with: #define _XOPEN_SOURCE 500
set(EXTRA_COMPILE_DEFINITIONS "${EXTRA_COMPILE_DEFINITIONS} -D_XOPEN_SOURCE=500")

try_run(
# Name of variable to store the run result (process exit status; number) in:
test_run_result
# Name of variable to store the compile result (TRUE or FALSE) in:
test_compile_result
# Binary directory:
${CMAKE_CURRENT_BINARY_DIR}
# Source file to be compiled:
${_selfdir_CheckFDPassing}/CheckFDPassing.c
# Extra -D Compile Definitions
COMPILE_DEFINITIONS ${EXTRA_COMPILE_DEFINITIONS}
# Where to store the output produced during compilation:
COMPILE_OUTPUT_VARIABLE test_compile_output
# Where to store the output produced by running the compiled executable:
RUN_OUTPUT_VARIABLE test_run_output )

# Did compilation succeed and process return 0 (success)?
if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0))
set(HAVE_FD_PASSING 1)
set(FDPASS_NEED_XOPEN 1)
endif()
endif()
else()
# For OpenBSD, test directly with _XOPEN_SOURCE=500
try_run(
# Name of variable to store the run result (process exit status; number) in:
test_run_result
Expand Down
3 changes: 3 additions & 0 deletions common/clamdcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "clamav-config.h"
#endif

/* must be first because it may define _XOPEN_SOURCE */
#include "fdpassing.h"

#include <stdio.h>
#include <stdint.h>
#include <string.h>
Expand Down
Loading