From: Olivier Houchard Date: Thu, 30 Jul 2026 12:03:55 +0000 (+0200) Subject: BUILD: listener: Fix the build on platforms without MSG_CMSG_CLOEXEC X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=9afec06e0eb477e29b7eeaf9eb8b5039ca4a470a;p=thirdparty%2Fhaproxy.git BUILD: listener: Fix the build on platforms without MSG_CMSG_CLOEXEC Some OSes, such as macos, do not provide MSG_CMSG_CLOEXEC, so provide a fallback mechanism using fdcntl(FD_CLOEXEC) instead. It doesn't matter right now, that code will never be used on such OS, because you can't use per-thread-group fd tables in there, but maybe it will change one day. --- diff --git a/include/haproxy/compat.h b/include/haproxy/compat.h index 39f7af7a6..3f0f0b393 100644 --- a/include/haproxy/compat.h +++ b/include/haproxy/compat.h @@ -150,6 +150,14 @@ typedef struct { } empty_t; #define MSG_DONTWAIT 0 #endif +/* + * Not every OS defines MSG_CMSG_CLOEXEC, so get a fallback version, to + * be tested when using it. + */ +#ifndef MSG_CMSG_CLOEXEC +#define MSG_CMSG_CLOEXEC 0 +#endif + /* Only Linux defines MSG_MORE */ #ifndef MSG_MORE #define MSG_MORE 0 diff --git a/src/listener.c b/src/listener.c index 29a938090..7018b08b0 100644 --- a/src/listener.c +++ b/src/listener.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -969,6 +970,10 @@ void rx_xfer_drain(uint grp) if (cmsg && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) memcpy(&fd, CMSG_DATA(cmsg), sizeof(int)); + /* platforms with no MSG_CMSG_CLOEXEC get it set by hand */ + if (!MSG_CMSG_CLOEXEC && fd >= 0) + fcntl(fd, F_SETFD, FD_CLOEXEC); + if (ret != sizeof(xmsg) || fd < 0) { if (fd >= 0) close(fd);