Detect FreeBSD versions with broken MSG_CMSG_CLOEXEC

If we are compiling against a version of FreeBSD where MSG_CMSG_CLOEXEC
does not work, use the fallback directly. This was only fixed recently
(in https://cgit.freebsd.org/src/commit/?id=6ceacebdf52211).

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
This commit is contained in:
Alex Richardson 2021-03-19 10:02:41 +00:00 committed by Alexander Richardson
parent 42bf011f65
commit 382f368a27
3 changed files with 33 additions and 1 deletions

View file

@ -168,6 +168,15 @@ recvmsg_cloexec_fallback(int sockfd, struct msghdr *msg, int flags)
ssize_t
wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags)
{
#if HAVE_BROKEN_MSG_CMSG_CLOEXEC
/*
* FreeBSD had a broken implementation of MSG_CMSG_CLOEXEC between 2015
* and 2021, so we have to use the non-MSG_CMSG_CLOEXEC fallback
* directly when compiling against a version that does not include the
* fix (https://cgit.freebsd.org/src/commit/?id=6ceacebdf52211).
*/
#pragma message("Using fallback directly since MSG_CMSG_CLOEXEC is broken.")
#else
ssize_t len;
len = recvmsg(sockfd, msg, flags | MSG_CMSG_CLOEXEC);
@ -175,7 +184,7 @@ wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags)
return len;
if (errno != EINVAL)
return -1;
#endif
return recvmsg_cloexec_fallback(sockfd, msg, flags);
}